Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table various UI issues #332

Closed
Chrriis opened this issue May 26, 2021 · 1 comment
Closed

Table various UI issues #332

Chrriis opened this issue May 26, 2021 · 1 comment
Milestone

Comments

@Chrriis
Copy link
Contributor

Chrriis commented May 26, 2021

Hi!

I see a certain number of odd behaviors related to tables.
TableIssues1

  • I think it is a bug that focus indication is visible for boolean column (it is not the case for other columns).
  • Selection background stops 1px before the end of the row.
  • It feels odd to miss the last separator line when the vertical scroll bar is showing: it is as if there is more content going under the scroll bar.
  • It feels odd to have the resize cursor on the header of the end of the last column.

Test code:

public static void main(String[] args) throws Exception {
	UIManager.setLookAndFeel(new FlatLightLaf());
	// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	UIManager.put("Table.showVerticalLines", Boolean.TRUE);
	UIManager.put("Table.showHorizontalLines", Boolean.TRUE);
	UIManager.put("Table.intercellSpacing", new Dimension(1, 1));
	UIManager.put("Table.gridColor", new Color(0xd9d9d9));
	JFrame frame = new JFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	JPanel centerPane = new JPanel(new GridBagLayout());
	centerPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
	Object[][] data = new Object[][] { { "Cell 1_1", Boolean.FALSE, "Cell 1_3" }, { "Cell 2_1", Boolean.TRUE, "Cell 2_3" }, { "Cell 3_1", Boolean.TRUE, "Cell 3_3" } };
	String[] titles = new String[] { "Column1", "Column2", "Column3" };
	AbstractTableModel tableModel = new AbstractTableModel() {
		@Override
		public Object getValueAt(int rowIndex, int columnIndex) {
			return data[rowIndex][columnIndex];
		}
		@Override
		public int getRowCount() {
			return data.length;
		}
		@Override
		public int getColumnCount() {
			return titles.length;
		}
		@Override
		public Class<?> getColumnClass(int columnIndex) {
			return columnIndex == 1 ? Boolean.class : String.class;
		}
	};
	JTable table1 = new JTable(tableModel);
	centerPane.add(new JScrollPane(table1), new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 2, 0), 0, 0));
	JTable table2 = new JTable(tableModel);
	JScrollPane scrollPane2 = new JScrollPane(table2);
	scrollPane2.setMinimumSize(new Dimension(60, 60));
	centerPane.add(scrollPane2, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
	centerPane.add(new JTextField(14), new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
	frame.getContentPane().add(centerPane);
	frame.setSize(400, 300);
	frame.setVisible(true);
}

Another problem related to the last vertical separator not being painted is when we create advanced tables using a composition of tables. Here is an example taken from a real-world application with FlatLaf, where the first column is a separate table acting like a row header, the second column is a "frozen" (tree) table so that only the rest (a third table) can scroll. At every end of table the separator is missing although it should not in this case:
TableIssues2

Is there a global property to paint the last vertical separator? Is there a per-table property to activate/deactivate the painting of the last separator?

And once again, thanks a lot for the great work! 😉

DevCharly added a commit that referenced this issue Sep 5, 2021
…st column is not possible because auto resize mode of table is not off (issue #332)
DevCharly added a commit that referenced this issue Sep 13, 2021
@DevCharly
Copy link
Collaborator

DevCharly commented Sep 13, 2021

I think it is a bug that focus indication is visible for boolean column (it is not the case for other columns).

Yes. It is actually a Swing bug in class JTable.BooleanRenderer, which does not use Table.focusSelectedCellHighlightBorder for selected cells (as DefaultTableCellRenderer does). Instead Table.focusCellHighlightBorder is used.

I tried to fix this in cell border FlatTableCellBorder.Focused (as done in class FlatTableCellBorder.Selected), but this does not work because the border does not know what cell it is painting and can not determine whether the cell is selected.

Selection background stops 1px before the end of the row.

Yes, because the last vertical separator line is hidden 😉
It would be necessary to make the cells in last column wider.
Can't fix this (at the moment) because table cell painting methods are all private.
A fix requires re-implementation of table cell painting in FlatLaf, which is a larger task.
(copying source code from BasicTableUI is not allowed because of incompatible licenses)

It feels odd to miss the last separator line when the vertical scroll bar is showing: it is as if there is more content going under the scroll bar.

but then is looks odd when there is no scroll bar:

image

A workaround would be to add a border to the vertical scrollbar. E.g.:

scrollPane2.getVerticalScrollBar().setBorder( new MatteBorder( 0, 1, 0, 0, UIManager.getColor( "Table.gridColor" ) ) );

It feels odd to have the resize cursor on the header of the end of the last column.

Actually a bug in Swing, but I found a workaround and fixed it in commit d508f33

Another problem related to the last vertical separator not being painted ...

Fixed in commit fa194ec

Is there a global property to paint the last vertical separator? Is there a per-table property to activate/deactivate the painting of the last separator?

Yes, since commit 824db2e and 578379f you can use:

UIManager.put( "Table.showTrailingVerticalLine", true );
UIManager.put( "TableHeader.showTrailingVerticalLine", true );

@DevCharly DevCharly added this to the 1.6 milestone Sep 13, 2021
DevCharly added a commit that referenced this issue Sep 14, 2021
…lLine` to `Table[Header].showTrailingVerticalLine` (issue #332)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants