Creating a calendar viewer application GUIs, renderers, JTable tutorial
#16 Guest_Metsis*
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
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
#17 Guest_Metsis*
Posted 31 May 2010 - 02:20 AM
Eh, typo in the last sentence. I forgot a "not".
Metsis
Metsis
#18
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
Josko
#19 Guest_Adnan*
Posted 01 August 2010 - 06:47 PM
Amaging...........absolutely amaging.....thanks a lot
#20
Posted 06 August 2010 - 01:58 AM
quite fantastic,very helpful for newbies and techiies
#21
Posted 18 September 2010 - 06:08 AM
dipito31, 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
#22 Guest_Platzwart*
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?
#23
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]
/*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]
#24 Guest_Wep*
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.)
//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.)
#25
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. 
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~
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~
This post has been edited by Raymondtks: 30 March 2011 - 07:55 PM
#26
Posted 25 April 2011 - 02:57 AM
#27
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/
http://www.dreaminco.../forum/32-java/
#28
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
http://www.toedter.c...endar/demo.html
#29
Posted 08 September 2012 - 01:04 PM
alpha02, on 08 July 2007 - 11:33 AM, said:
TheKingOfCodes, 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.
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
#30
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
|
|


MultiQuote










|