Thread View: borland.public.jbuilder.java.swing
1 messages
1 total messages
Started by Dick
Fri, 23 Jan 2004 09:02
how to re-pack JOptionPane
Author: Dick
Date: Fri, 23 Jan 2004 09:02
Date: Fri, 23 Jan 2004 09:02
48 lines
2762 bytes
2762 bytes
I you have a JOptionPane with a JButton and a JLabel, in the event handler
of the JButton I do a label.setText("very long text,.. blah etc").
When I click the button I would expect the JOptionPane to resize so that the
JLabel shows the whole text, but that does not happen. I found out that The
label doesn't show anything when the length of the text exceeds a certain
value. How can you force the JOptionPane to recalculate its layout?
Here is my test program:
public class TestPanel extends JPanel {
JButton button = new JButton("pack");
JLabel label = new JLabel("");
StringBuffer sb = new StringBuffer();
public TestPanel() {
add(button);
add(label);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
//label.setText("kfhnwqeiv jglsgjdsfl; mgldsfmgdsf ,gmns;lfg
gfegvnjeqrp");
sb.append("aap");
label.setText(sb.toString());
}
});
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
TestPanel tp = new TestPanel();
JOptionPane.showConfirmDialog(null, tp, "Set datafile",
JOptionPane.OK_CANCEL_OPTION, -1, null);
}
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads