• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

components won't display unless window is resized

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having a really weird problem with things being displayed on a JFrame. I was about to tear my hair out trying to get components to display on a JPanel that is sitting in a JFrame, but after I accidentally resized the window, everything showed up! After doing this several more times, I confirmed that my components were invisible until I adjusted the window, making it bigger or smaller or just clicking and holding it was sufficient to cause everyhting to appear.

I decided to put it aside for now, and moved on to another project. I wanted to test out the setSelectionStart and setSelectionEnd methods of JTextField, so I threw a simple JTextField onto a JFrame, and had the same problem! I'm going to attach both programs, I can't figure out what they both have in common that is causing this. I have tried running them on different computers and operating systems and still having the same problem, I thought it might be a linux problem at first, weird stuff happens to us after upgrades or moving seemingly unrelated things sometimes. Very exasperated, help appreciated.

Here's the one that really gets me, it's so small there's hardly any room to make a mistake, yet I still found a way >.<



Here's my first project (it's a program to quiz my cousin on her lefts and rights, long story), I'm fairly new to swing so I know the buttons don't do anything ;) I'm just arranging for now






 
Rancher
Posts: 3265
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code should be:



If you add components to the frame after it is visible then you need to revalidate() the JPanel that you add the components to.
 
Andy Ranangnai
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
*deep exhale* thank you. I was about to smash my computer and go live in a cave.
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic