This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Alignment format on JTable

 
May Wong
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May- That sounds really what I would like to do. But think, is it an overkill ?.
-Rajesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic