• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

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: 22040
113
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: 71031
291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing Forum
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic