my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Question regarding JFrame in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Question regarding JFrame in Java" Watch "Question regarding JFrame in Java" New topic
Author

Question regarding JFrame in Java

Kevin Doo
Greenhorn

Joined: Apr 16, 2008
Posts: 2
Hi, I've come into a sort of odd problem/glitch and was wondering if anyone
be of some help.

I'm in the process of making a simple web-browser that is being displayed using a JFrame. In the JFrame so far there are various Jbuttons, JTextAreas, JLabels and so on.

When I run my program (I am doing frame.setVisible(true)) ,
about 80% of the time, the JFrame will not accurately display everything
within it.

For instance, I have both a back and submit button in the JFrame. The back
button will always show, but occasionally the submit button will appear to
be blank even though the text "submit" is explicitly assigned to it. I am beginning to think that this may be an issue with my computer, but I have not tested this on other computers so I don't know if it's just mine.

However, if I maximize the window and then restore the size, the seemingly-non-existent components of the JFrame magically appear.

Included also are some screenshots (of the JFrame both with all elements and
without some elements):

With all the elements of the JFrame visible:


With only some visible:
(The Label that has text "Label" and part of the send Button are missing)


I still don't get why only some of the text disappears...
Also if it helps I'm running Windows XP SP2 with
a NVidia GeForceGo 7900 GS graphics card (supports SLI)

Any help would be great, Thanks!

Edit: Another note, I'm using Eclipse SDK

[ April 16, 2008: Message edited by: Kevin Doo ]
[ April 16, 2008: Message edited by: ]
Rodrigo Lopes
Ranch Hand

Joined: Feb 29, 2008
Posts: 119
Are you calling frame.pack() before showing it?
Show some piece (or all) of you code. This may be easier to help you.
Kevin Doo
Greenhorn

Joined: Apr 16, 2008
Posts: 2


Here's the code. I tried it today using Linux and it always displayed
perfectly with no problems.

However, when I run the same program on Windows XP SP 2, the issue above
occurs (look at the difference between the two pictures). I was told by
the TA's in my class that the error is mainly Window's version of java
is slightly buggy when it comes to using JFrame.

Although it is not in the code, I tried doing
link1.setPreferredSize(new Dimension etc.) and it yielded the same result.
I am beginning to think it is more of an issue with my computer than
anything else.

Oh, and yes I do call frame.pack().
However, I just realized that I did not do a setPreferredSize on the JPanel.
Could that be a problem?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Ran the code on my laptop running Windows XP SP 2, and saw no problems like you're describing...

Is any code outside of the code you posted doing anything like messing with the look and feel?

What version of the JDK are you using? If this is a known "bug" it may be tied to the version you're using.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
Consider Paul's rocket mass heater.
 
subject: Question regarding JFrame in Java