• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

components won't display unless window is resized

 
Andy Ranangnai
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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






 
Rob Camick
Ranch Hand
Posts: 2564
9
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
*deep exhale* thank you. I was about to smash my computer and go live in a cave.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic