Dears I tried what you've suggested and I made some progress but I still have some troubles that I can not understand.
here is my code:
public class ButtonTextCell extends AbstractCellEditor implements TableCellRenderer, TableCellEditor{
String value ="default";
JPanel panel = new JPanel();
JButton button;
JTextField text;
public ButtonTextCell(){
super();
button = new JButton("...");
button.setPreferredSize(new Dimension(16,16));
button.setFocusable(false);
button.setRolloverEnabled(false);
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//fireEditingStopped();
JOptionPane.showMessageDialog(null, "Hello");
//fireEditingStopped();
}
});
text = new JTextField(value);
text.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
value = text.getText();
//fireEditingStopped();
}
});
panel.setLayout(new BorderLayout());
panel.add(button,BorderLayout.EAST);
panel.add(text,BorderLayout.CENTER);
}
@Override
public Object getCellEditorValue() {
// TODO Auto-generated method stub
return null;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
//panel.setBackground(table.getSelectionBackground());
return panel;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
//text.setBackground(isSelected?table.getSelectionBackground():table.getBackground());
if(isSelected){
text.setBackground(table.getSelectionBackground());
button.setBackground(table.getSelectionBackground());
}else
text.setBackground(table.getBackground());
button.setBackground(table.getBackground());
if (value == null
|| value.toString().length() == 0)
return panel;
return panel;
}
}
and the problems are like the following:
1- sometimes when I run this code I get the table but the second column is empty, and I should do some action like resizing or clicking to show the components in the second column as photo number 1 shows.
2- when I click on the left column everything is ok and the complete row is selected, but when I click on the second column (the right one) just the right column is selected and the current one becomes white and all components disappear. beside when I click on the button sometimes the same scenario happens and the color of the button does not change when I click another one. it is shown in photo number 2
would you please check the code for me and tell what to do ... I believe there is something missing ...