Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JFrame problem

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats wrong with my code, ive got a problem, it shows a blank frame, but when i resize it, the button and the textfield will appear

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are constructing your GUI after the frame is made visible, and never re-validating it (and another nono is you are doing it outside the event dispatch thread but that is minor).

Reorder the code so the JPanel is made and added to the Frame before the frame.setVisible() method is called. You should also set the size of the Frame before making it visible.
 
Sheriff
Posts: 21999
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call frame.pack(). It will set the size automatically to its preferred size. And also move the setVisible(true) call to the end as Steve suggested.
 
Marshal
Posts: 70276
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing Forum
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic