-
Bug
-
Resolution: Fixed
-
P4
-
1.1.7
-
beta
-
x86
-
windows_nt
Name: dbT83986 Date: 04/25/99
// Construst some frame that contains the following scroll pane
.
.
// The problem
JScrollPane sp = new ScrollPane(...);
JScrollBar sb = sp.getVerticalScrollBar();
sb.setPrefferedSize(new Dimension(30,30));
.
.
In this case, the ScrollBar will be about twice wider then the default.
Its arrow button will get wider too, but they will not get 'higher'
in order to become a square (as they are in the default situation).
There is no way to change it with the existing interfaces of the JScrollBar
and/or its UI class.
The problem is caused by the following method in the
package javax.swing.plaf.basic.BasicArrowButton class:
public Dimension getPreferredSize()
{
return new Dimension(16, 16);
}
Here is a code you can copy-paste, compile and run:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ScrollBarDemo
{
public static void main(String[] str)
{
ScrollBarDemo s = new ScrollBarDemo();
}
public ScrollBarDemo()
{
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception exc)
{
System.err.println("Error loading L&F: " + exc);
System.exit(0);
}
JFrame frame = new JFrame();
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
JPanel panel = new JPanel();
JPanel p1 = new JPanel(new BorderLayout());
JComboBox cb = new JComboBox(new String[] {"a","b","c","d","e","f"});
cb.setMaximumRowCount(5);
p1.add(cb, BorderLayout.NORTH);
JScrollPane sp = new JScrollPane(p1);
sp.setPreferredSize(new Dimension(200,200));
sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// This is the code 'widening' the scrollbars. The arrow buttons get wider too,
// but their height (or width in the case of the horizontal scroll bar) does not
// get larger proportionally.
sp.getVerticalScrollBar().setPreferredSize(new Dimension(30,30));
sp.getHorizontalScrollBar().setPreferredSize(new Dimension(30,30));
panel.add(sp);
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
}
}
(Review ID: 57306)
======================================================================