• (3 Pages)
  • +
  • 1
  • 2
  • 3

Creating a calendar viewer application GUIs, renderers, JTable tutorial Rate Topic: ***** 3 Votes

#16 Guest_Metsis*


Reputation:

Posted 31 May 2010 - 02:18 AM

I'm not sure if Josko was asking me to post the code. Here's a short description what I did.

Create a project in Netbeans, select new Java Desktop App in the wizard. This will give you a basic application infrastructure with a main window.

Follow the instructions in the tutorial but instead of creating the controls manually, create them by dragging from the palette. The default layout manager in Netbeans works actually quite well (at least compared to several others). Also, you don't have to set look and feel as Netbeans will do that automatically for you.

For the calendar grid, use JTable as in the tutorial. After having placed it onto the frame view, click it and go into its properties. Click the ellipsis at the end of the row with text "model [TableModel]", a JTable editor opens up. Change the row count to 6 and column count to 7. Give the column headers appropriate titles. You can leave the cell type to Object as Java currently supports what is called autounboxing.

Complete the tutorial. Remember to write your code in the MyProjectView (assuming MyProject is your project's name) class but outside the auto-generated code. Note, there is no main method here, it's buried elsewhere. You do not need to edit it, let Netbeans take care of it.

Now, as I wrote Java has a strange opinion about when a week begins. The class GregorianCalendar also deviates from Java practise where numbering begins at zero. Therefore, add the code I posted just before the for loop which fills the calendar.

If you want to know more about table model or auto(un)boxing, Google will help you, although necessary for completing this tutorial.

HTH,

Metsis
Was This Post Helpful? 0

#17 Guest_Metsis*


Reputation:

Posted 31 May 2010 - 02:20 AM

Eh, typo in the last sentence. I forgot a "not".

Metsis
Was This Post Helpful? 0

#18 josko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-May 10

Posted 31 May 2010 - 10:56 AM

Thank you Metsis,this was very helpfull answer,I never worked in netbeans,but I will try.I really want to try to make this icalendar.
Josko
Was This Post Helpful? 0
  • +
  • -

#19 Guest_Adnan*


Reputation:

Posted 01 August 2010 - 06:47 PM

Amaging...........absolutely amaging.....thanks a lot
Was This Post Helpful? 0

#20 ragz13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-July 10

Posted 06 August 2010 - 01:58 AM

quite fantastic,very helpful for newbies and techiies
Was This Post Helpful? 0
  • +
  • -

#21 skorned  Icon User is offline

  • New D.I.C Head

Reputation: 13
  • View blog
  • Posts: 41
  • Joined: 30-August 08

Posted 18 September 2010 - 06:08 AM

View Postdipito31, on 22 April 2010 - 06:52 AM, said:

Hey there...ive read your code and you do allow individual cell selection...but i dont know why...for some reason i cant select any of them....it would be really help if you could help me out as i need an event based calender that add an appointment if clicked on a date..


I was wondering the same thing, so after I spent half an hour reading about actionlisteners on tables, and complicated stuff about ListSelectionModes, I realized all that wasn't needed. By default, the table here allows for individual cells to be selected, and in a normal table, these would have been highlighted in Windows default highlighting style (create a default netbeans desktop app, drag in a table, change the 'cellSelectionEnabled' property, and run, to see what I mean). However, in this program, this default behaviour is messed with because we're modifying the renderer. So, simply updating
public Component getTableCellRendererComponent
, with the addition of the following code, got simple highlighting going.
if (selected == true){
                                setBackground(new Color(220,220,0));
                        }


Forgive me for the ugly color, but I was in a hurry. Anyhow, basic formatting is easy, but what if you want to run a certain function? Well...the following code works:
if (selected == true){
                                setBackground(new Color(220,220,0));
                                lblYear.setText(value.toString());
                        }


This code changes the lblYear's value to the date currently selected (I didn't have the time to add another label and manually position it, so I used the useless lblYear). So theoretically, you could add any custom callback you want here, and then run whatever function you want on the value parameter. However, semantically, I'm not sure this is the best way to go about achieving this function. The renderer should only be controlling the appearance, not the functionality, right? Can OP please add a listener for a particular cellSelection, and maybe just update a label to show the currently selected date?

