This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable cell formatting" Watch "JTable cell formatting" New topic

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?

Ryan Headley<br /><a href="" target="_blank" rel="nofollow"></a>
jeremy hull

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.
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 {
}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....
I agree. Here's the link:
subject: JTable cell formatting
It's not a secret anymore!