Article View: borland.public.jbuilder.java.swing
Article #1179how to re-pack JOptionPane
From: 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);
}
}
Technical Details
Message-ID:
<4010e23a$0$321$e4fe514c@news.xs4all.nl>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!transit.news.xs4all.nl!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,d7dd875c1d2ac239,start X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-01-23 00:58:35 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!transit.news.xs4all.nl!not-for-mail Message-ID: <4010e23a$0$321$e4fe514c@news.xs4all.nl> From: Dick <dickdijk@xs4all.nl> Subject: how to re-pack JOptionPane Newsgroups: borland.public.jbuilder.java.swing Date: Fri, 23 Jan 2004 10:02:36 +0100 User-Agent: KNode/0.7.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Lines: 49 NNTP-Posting-Date: 23 Jan 2004 09:58:34 CET NNTP-Posting-Host: 213.84.186.205 X-Trace: 1074848314 news.xs4all.nl 321 [::ffff:213.84.186.205]:12868 X-Complaints-To: abuse@xs4all.nl