0

I'm trying to make a JDialog with the size of the JOptionPane that contains, but function getSize is returning something a little bit smaller than the JOptionPane and the button of accept is not seen.

I'm trying this:

JOptionPane panel = new JOptionPane(orden);
JDialog informa = panel.createDialog("Orden"); 
//panel.validate();
informa.setSize(panel.getSize());

where orden is a String with the info I want to display.

I'm not trying a scroll bar because it will be horizontal scroll and its uncomfortable.

EDIT: If I try to reach the size with

informa.setSize(panel.getWidth(),panel.getHeight());

It happens exactly the same, it gets the right width but it gets a little bit less height, so I guess the getHeight is failing.

MY SOLUTION: Just adding 25 to getHeight

informa.setSize(panel.getWidth(),panel.getHeight()+25);
Luis A.G.
  • 1,017
  • 2
  • 15
  • 23
  • 1
    Post an [MCVE](http://stackoverflow.com/help/mcve). Make sure it includes the `setVisible` calls and the parent of the dialogs. – user1803551 May 26 '14 at 12:44
  • What exactly are you trying to display, and what is the required functionality for the dialog? – Paul Samsotha May 26 '14 at 12:57
  • Is there a reason you aren't using [JOptionPane.showMessageDialog](http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html#showMessageDialog%28java.awt.Component,%20java.lang.Object%29), or one of the 3 others, method?? – Jonathan Drapeau May 26 '14 at 12:57
  • I'm not using showMessageDialog because I need to add 3 buttons with different functions. I'm displaying information from the selected row of a JTable, which contains data from database. And I need the buttons to fill an inform, to make an exportation file and to print another kind of inform. – Luis A.G. May 26 '14 at 14:15
  • MCVE is going to be a little bit complex here – Luis A.G. May 26 '14 at 14:21
  • Create your own JDialog using an appropriate layout manager(s) and don't use JOptionPane at all. Use the JDialog pack method to make the JDialog the preferred size of your Swing components. – Gilbert Le Blanc May 26 '14 at 14:33
  • MCVE is not complex by definition. – user1803551 May 26 '14 at 14:40
  • And your solution is not robust. – user1803551 May 26 '14 at 14:40
  • WOW [@trashgod](http://stackoverflow.com/users/230513/trashgod) IDFKW I didn't use it! I feel really ashamed now – Luis A.G. May 26 '14 at 15:27
  • SOMEONE TO CLOSE THIS QUESTION PLEASE – Luis A.G. May 26 '14 at 15:30
  • No shame; glad it helped; more on preferred size [here](http://stackoverflow.com/q/7229226/230513). – trashgod May 26 '14 at 15:51
  • Thank you, the worst is that I'm coding without using desing view and I have used pack for my messages dialogs – Luis A.G. May 26 '14 at 16:02

0 Answers0