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

javax.swing.TableColumn.setMinWidth() doesn't update preferred width.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.2.2
    • client-libs



      Name: skT45625 Date: 08/14/2000


      java version "1.2.2.Symc"
      Classic VM (build 1.2.2.Symc, native threads, symantec gc, symcjit)

      I created my own TableColumnModel and inherited from DefaultTableColumn.

      In the constructor I filled the rows like this:

      public DocumentColumnModel() {
      setColumnMargin(1);
      setColumnSelectionAllowed(false);
      for(int i = 0; i < _header.length; i++) {
      TableColumn col = new TableColumn(i);
      col.setHeaderValue(_header[i].getName());
      col.setMinWidth(_header[i].getWidth());
      addColumn(col);
      }
      }

      The JTable using this TableColumnModel was displayed in a JScrollPane and here
      the problem surfaced: although the DocumentColumnModel.getTotalColumnWidth()
      did show the correct width of the tablecontents but the JTable itself was way
      too small and therefore I couldn't scroll to the rightmost columns.
      The tables AutoResizeMode was set to JTable.AUTO_RESIZE_OFF.

      The solution of this problem lies within the implementation of
      TableColumn.setMinWidth(int):

          public void setMinWidth(int minWidth)
          {
      this.minWidth = Math.max(minWidth, 0);

      if (width < minWidth) {
      setWidth(minWidth);
      }
          }

      As you can see setWidth() is called if the current(?) width is smaller than the
      new minWidth but the preferred width is not checked. On a side note: the
      maximum width neither.

      Obviously (although I haven't found the location in the source) what happens
      is, that somewhere in the process of rendering the table the (unadjusted)
      preferred width is used to calculate the width of the table but the real width
      is used for drawing.

      As a solution I would propose to do quite a bunch of crosschecks more in those
      TableColumn.set*Width() routines.
      (Review ID: 108396)
      ======================================================================

            apikalev Andrey Pikalev
            skondamasunw Suresh Kondamareddy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: