Swing Appearance Problems

Discussion in 'Java' started by matt, Aug 14, 2007.

  1. matt

    matt Guest

    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.
    matt, Aug 14, 2007
    #1
    1. Advertising

  2. matt

    Daniel Pitts Guest

    On Aug 14, 1:19 pm, matt <> 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.
    Daniel Pitts, Aug 14, 2007
    #2
    1. Advertising

  3. matt

    matt Guest

    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
    matt, Aug 14, 2007
    #3
  4. On Aug 15, 7:08 am, matt <> 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.
    Andrew Thompson, Aug 15, 2007
    #4
  5. On Aug 15, 7:08 am, matt <> 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.
    Andrew Thompson, Aug 15, 2007
    #5
  6. matt

    matt Guest

    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
    matt, Aug 15, 2007
    #6
  7. 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/
    Knute Johnson, Aug 15, 2007
    #7
  8. 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.aspx/java-general/200708/1
    Andrew Thompson, Aug 15, 2007
    #8
  9. matt

    matt Guest

    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?
    matt, Aug 15, 2007
    #9
  10. 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.aspx/java-general/200708/1
    Andrew Thompson, Aug 15, 2007
    #10
  11. matt

    Roedy Green Guest

    On Tue, 14 Aug 2007 14:08:56 -0700, matt <> wrote,
    quoted or indirectly quoted someone who said :

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


    I would try this voodoo.
    1. Reinstall your video driver.
    2. change the screen resolution and font size in the OS control panel.

    It is almost as if you have accidentally turned some sort of feature
    for people with poor vision.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Aug 15, 2007
    #11
  12. matt

    Michael Jung Guest

    "Andrew Thompson" <u32984@uwe> writes:
    > 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.


    In order to check, whether this is a PLAF problem or not, set the PLAF at the
    beginning and see, whether this problem persists for more than the OS-default
    PLAF. (You could also play around with the fonts, but I doubt that this has
    to do with either that or the screen resolution.

    Someone else already guessed that it may have to do with some accessibility
    hints.

    You may also compare the LOCALEs. To me it looks as if someone was trying to
    add an additional line at the end of text. Maybe the LOCALE force-codes CR or
    LF or CR/LF at the end of strings?

    You may also write a simple AWT program to display a label and compare those
    to see whether this is a Swing problem or lies deeper.

    Michael
    Michael Jung, Aug 15, 2007
    #12
  13. matt

    matt Guest

    On Aug 15, 10:26 am, Michael Jung <> wrote:
    > "Andrew Thompson" <u32984@uwe> writes:
    > > 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.


    Ok, I changed screen resolutions and changed the fonts around but
    nothing seemed to work. I tried reinstalling my video drivers but I'm
    not totally sure if I did it correctly since all of those drivers were
    packaged with my laptop on one disc.

    >
    > In order to check, whether this is a PLAF problem or not, set the PLAF at the
    > beginning and see, whether this problem persists for more than the OS-default
    > PLAF. (You could also play around with the fonts, but I doubt that this has
    > to do with either that or the screen resolution.
    >


    I am interested in this PLAF stuff though. However, I'm not really
    familiar with any of it. From what I have looked up on google (I
    thought PLAF was a kind of rice) the only stuff I have ever done with
    it is using the setDefaultLookAndFeel method that comes in most swing
    components. Do you think you could get me started in a way to change
    this?


    > Someone else already guessed that it may have to do with some accessibility
    > hints.
    >
    > You may also compare the LOCALEs. To me it looks as if someone was trying to
    > add an additional line at the end of text. Maybe the LOCALE force-codes CR or
    > LF or CR/LF at the end of strings?
    >


    I have no idea what any of those things are. How would I look for
    force codes? You saw the code I have and Andrew's code is posted in a
    previous message. Is that something that is in the code, or an
    internal setting?

    > You may also write a simple AWT program to display a label and compare those
    > to see whether this is a Swing problem or lies deeper.
    >


    I am assuming this means something other than a swing program. Labels
    tend to look the same for some reason. Most of these sizing issues
    only occur on buttons and combo boxes. Do you know of anyway to create
    those using AWT?

    Thanks for your help guys. I'm glad I'm not just doing something
    stupid, although I wouldn't rule that out yet
    matt, Aug 16, 2007
    #13
  14. matt

    matt Guest

    Ok I figured out the AWT thing. Not as hard as I thought it would be.
    I made a simple class located here: http://matthome.gotdns.com/AWTFrame.java
    and everything looks ok. I guess that means its a swing problem then???
    matt, Aug 16, 2007
    #14
  15. matt

    Michael Jung Guest

    matt <> writes:
    > On Aug 15, 10:26 am, Michael Jung <> wrote:
    > > In order to check, whether this is a PLAF problem or not, set the PLAF at
    > > the beginning and see, whether this problem persists for more than the
    > > OS-default PLAF. (You could also play around with the fonts, but I doubt
    > > that this has to do with either that or the screen resolution.


    > I am interested in this PLAF stuff though. However, I'm not really
    > familiar with any of it. From what I have looked up on google (I
    > thought PLAF was a kind of rice) the only stuff I have ever done with
    > it is using the setDefaultLookAndFeel method that comes in most swing
    > components. Do you think you could get me started in a way to change
    > this?


    LAF = Look and Feel. PLAF = Platform LAF. What I meant was that you should
    change that. Take a look at the Java tutorials to see how to change the
    LAF. You have at least two at your disposal: Native (Windows) and
    Metal. Try Metal.

    > > Someone else already guessed that it may have to do with some
    > > accessibility hints. You may also compare the LOCALEs. To me it looks as
    > > if someone was trying to add an additional line at the end of text. Maybe
    > > the LOCALE force-codes CR or LF or CR/LF at the end of strings?


    Accessibility means preparing your application for people with disabilities,
    mostly reading in this case. I'm not really sure how Java interacts with OS
    hints here. Mostly such things include big letters, black and white only
    screens. It doesn't appear to be in your case.

    "Locale" is actually a class in java.util. Read the Javadoc in print out the
    result of "getDefault".

    > I have no idea what any of those things are. How would I look for
    > force codes? You saw the code I have and Andrew's code is posted in a
    > previous message. Is that something that is in the code, or an
    > internal setting?


    force-code isn't a technical entity. I meant that somehow Swing might attempt
    to use "any_string\n" instead of "any_string" in it's representation on the
    GUI (forcing a "\n" at the end of every string). For whatever reasons. From
    what I'm writing here you should infer that I am guessing and my guess isn't
    better than anybody elses. The Locale is just a possibility (to which maybe
    only my imperfect understanding of them lead me).

    What I would also try, just curiousity, how multiline strings are displayed in
    your swing elements.

    You could also print out the FontMetrics of your GUI elements to see whether
    they have oversized descents (getDescent and getMaxDescent). Compare that on
    your machines. But that should also show in AWT.

    Or force it to use a built-in font, such as "Lucida sans" and see whether
    there is a difference. (See the Java2D FAQ on how to check your fonts.)

    > > You may also write a simple AWT program to display a label and compare
    > > those to see whether this is a Swing problem or lies deeper.


    Since you get an AWT program to run, we have cornered the problem in swing. Is
    it possible that you install another JDK on your machine at another location?
    Try and run your programs from there. Maybe the orginal installation was
    botched.

    Michael
    Michael Jung, Aug 16, 2007
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Big Daddy

    Java 1.2 Swing vs. Java 1.5 Swing

    Big Daddy, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    488
    Pete Barrett
    Apr 16, 2005
  2. mkrause
    Replies:
    0
    Views:
    661
    mkrause
    May 6, 2005
  3. lizard
    Replies:
    0
    Views:
    1,750
    lizard
    Jan 30, 2006
  4. Delfry
    Replies:
    3
    Views:
    477
    Salt_Peter
    Mar 26, 2007
  5. S.T
    Replies:
    2
    Views:
    565
Loading...

Share This Page