プログラムで JScrollPane のサイズを変更したい。JScrollPane のビューポートのサイズを変更したくはありませんが、JScrollPane 自体は親 JDialog と一緒にサイズ変更します。
これまでのところ、JScrollPane の setPreferredSize を再検証しようとしましたが、機能しません。JScrollPane を作成して 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();
}
そのため、JScrollPane を適切に作成し、JLabel のテキストが変更されるたびにビューポートのサイズが自動的に変更されます。
親JDialogと一緒にJScrollPane自体のサイズを変更するには?
ありがとうございました!