Creating a calendar viewer application GUIs, renderers, JTable tutorial
#16 Guest_Metsis*
Posted 31 May 2010 - 02:18 AM
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
Metsis
#18
Posted 31 May 2010 - 10:56 AM
Josko
#19 Guest_Adnan*
Posted 01 August 2010 - 06:47 PM
#20
Posted 06 August 2010 - 01:58 AM
#21
Posted 18 September 2010 - 06:08 AM
dipito31, on 22 April 2010 - 06:52 AM, said:
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
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
/*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
//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
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
http://www.dreaminco.../forum/32-java/
#28
Posted 26 April 2011 - 02:03 PM
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:
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
|
|


MultiQuote










|