aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable cell formatting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable cell formatting" Watch "JTable cell formatting" New topic
Author

JTable cell formatting

ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
Is there a way in a JTable to "merge" cells. In other words, for each label on the left side of the table I need to cells. Say I was making some sort of scheduling program.
For any specific time I would need whether or not its available, and the last name of the person they are to meet with, etc.
I suppose I could just say its booked and have them click to open another window for more info, but in that case how do I add a listener to that specific cell?
Thanx


Ryan Headley<br /><a href="http://www.sudovi.com" target="_blank" rel="nofollow">http://www.sudovi.com</a>
jeremy hull
Greenhorn

Joined: Jan 18, 2001
Posts: 10
Take a look at a common approach to doing row oriented tables. You can have separate tables that are side-by-side, but line up, appearing to be one table. I have not done it myself, but have seen it done and it looks good, although it may be kinda slow.
Sanjay Bahrani
Ranch Hand

Joined: Apr 17, 2001
Posts: 38
Hi there,
You want to add the listeners to each cell, yeah you can do this by using ListSelectionListener. You have to add this listener to both rows and columns of the table so that each cell can react to the listener. I am giving you the example for this.
Example:
code....
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSelection=table.getSelectionModel();
rowSelection.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent le) {
try {
if(le.getValueIsAdjusting()) return;
ListSelectionModel lsm= (ListSelectionModel)le.getSource();
if (lsm.isSelectionEmpty()) {
//Nothing to Do
}
else {
table.setCellSelectionEnabled(true);
table.setRowSelectionAllowed(false);
selectedRow=lsm.getMinSelectionIndex();
}catch(NumberFormatException ex) {}
}
});
The above code is for only the row, same way you have to use for column also.
I have used this in Calendar(Swing application), when you select a date in a calendar (Dates resides in the cells of the table) it will give you the weekday for a particular date. I had added the Listener on each cell in this way....
Regards.
 
 
subject: JTable cell formatting