Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable and JButton question

 
Ramses Butarbutar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, ,

I made a sample testing class of JTable.. and create each data as object based on columnNames.
And i want to put a button in JTable but it's doesn't work.. only show up text(javax.swing.JButton..).
How can i do this.. put a button into JTable??


Thanks..

Ramses,
 
Ramses Butarbutar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hehe.. sorry all, I'm too lazy to think today...
I just remember what i need to display a jbutton in a jtable..
I have to make my own TableCellRenderer, get component which return component as the renderer.. and next step is to make TableModel that implement the return because DefaultTableModel is designed to work with "DefaultTableCellRenderer" that return string...
And final step is creating buttonmouselistener for action..

Thanks guys for your attention..

Ramses
 
Rob Camick
Ranch Hand
Posts: 2539
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its more complicated than that. You need a custom renderer and a custom editor.

The Table Button Column entry can help you out.
 
Ramses Butarbutar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:Its more complicated than that. You need a custom renderer and a custom editor.

The Table Button Column entry can help you out.


I've read your clue.. So what you have written in your class is basicly to specify column that is used to contain the button so renderer and editor can perform invoke action based on row number of clicked button...
Hmm... great thought...
What that i want to point in my previous message is to handle what DefaultTableCellRenderer can't handle if return value is component..so we have to customize to get getTableCellRendererComponent() which returns a java.awt.Component that knows how to draw the contents of a specific cell.
To maintain the column is the job of TableCellRenderer, it will return same component for every cell of the column..
I think that the simply way to implement a button in a table..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic