• Post Reply Bookmark Topic Watch Topic
  • New Topic

Set size for JOptionPane?  RSS feed

 
Kari Nordmann
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to set a size(width) for the JOptionPane, and have text in it resize to fit it? Instead of either using \n to cut the text in two lines and having the JOptionPane resize to fit the text.

Or do I have to create a panel\contentpane to do this?
Maybe it's possible to put a JTextArea in the optionpane?
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JOptionPane methods can take any Object as its second argument. This object is usually a String with a message, but it can be multiple things. Some I've used quite often are a String[], where each element will appear on a new line, or a Component. Guess what that does
 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this post would fit better in the Swing forum. Moving.

My 4000th post! What an exciting post it is, too. :roll:
[ June 06, 2008: Message edited by: Campbell Ritchie ]
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or do I have to create a panel\contentpane to do this?
Maybe it's possible to put a JTextArea in the optionpane?

I often create a JPanel, one whose preferredSize I've set, as the Object passed to the JOptionPane. It's easy to do, and not only sets the size of the dialog but allows great flexibility of content.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!