This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Alignment format on JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Alignment format on JTable" Watch "Alignment format on JTable" New topic
Author

Alignment format on JTable

May Wong
Greenhorn

Joined: Feb 19, 2002
Posts: 8
Hi,
I'm working on GUI part now. I created my own TableModel class say, FlightTableModel, by extending AbstractTableModel interface. Since I use DataInfo[] to hold the data in FlightTableModel and DataInfo holds a String array. So, all the data display on JTable will be String type and will be left aligned. I feel uncomfortable everytime I saw the Price and AvailableSeats data are left aligned.
Could you please tell me what did you realize the right alignment? Or just let it be left?
Thank you for your help.
May
Rajesh Matti
Ranch Hand

Joined: Jan 07, 2002
Posts: 121
For this assignment, you can do it simply by overiding the method "public Class getColumnClass(int columnIndex)" and returing Integer.class for the column index in question and String.class for the rest.
May Wong
Greenhorn

Joined: Feb 19, 2002
Posts: 8
Hi Rajesh,
Thank you for your help. I happened to define my own FTable extends JTable. So, it's very easy to override. Now, I feel much more comfortable.
May
Rajesh Matti
Ranch Hand

Joined: Jan 07, 2002
Posts: 121
May- I am bot happy about subclassing JTbale for the purpose you have mentioned. Never extend anything if the framework already allows a way to do it, that is exactly sun mentioned in its requirement.
May Wong
Greenhorn

Joined: Feb 19, 2002
Posts: 8
Oops, I didn't notice that.Thanx Rajesh!!
In order to make the GUI look good. I added some functions on Swing components. For example, everytime when the mouse moves into button area the foreground color of the button will be changed. Since there are several buttons in my GUI, I created my own FButton class by extending JButton to let me use it more conveniently. Do you think is it OK?
Does anybody do the same thing as me?
Rajesh Matti
Ranch Hand

Joined: Jan 07, 2002
Posts: 121
May- That sounds really what I would like to do. But think, is it an overkill ?.
-Rajesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Alignment format on JTable
 
Similar Threads
L&F JTable Guidelines
Alignment format on JTable
Refresh JTable
My Swing JTable won't work!
JTable number renderer