• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

restrictions on resizing JFrame

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there.

i just want to ask,

well, i have here a JFrame size set as 1024 x 768.
it is resizable.

what i want to know is, how can i restrict the frame from resizing when it reaches 800 x 600?

i mean, when resized, the smallest possible size of the frame must be 800 x 600 and will not go smaller than that.

any suggestions are very much appreciated. thank you.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try out setPreferredSize()
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> what i want to know is, how can i restrict the frame from resizing when it reaches 800 x 600?

presume you mean resize smaller

the only way I've seen possible do do what you want is to add this line
(prior to creating the frame)
JFrame.setDefaultLookAndFeelDecorated(true);
then
frame.setMinimumSize(new Dimension(800,600));

problem is java's default L&F is not the best looking.

a hack is to add a windowListener which snaps it back to 800,600 if smaller,
then, when snapped-back, you could add code to make it not resizable
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, since Java 5.0 the call to JFrame.setDefaultLookAndFeelDecorated(true); is no longer needed. The minimum size is now adhered to with at least the default look&feel (Metal), the Motif look and feel and the Windows look and feel.
 
Everybody's invited. Except this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic