public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable() {
public void run()
{
initGui();
}
});
}
public static void initGui()
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
JPanel innerPanel = new JPanel(new BorderLayout());
innerPanel.setBackground(Color.RED);
final JPanel controllPanel = new JPanel(null);
JButton biggerButton = new JButton("Make bigger");
biggerButton.setBounds(0, 0, 200, 50);
controllPanel.add(biggerButton);
JButton smallerButton = new JButton("Make smaller");
smallerButton.setBounds(0, 100, 200, 50);
controllPanel.add(smallerButton);
JScrollPane mainScrollPane = new JScrollPane(innerPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
frame.add(mainScrollPane);
JScrollPane innerScrollPane = new JScrollPane(controllPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
innerPanel.add(innerScrollPane);
biggerButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
Dimension prefSize = controllPanel.getPreferredSize();
prefSize.width+= 1000;
prefSize.height+= 1000;
controllPanel.setPreferredSize(prefSize);
controllPanel.revalidate();
}
});
smallerButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
Dimension prefSize = controllPanel.getPreferredSize();
prefSize.width-= 1000;
prefSize.height-= 1000;
controllPanel.setPreferredSize(prefSize);
controllPanel.revalidate();
}
});
frame.setVisible(true);
}