How to save JTable columns when resizing while resizing JFrame?

This code puts the JTable in a JFrame (the only component of the whole UI):

    JFrame frame = new JFrame( "Title");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTable table = appender.createTable();
    JScrollPane scrollPane = new JScrollPane(table);
    table.setFillsViewportHeight(true);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);

    frame.pack();
    frame.setVisible(true);

I also have code to set the preferred column size.

Nothing unusual. When the user interface opens, the table takes up the whole view, and I don't have scrollbars. Combined preferred column widths require more horizontal space than windows. Despite this, there is no horizontal scrollbar, and the columns are too narrow.

What do I need to do

  • Columns are still user editable
  • Is the width of the current width taken into account? That is, when I change the width of one column, the width of the other columns should not change.
+3
1
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );

, , JPanel, . , , scrollpane.

+3

Source: https://habr.com/ru/post/1756768/


All Articles