I'm gonna try doing it myself in a while, but right now, gotta get back to work :(
Was This Post Helpful? 1
  • +
  • -

#22 Guest_Platzwart*


Reputation:

Posted 30 September 2010 - 08:48 AM

Quote

Can OP please add a listener for a particular cellSelection, and maybe just update a label to show the currently selected date?


Tried it today aswell, but coulnt figured it out on my own. Can someone post a working method for this?
Was This Post Helpful? 0

#23 briankasozi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-November 10

Posted 20 November 2010 - 12:05 PM

i will be glad if you also help me with this question. i have tried but still with some errors. thank you


/*Design and implement an application that displays a button and a
label. Every time the button is pushed, the label should display a
random number between 1 and 100, inclusive.*/[/b]
Was This Post Helpful? 0
  • +
  • -

#24 Guest_Wep*


Reputation:

Posted 22 December 2010 - 10:18 AM

For those who wonderd how to change the starting day on monday instead of sunday change the following:

//Get first day of month and number of days
GregorianCalendar cal = new GregorianCalendar(year, month, 0); //<---- Change the 1 to 0 (starting day monday)

after that change the colord coloms aswell:

if (column == 5 || column == 6){ //Week-end // <--- For colom 5 & 6 and not 0 & 6
setBackground(new Color(255, 220, 220));
}

Change your order of days in your Array and you're done :)

(The code that was posted to solve this, didn't really work for me, so i started looking and this solved the prob for me.)
Was This Post Helpful? 0

#25 Raymondtks  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-March 11

Posted 30 March 2011 - 07:54 PM

I was having a hard time doing a Calendar Socket Programming for my school assignment, and your code is the best i can found, thank you! Hope I can get more information from this site. :bigsmile:

Is there any way to add/remove an event by clicking the date inside the calender? I really need it. Does anybody knows?

Help Help~ :cry:

This post has been edited by Raymondtks: 30 March 2011 - 07:55 PM

Was This Post Helpful? 0
  • +
  • -

#26 elvea  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-April 11

Posted 25 April 2011 - 02:57 AM

View PostRaymondtks, on 30 March 2011 - 07:54 PM, said:


Is there any way to add/remove an event by clicking the date inside the calender? I really need it. Does anybody knows?

Help Help~ :cry:


I really need help with this too. Anyone who can at least point me in the right direction?
Was This Post Helpful? 0
  • +
  • -

#27 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,021
  • Joined: 15-July 08

Posted 25 April 2011 - 03:22 AM

Why don't you start a topic in the Java Help forum? We'll see what we can do there:
http://www.dreaminco.../forum/32-java/
Was This Post Helpful? 0
  • +
  • -

#28 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2652
  • View blog
  • Posts: 11,189
  • Joined: 20-September 08

Posted 26 April 2011 - 02:03 PM

It would be a whole lot easier just to use a proper calendar component:

http://www.toedter.c...endar/demo.html
Was This Post Helpful? 0
  • +
  • -

#29 h4han  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-September 12

Posted 08 September 2012 - 01:04 PM

View Postalpha02, on 08 July 2007 - 11:33 AM, said:

View PostTheKingOfCodes, on 8 Jul, 2007 - 01:41 PM, said:

[size=2]think you so much for this amaizing codes, for this i have choosen this code to be my project in java, but
it there is something missing in this code which is you didn't make any sign or highlight the cell in jtable
to keep track on date, so i have been tring to solve this for four days and with out any gain so please complete the missing part and i'd be so appreciated if so, and thinks again.


The tutorial has been updated, now the current day is highlighted blue :)



how can i call it in another application
Was This Post Helpful? 0
  • +
  • -

#30 balraj8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 29-October 12

Posted 29 October 2012 - 10:21 AM

after reading ur code. i got a doubt that, will it be possible that the, selected date in the calender can be passed as the input to the database. or can be saved in the database
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3