|
|
Return
to JAVA table list |
Best books about JAVA programming:
|
JAVA JTable JButton
cells
The following code add Jbutton in JTable columns.
This program involes 3 JAVA file:
JButtonTableExample.java, ButtonEditor.java, ButtonRenderer.java
//Example modified from http://www.crionics.com/products/opensource/faq/swing_ex/JTableExamples2.html
/**
* @version 1.0 12/03/98
*/
/* (swing1.1beta3) */
/* (swing1.1beta3) */
/* (swing1.1beta3) */
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
/**
* @version 1.0 11/09/98
*/
public class ButtonRenderer extends JButton implements TableCellRenderer
{
public ButtonRenderer() {
setOpaque(true);
}
public Component getTableCellRendererComponent(JTable table, Object
value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());
setBackground(table.getSelectionBackground());
} else{
setForeground(table.getForeground());
setBackground(UIManager.getColor("Button.background"));
}
setText( (value ==null) ? "" : value.toString() );
return this;
}
}
|
|
|