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

JScrollBar.getWidth() returns wrong value

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 Pro 1903

      java version "13.0.1" 2019-10-15
      Java(TM) SE Runtime Environment (build 13.0.1+9)
      Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      See synopsis

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The width of the vertical scrollbar will be at least 30 points.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;
      import javax.swing.table.*;

      public class ScrollBarWidth extends JFrame {

        public ScrollBarWidth() {
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(300, 150);

          String headers[] = {"Fruit", "Colour"};
          String data[][] = {
      {"Tomato", "Red"},
      {"Banana", "Yellow"},
      {"Orange", "Orange"},
      {"Kiwi", "Green"},
      {"Grape", "Red blue"},
      {"Grape", "Green"},
      {"Plum", "Blue"}
      };

          TableModel model = new DefaultTableModel(data, headers);
          JTable table= new JTable(model);
          TableColumnModel tcm= table.getColumnModel();
          tcm.getColumn(0).setPreferredWidth(200);
          tcm.getColumn(1).setPreferredWidth(100);
          JScrollPane scrollPane= new JScrollPane(table);
          add(scrollPane, BorderLayout.CENTER);
          setVisible(true);
          System.out.println(tcm.getColumn(0).getWidth());
          System.out.println(tcm.getColumn(1).getWidth());
          System.out.println(scrollPane.getVerticalScrollBar().getWidth());
        }


        public static void main(String args[]) {
          EventQueue.invokeLater(ScrollBarWidth::new);
        }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              amrsahu Amresh Sahu
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: