Morgan
Morgan

Reputation: 927

Remove cell editor border in JTable (Windows LaF)

I have a JTextField based cell editor that comes with this ugly black border (ignore the caret on the left):

enter image description here

Is there a way to remove it so it looks similar to this?

enter image description here

Upvotes: 2

Views: 170

Answers (1)

camickr
camickr

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

Related Questions