Forums Register Login

JDialog too small for title

+Pie Number of slices to send: Send
I want to create and display a JDialog whose contents and title are specified at runtime. I can't rely on hard-coding the size through , because the contents and title are determined at runtime. The dialog is smart enough to size itself for the component being placed on it, but the title gets truncated. How to force it to accommodate the title?

Here is a simplified version, which demonstrates the problem I'm having while shortening the code sample to a few lines:


Thanks.
+Pie Number of slices to send: Send
You could set a preferred/minimum size that reflects the length of the title. The FontMetrics class can tell you how many pixels a given string will take up in a given font.
+Pie Number of slices to send: Send
Thanks for pointing me in the right direction, Ulf.

This works:


For some reason, setPreferredSize(Dimension) and setMinimumSize(Dimension) did not render the JDialog with the desired size... I don't know why... but since setSize(Dimension) worked, I'm good to go.

Thanks again.
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2719 times.
Similar Threads
In the swing of JFrame.setFocusableWindowState (false),Corresponds to what is in the method in swt
JOptionPane question
Not able to add scroll bar for a JPanel.
Modal JWindow
JPopupMenu: add JComboBox, close via JButtons
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:43:51.