how to re-pack JOptionPane

2004-01-23 05:02:36 PM
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() {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
//label.setText("kfhnwqeiv jglsgjdsfl; mgldsfmgdsf ,gmns;lfg
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
private static void createAndShowGUI() {
TestPanel tp = new TestPanel();
JOptionPane.showConfirmDialog(null, tp, "Set datafile",
JOptionPane.OK_CANCEL_OPTION, -1, null);