Hi,
I would like to hear your opinion:
import java.awt.*;
import javax.swing.*;
public class BugExample2
{
private static class C1 extends JComponent
{
public C1()
{
Dimension d = new Dimension(200,200);
Dimension d2 = new Dimension(201,201);
setMinimumSize(d);
setMaximumSize(d2);
setPreferredSize(d);
setSize(d);
};
public void paint(Graphics g)
{
g.setColor(Color.BLACK);
g.drawLine(0,0,getWidth(),getHeight());
g.drawLine(getHeight(),0,getWidth(),0);
};
public void setSize(int x, int y)
{
System.out.println("setSize("+x+","+y+")");
super.setSize(x,y);
};
public void setSize(Dimension d)
{
System.out.println("setSize("+d.toString()+")");
super.setSize(d);
};
};
public static void main(String [] args)
{
JFrame f1 = new JFrame("F1");
f1.getContentPane().add(
new JScrollPane(
new C1(),
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
)
);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setVisible(true);
};
};
If You run above code and enlarge frame beond 201 pixels, you will see, that JScrollPane does not honour the value passed to setMaximumSize() and sets size for component to be greater than this limit.
What do You think - is this correct behaviour? Shouldn't it leave size untouched, change only the size JViewPort and let JViewPort paint missing space?
regards,
Tomasz Sztejka.
P.S.
If I make C1 to subclass java.awt.Canvas things are getting totally messed up.