Article View: borland.public.jbuilder.java.swing
Article #12376Re: How to add a JButton to a cell of JTable?
From: Praveen_Jani
Date: Fri, 15 Jan 1999 00:00
Date: Fri, 15 Jan 1999 00:00
47 lines
2478 bytes
2478 bytes
Hi, You can add a button fair simple. Yes it takes only 3 components in cell.
But you can very wel make swing fool. Here sending you a piece of code. lets
see if it helps you. Use code like this as a editor for the cell.
Bye
-Praveen
class ColorEditor extends DefaultCellEditor {
Color currentColor = null;
public ColorEditor(JButton b) {
super(new JCheckBox()); //Unfortunately, the constructor
//expects a check box, combo box,
//or text field.
editorComponent = b;
setClickCountToStart(1); //This is usually 1 or 2.
//Must do this so that editing stops when appropriate.
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fireEditingStopped();
}
});
}
protected void fireEditingStopped() {
super.fireEditingStopped();
}
public Object getCellEditorValue() {
return currentColor;
}
public Component getTableCellEditorComponent(JTable table,
Object value,
boolean isSelected,
int row,
int column) {
((JButton)editorComponent).setText(value.toString());
currentColor = (Color)value;
return editorComponent;
}
}
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Technical Details
Message-ID:
<77nn30$c31$1@nnrp1.dejanews.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3687B08F.3DE9C3F3@rz.hu-berlin.de> <76on45$76h4@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,5ecb4afb31fd709d X-Google-Attributes: gid111d45,public From: Praveen_Jani@hotmail.com Subject: Re: How to add a JButton to a cell of JTable? Date: 1999/01/15 Message-ID: <77nn30$c31$1@nnrp1.dejanews.com> X-Deja-AN: 432961933 References: <3687B08F.3DE9C3F3@rz.hu-berlin.de> <76on45$76h4@forums.borland.com> X-Http-Proxy: 1.0 x4.dejanews.com:80 (Squid/1.1.22) for client 202.54.48.119 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Fri Jan 15 15:32:47 1999 GMT Newsgroups: borland.public.jbuilder.java.swing X-Http-User-Agent: Mozilla/4.04 [en] (Win95; I)