• 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

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: 3324
32
  • 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.
 
What are you doing? You are supposed to be reading 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