Я использую JFrame, чтобы представить окно сообщения с некоторым текстом и 2 кнопками. Как мне автоматически обернуть текст в зависимости от размера поля?
Вот мой текущий код:
dialogFrame = new JFrame();
JButton newButton = new JButton("New");
newButton.addActionListener(new newUploadAction());
JButton resumeButton = new JButton("Resume");
resumeButton.addActionListener(new resumeUploadAction());
//dialogFrame.setUndecorated(true);
JPanel addPanel = new JPanel();
JPanel addPanel2 = new JPanel();
addPanel.add(newButton);
addPanel.add(resumeButton);
String text = "<html><p>A previous control file exists for this file. ";
text += "Would you like to initiate a new transfer or resume the previous one?</p></html>";
JLabel testLabel = new JLabel(text);
//testLabel.setPreferredSize(new Dimension(1, 1));
addPanel2.add(testLabel);
Container content = dialogFrame.getContentPane();
//content.setBackground(Color.white);
content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
content.add(addPanel2);
content.add(addPanel);
dialogFrame.setSize(200,200);
dialogFrame.setVisible(true);
dialogFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Я где-то читал, что зовет
testLabel.setPreferredSize(new Dimension(1, 1));
вызовет поведение обтекания, которое я хочу, но это просто привело к тому, что текст вообще не отображается.