Reputation: 927
I have a JTextField based cell editor that comes with this ugly black border (ignore the caret on the left):
Is there a way to remove it so it looks similar to this?
Upvotes: 2
Views: 170
Reputation: 324207
After creating the table you can try something like:
DefaultCellEditor editor = (DefaultCellEditor)table.getDefaultEditor(Object.class);
JTextField textField = (JTextField)editor.getComponent();
textField.setBorder( null );
Edit:
The above approach won't work because the JTable uses a GenericEditor
which is an inner class of the table that extend the DefaultCellEditor and adds extra functionality for the table.
One piece of functionality added is to manager the Border: "red" for errors and "black" for valid data. So the border is continually being reset by the editor.
Or the other approach would be something like:
JTextField textField = new JTextField();
textField.setBorder( null );
DefaultCellEditor editor = new DefaultCellEditor( textField );
table.setDefaultEditor(Object.class, editor):
Upvotes: 4