• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JDialog too small for title

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Paula Davis
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic