Reputation: 10330
Trying to set size of a JOptionPane but it's sticking with the same size. I've tried setPreferredSize and setSize but for some reason the JOptionPane is sticking with the same width and height. Basically I have a bunch of text and it's being "cut off" because of the size of the window.
I'm actually using a port of the swing library in another language, so it could be a bug with their library - but according to the docs it should mirror the Java Swing calls.
Am I missing something?
edit - wanted to add that I create the joptionpane with JOptionPane.showInputDialog
edit again - i'm using ASwing (actionscript port of Java Swing - hence there might be api differences though it's supposed to be a port...)
Upvotes: 0
Views: 13917
Reputation: 11
You can just as well override setSize by extending our Componemt:
public class Headerfield extends JLabel
{
public Headerfield(String text)
{
super(text);
}
public void setSize(int width, int height)
{
super.setSize(100, 20);
}
}
Upvotes: 0
Reputation: 30698
It is good idea to create a JPanel with prefereed size or JTextArea with JScrollPane scrollbars and add it to optionpan.
It's easy to do, and not only sets the size of the dialog but allows great flexibility of content.
JTextArea mytext = new JTextArea();
mytext.setText("mytextline1\nmytextline2\nmytextline3\nmytextline4\nmytextline5\nmytextline6");
mytext.setRows(5);
mytext.setColumns(10);
mytext.setEditable(true);
JScrollPane mypane = new JScrollPane(mytext);
Object[] objarr = {
new JLabel("Enter some text:"),
mypane,
};
JOptionPane Optpane = new JOptionPane(objarr, JOptionPane.PLAIN_MESSAGE);
see details
Upvotes: 5
Reputation: 10330
Actually, found the fix. The ported library built the JOptionPane I guess slightly different than the Java version.
optionpane.getFrame().setSize()
(using ASwing - Actionscript port of Java Swing)
Upvotes: 1