Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I insert a JButton in a JTable cell????

Status
Not open for further replies.

Oxymoron

Technical User
Dec 17, 2000
168
GB
Hi,
I have a very standard JTable which just takes a 2 dimensional array of objects as normal and shows the String representation of these objects.
This I understand, however I know there is a way to insert other objects besids the allowed Components such as JComboBox, JCheckBox etc.

Here' what I tried, alas to no-avail.
-------------------code---------------------
JTable resultsTable = new JTable(data, columnNames);

TableColumn resultsColumn = resultsTable.getColumnModel().getColumn(4);
resultsColumn.setCellEditor(new showButton(new JButton("testing")));
----------------------------------------
inner class showButton
----------------------------------------
class showButton extends DefaultCellEditor
{
public showButton(JButton b)
{
super(new JCheckBox());
editorComponent = b;

setClickCountToStart(0);

}
}
------------------------------------------

I am very new to JTables so any and all suggstions and commnts will be very welcome!

Thanks,
Oxy we are all of us living in the gutter.
But some of us are looking at the stars.
 
me again, Iv found that my way of doing it does infact work when the table is setEnabled(true) but that means the entire table is editable.

I just need ONE column to be editable none of the TableColumn classes seem to allow this....there must be a way???

Any ideas?? I'd be very grateful,
Cheers, Oxy we are all of us living in the gutter.
But some of us are looking at the stars.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top