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

Funny behavior of JTable column resizing in JScrollPane (Swing1.1beta3 vs 1.0.3)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs



      Name: clC74495 Date: 11/26/98


      Under Swing1.0.3, the code below exhibited fairly nice behavior for
      JTable column header resize in a JScrollpane. In Swing1.1beta3, the
      behavior is different/unexpected/unacceptable. Happens under jdk1.1.7a
      w/swing1.1beta3 jar (or jdk1.2RC2 w/plugin), Win95, IE 4.01 w/SP1.
      Perhaps with all the JTable resizing updates, I've missed something
      new that I should be doing to avoid this behavior.

      Steps to reproduce:
      1) Scroll the JTable in "Test" JIF all the way to the right (so that at least
         Column A is not in view).
      2) Pull the column header divider between cols D & E to the left. Problem:
         Columns C, B etc. scoot over to the right as column D's size is reduced.
         Under Swing1.0.3, columns C,B etc. did not scoot over to the right as
         column D's size was reduced. You have to compile/run the code under
         both releases to see what I talking about. Results in Column D's size
        being reduced too quickly (unexpected).

      Perhaps this is by design through new implementation of the options
      I'm using below.

      html:
      <html>
      <head>
      <title>Swing bug demo #1</title>
      </head>
      <body>
      <applet code=LT3Test width=700 height=500>
      </applet>
      </body>
      </html>

      code (sorry for indentation & wraps):
      import java.awt.*;
      import java.applet.*;
      import java.text.*;
      import java.awt.event.*;
      import java.util.*;
      import java.beans.*;

      /* Importing SWING 1.0.1 classes. Will need to reduce these to the actual classes used. */
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.text.*;
      import javax.swing.border.*;
      import javax.swing.table.*;

      public class LT3Test extends JApplet
      {
      public void init()
      {
             TableModel dataModel = new AbstractTableModel() {
                 public int getColumnCount() { return 5; }
                 public int getRowCount() { return 5;}
                 public Object getValueAt(int row, int col) {
                   return new Integer(((5-row)*(5-col)));
                 }
             };
             
             // Create splitpane with JTree on left to show divider swipe problem....
             JSplitPane innerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
             JTree jt = new JTree();
             JScrollPane scrollTree = new JScrollPane(jt);
             scrollTree.setBorder(BorderFactory.createTitledBorder("TestTree:"));
             
             // subpanel will hold 2 JIFs with button & table
             JPanel jp = new JPanel();
             jp.setLayout(new BoxLayout(jp,BoxLayout.Y_AXIS));
             
             JTable table = new JTable(dataModel);
             // Show annoying resize behavior for cols when scrolled to right
             table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
             JScrollPane scrollpane = new JScrollPane(table);
             JButton jb = new JButton("test");
             jp.add(jb);
             jp.add(scrollpane);
             JInternalFrame jif = new JInternalFrame("test",true, true, true, true);
             jif.getContentPane().add(jp,BorderLayout.CENTER);
             jif.setBounds(50, 50, 200, 200);
             
             JTable table2 = new JTable(dataModel);
             table2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
             JScrollPane scrollpane2 = new JScrollPane(table2);
             JPanel jp2 = new JPanel();
             jp2.setLayout(new BoxLayout(jp2,BoxLayout.Y_AXIS));
             JButton jb2 = new JButton("test2");
             jp2.add(jb2);
             jp2.add(scrollpane2);
             JInternalFrame jif2 = new JInternalFrame("test2",true, true, true, true);
             jif2.getContentPane().add(jp2,BorderLayout.CENTER);
             jif2.setBounds(300, 50, 200, 200);
             
             JDesktopPane lc = new JDesktopPane();
             lc.add(jif,BorderLayout.CENTER);
             lc.add(jif2,BorderLayout.CENTER);
             lc.validate();
             lc.setVisible(true);
             
             innerPane.setLeftComponent(scrollTree);
             innerPane.setRightComponent(lc);
             
             getContentPane().add(innerPane,BorderLayout.CENTER);
             getContentPane().validate();
      }
      }
      (Review ID: 43368)
      ======================================================================

            pmilnesunw Philip Milne (Inactive)
            clucasius Carlos Lucasius (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: