Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8234071

JTable.AUTO_RESIZE_LAST_COLUMN acts like AUTO_RESIZE_ALL_COLUMNS

XMLWordPrintable

    • b08
    • x86
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      MacBook Pro 2018 / Catalina / 1.8.0_221

      A DESCRIPTION OF THE PROBLEM :
      When I resize a window after having called JTable.setAutoResizeMode with AUTO_RESIZE_OFF (or AUTO_RESIZE_ALL_COLUMNS), then I get expected results described in the javadocs.

      When I call it with AUTO_RESIZE_LAST_COLUMN, then I get behavior exactly as if I specified AUTO_RESIZE_ALL_COLUMNS.

      I see the title of bug 4098154 but I can't see its content to determine if my bad behavior is the same. I also can't see if there is a workaround.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Overall, run the source code after changing the constant from AUTO_RESIZE_ALL_COLUMNS to AUTO_RESIZE_LAST_COLUMN. Then you will see the same behavior from the application when you resize the window's width.

      1. Run the code.
      2. Use the window manager to change the window's width.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When using AUTO_RESIZE_LAST_COLUMN, I expect only the rightmost column to be resized. When I use AUTO_RESIZE_ALL_COLUMNS, I expect all columns to be resized.
      ACTUAL -
      When I use AUTO_RESIZE_LAST_COLUMN, then all columns are resized when I change the window's width. This is not expected.

      When I use AUTO_RESIZE_ALL_COLUMNS, then all columns are resized when I change the window's width. This is expected.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      public class ScrollableJTable extends JPanel {
          public ScrollableJTable() {
              setLayout(new BorderLayout());
              JTable table = new JTable(10, 10);
              table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); // vary the constant
              JScrollPane pane = new JScrollPane(table);
              add(pane, BorderLayout.CENTER);
          }
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      JPanel panel = new ScrollableJTable();
                      JFrame frame = new JFrame();
                      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                      frame.setContentPane(panel);
                      frame.pack();
                      frame.setVisible(true);
                  }
              });
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None yet. I've tried using a TableColumnModelListener but it has significant problems.

      FREQUENCY : always


            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: