Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Swing Appearance Problems

Reply
Thread Tools

Swing Appearance Problems

 
 
matt
Guest
Posts: n/a
 
      08-14-2007
Ok so this has been bugging me for a while now and I have no idea what
to search for or what else to do. Basically, I have had java installed
on this computer for a while and it worked fine. But a while back, my
GUIs started getting all weird. I am using the Swing components
(JFrame and such) and what is happening is everything is more spaced
out. I have tried reinstalling the JRE multiple times but the problem
does not fix itself. I have also tried clearing the Java cache through
the control panel. I know it is nothing in my program because when I
move the code to another computer everything looks fine.
This is a hard problem to explain but the best way I can do it is to
say that everything is spaced out in the frames. The text fields are
wider but the text size is the same. In the combo boxes, the items are
spaced apart farther. An analogy would be in HTML the cell padding
field is bigger but obviously there is no place to set this within
Java.
I hope this makes sense, any help would be appreciated.

 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      08-14-2007
On Aug 14, 1:19 pm, matt <(E-Mail Removed)> wrote:
> Ok so this has been bugging me for a while now and I have no idea what
> to search for or what else to do. Basically, I have had java installed
> on this computer for a while and it worked fine. But a while back, my
> GUIs started getting all weird. I am using the Swing components
> (JFrame and such) and what is happening is everything is more spaced
> out. I have tried reinstalling the JRE multiple times but the problem
> does not fix itself. I have also tried clearing the Java cache through
> the control panel. I know it is nothing in my program because when I
> move the code to another computer everything looks fine.
> This is a hard problem to explain but the best way I can do it is to
> say that everything is spaced out in the frames. The text fields are
> wider but the text size is the same. In the combo boxes, the items are
> spaced apart farther. An analogy would be in HTML the cell padding
> field is bigger but obviously there is no place to set this within
> Java.
> I hope this makes sense, any help would be appreciated.


It makes perfect sense, not...
Please provide an SSCCE so that we can make an educated guess at what
might be going wrong.

 
Reply With Quote
 
 
 
 
matt
Guest
Posts: n/a
 
      08-14-2007
Unfortunately, I cannot really provide my code as an example, not that
it would make a difference anyways. What I have provided, is two
screenshots side by side of the program, here:

http://matthome.gotdns.com/pic.jpg

The one on the left is on this computer with the spacing really big
and the one on the right is on another computer. Notice that the
dropdown box is more compact, and that the buttons and textfields are
smaller as well. Those are all JComboBox, JButton, and JTextfield
respectively.

Thank you

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      08-15-2007
On Aug 15, 7:08 am, matt <(E-Mail Removed)> wrote:
> Unfortunately, I cannot really provide my code as an example, ..


Why not?

>..not that it would make a difference anyways.


That is a classic statement, coming from someone
who does not yet understand the source of the problem.

>...What I have provided, is two
> screenshots side by side of the program, here:
>
> http://matthome.gotdns.com/pic.jpg


>From that screenshot (as well as your initial

description), I would suggest the source of
the problem is the Layouts that this code either
does not use, or misuses.

Other tell-tale signs for fragile GUI's are
to be (regularly) calling setPreferredSize()
or setSize() or setBounds() on components..

My guess is the 'other computer' is still using
a JRE/screen resolution ..whatever that is suitable
for the original GUI, while something in the
problem PC has changed.

The fix is to reimplement the layouts properly.

Andrew T.

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      08-15-2007
On Aug 15, 7:08 am, matt <(E-Mail Removed)> wrote:
> Unfortunately, I cannot really provide my code as an example,


Note also that Daniel never suggested you post
'your code', but an SSCCE - which is a very
different thing. Read more here..
<http://www.physci.org/codes/sscce.html>

Andrew T.

 
Reply With Quote
 
matt
Guest
Posts: n/a
 
      08-15-2007
Ok. Here is an example of the problem. I wrote a short program to
display a frame and ran it on 2 separate computers, with the same JRE
installed. It happens to be 1.5.0_01.

The code for the program is here: http://matthome.gotdns.com/DoesStuff.java
and the screen shot results are here http://matthome.gotdns.com/sidebyside.jpg

The reason I feel like it is a problem with the JRE rather than my
code is because commercial applets such as Yahoo games and other
things like that have the same problem. Also, when producing a small
program such as this, the problem is still there.

Matt

 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      08-15-2007
matt wrote:
> Unfortunately, I cannot really provide my code as an example, not that
> it would make a difference anyways. What I have provided, is two
> screenshots side by side of the program, here:
>
> http://matthome.gotdns.com/pic.jpg
>
> The one on the left is on this computer with the spacing really big
> and the one on the right is on another computer. Notice that the
> dropdown box is more compact, and that the buttons and textfields are
> smaller as well. Those are all JComboBox, JButton, and JTextfield
> respectively.
>
> Thank you
>


Are the examples being run on different operating systems? Is the first
a Linux or maybe Vista? If it is Vista, I would be very curious to see
this on a 1.6 JRE.

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      08-15-2007
matt wrote:
>Ok. Here is an example of the problem. I wrote a short program to
>display a frame and ran it on 2 separate computers, with the same JRE
>installed. It happens to be 1.5.0_01.
>
>The code for the program is here: http://matthome.gotdns.com/DoesStuff.java


Yes.. there it is, just like I warned against in my first post..
setBounds(0,0,200,100);

Try this code on both machines, I am guessing it
will look slightly different on each PCs, but should
work well for either.

<sscce>
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import javax.swing.border.EmptyBorder;


public class DoesStuff extends JFrame{

public DoesStuff() {
super("Frame");

JPanel layout = new JPanel( new FlowLayout() );

// I will want to use a Border, so will
// .. use the panel above..
// setLayout(new FlowLayout());
setContentPane( layout );

//setBounds(0,0,200,100);
layout.add(new JButton("Button1"));
String[] stuff = {"Option1","Option2","Option3"};
layout.add(new JComboBox(stuff));

// add spacing around the panel..
layout.setBorder( new EmptyBorder(10,50,10,50) );

setDefaultCloseOperation(EXIT_ON_CLOSE);

// packing a layout will both validate
// it, and change the root component to the
// size it *needs* *to* *be*.
pack();

// if you insist* on calling setBounds/setSize,
// do it after the call to pack or validate.

// setSize( 200,100 );

// though note that such 'spacing' can best
// be achieved by adding an EmptyBorder, like above

setLocationRelativeTo(null);

setVisible(true);
}

public static void main(String[] args) {
Thread t = new Thread() {
public void run() {
new DoesStuff();
}
};
SwingUtilities.invokeLater( t );
}
}
</sscce>

...
>The reason I feel like it is a problem with the JRE rather than my
>code is because commercial applets such as Yahoo games and other
>things like that have the same problem.


There are lots of extremely poor layouts, mostly those
designed in IDE's by people that think they can drag
components anywhere they like and assume that will
'just work' for anyone else's VM version, screen
size/resolution, default font face & size, PLAF..

>...Also, when producing a small
>program such as this, the problem is still there.


Try the altered code. Note that I do not actually set
the size of any component in that code, as it is.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200708/1

 
Reply With Quote
 
matt
Guest
Posts: n/a
 
      08-15-2007
Knute:
No, both operating systems are the same. XP Pro w/ SP2 installed. I
am not sure if I am able to upgrade to 1.6, I was having trouble
finding a link.

Andrew:
The code you provided was correct syntactically but didnt fix the
appearance problem. The only difference was that the button and combo
box were centered in the frame.

Any other ideas?

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      08-15-2007
matt wrote:
>Knute:
> No, both operating systems are the same. XP Pro w/ SP2 installed.


There were a number of other potential differences (I)
listed, including screen size and resolution, default
font size, and PLAF.

While some of those might be identical for both
PC's..

>...I
>am not sure if I am able to upgrade to 1.6,


..The PLAF migh be slightly different even between
1.5 and 1.6. Though of course, the really important
thing for me to discuss is..

>...I was having trouble finding a link.
>
>Andrew:
> The code you provided was correct syntactically but didnt fix the
>appearance problem.


..that's a bummer. And really the relevant (to my point)
negation of what I was saying. Or to put that another,
simpler way.

"Seems I was wrong"

>...The only difference was that the button and combo
>box were centered in the frame.


<weakly>
Looks neat on my PC (XP Pro, running 1.6, using
screen res. of 1024x786 and relatively 'default' settings
otherwise).
</weakly>

>Any other ideas?


Can you give us a screen shot of the new GUI?

Also I would be interested to hear any critique of my
new (or your original) layouts. Though more interested
in hearing critiques of mine, because I was *really*
confident that would sort the problem, and would like
to get to the bottom of what went wrong.

Come on you GUI gurus, where are you hiding?

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200708/1

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swing is dead! Long live Swing. Knute Johnson Java 32 02-29-2012 05:10 PM
Why not using javax.swing.event with swing? S.T Java 2 05-25-2007 12:10 AM
javax.swing.Popup, javax.swing.PopupFactory lizard Java 0 01-30-2006 09:34 PM
Swing Model Classes Updating Swing Components on a Thread Other Than AWT mkrause Java 0 05-06-2005 04:32 PM
Java 1.2 Swing vs. Java 1.5 Swing Big Daddy Java 2 04-16-2005 01:14 PM



Advertisments