I want to resize JScrollPane programmatically. I do not want to resize viewport of JScrollPane but JScrollPane itself together with parent JDialog.
So far I tried to setPreferredSize of JScrollPane and revalidate it but it does not work. Here is my code that creates JScrollPane and adds it into JDialog.
public ConnectionTreeTooltip(MainFrame parent) {
super(parent, "", false);
super.setUndecorated(true);
JPanel contentPane = (JPanel) super.getContentPane();
contentPane.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.blue, Color.red));
tipLabel = new JLabel();
tipLabel.setBackground(Color.WHITE);
scrollPane = new JScrollPane(tipLabel);
scrollPane.setPreferredSize(new Dimension(100, 100));
scrollPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 1, 1));
// super.setLayout(new BorderLayout());
super.getContentPane().add(scrollPane);
super.pack();
}
So I have my JScrollPane created all right and its viewport is automatically resized whenever text of JLabel changes.
How to resize JScrollPane itself together with parent JDialog?
Thank you!