Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SpringLayout seems unworkable on OSX



Mark Leone wrote:

>So now I have an app with a GUI that looks great on Windows, but when I
>try to run it on OSX, it's entirely unusable. And as I play with it, it
>seems that the constraints I set in the SpringLayuout mamaner are just not
>being honored at all on OSX.

Please specify the OSX version and Java version you're using.

Also specify the Windows OS and Java version you're using.


I wrote a simple test-case (source below).  I had to add code to get a
complete working example, so what I added may well differ from your code.
If you can make a complete working example that better illustrates what
you're doing, in the smallest form that malfunctions the same, we could
then analyze that.  Code fragments without context invariably
under-represent what's happening.

However, I did make a small change that dramatically changed the behavior.

Where you have this line:
   mainLayout.putConstraint(SpringLayout.SOUTH, bottomPanel, -5, SpringLayout.SOUTH, mainPanel);

I rearranged it like this:
    mainLayout.putConstraint(SpringLayout.SOUTH, mainPanel, 5, SpringLayout.SOUTH, bottomPanel);

This simple change made a big difference in how the layouts resized.  I
don't know why this should be so, because I didn't find anything that said
negative padding was prohibited.  However, you might want to make similar
changes in the other places you have negative padding.

Also, I observed roughly equivalent behavior, or misbehavior, on 10.4.9 or
10.5, JDK 1.4.2 or 1.5.  I could be wrong about that in the details,
because the label placeholders leave so much air.  In that respect, it
would help if you provided a complete example, and more precise description
about exactly what malfunction you're seeing.  I'm afraid "entirely
unusable" is too vague to tell what might be going wrong, given all the
components you omitted.

  -- GG


 - - - File "SpringTest.java" - - -

import java.awt.*;
import javax.swing.*;


public class SpringTest
  extends JFrame
{
  public static void main( String[] args )
  {
    SpringTest frame = new SpringTest();
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    frame.setVisible( true );
  }


  public SpringTest()
  {
    super( "SpringTest: JDK " + System.getProperty( "java.version" ) );
    JComponent main = compose();
    getContentPane().add( main );
  }

  private JComponent compose()
  {
//    screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
//    screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
//    w = prefs.getInt("mainWindowWidth", Math.min(900, (int)(0.9 * (double) screenWidth)));
//    h = prefs.getInt("mainWindowHeight", Math.min(700, (int) (0.9 * (double)screenHeight)));
    int w = 900, h = 700;
    setSize(new Dimension(w,h));
    JPanel mainPanel = new JPanel();
    SpringLayout mainLayout, listPanelLayout, midLeftLayout, midMidLayout, midRightLayout;
    SpringLayout.Constraints cons;
    mainPanel.setLayout(mainLayout = new SpringLayout());

    JPanel topPanel, midPanel, bottomPanel;
    topPanel = new JPanel();
    midPanel = new JPanel();
    bottomPanel = new JPanel();
    mainPanel.add(topPanel);
    mainPanel.add(midPanel);
    mainPanel.add(bottomPanel);
    cons = new SpringLayout.Constraints();
    cons.setY(Spring.constant(5));
    cons.setHeight(Spring.constant(110, 120, 130));
    mainLayout.addLayoutComponent(topPanel, cons);
    mainLayout.putConstraint(SpringLayout.WEST, topPanel, 5, SpringLayout.WEST,mainPanel);
    mainLayout.putConstraint(SpringLayout.EAST, topPanel, -5, SpringLayout.EAST,mainPanel);
    cons = new SpringLayout.Constraints();
    cons.setHeight(Spring.constant( (int)(getHeight() * 0.25),
    (int)(getHeight() * 0.55),
    (int)(getHeight() * 0.7)));
    mainLayout.addLayoutComponent(midPanel, cons);
    mainLayout.putConstraint(SpringLayout.WEST, midPanel, 5, SpringLayout.WEST,mainPanel);
    mainLayout.putConstraint(SpringLayout.EAST, midPanel, -5, SpringLayout.EAST,mainPanel);
    mainLayout.putConstraint(SpringLayout.NORTH, midPanel, 5, SpringLayout.SOUTH,topPanel);
    cons = new SpringLayout.Constraints();
    cons.setHeight(Spring.constant(120, 130, 140));
    mainLayout.addLayoutComponent(bottomPanel, cons);
    mainLayout.putConstraint(SpringLayout.WEST, bottomPanel, 5, SpringLayout.WEST,mainPanel);
    mainLayout.putConstraint(SpringLayout.EAST, bottomPanel, -5, SpringLayout.EAST,mainPanel);
    mainLayout.putConstraint(SpringLayout.NORTH, bottomPanel, 5, SpringLayout.SOUTH,midPanel);
//    mainLayout.putConstraint(SpringLayout.SOUTH, bottomPanel, -5, SpringLayout.SOUTH,mainPanel);
    mainLayout.putConstraint(SpringLayout.SOUTH, mainPanel, 5, SpringLayout.SOUTH,bottomPanel);

    // Placeholders
    topPanel.add( new JLabel( "OS version " + System.getProperty( "os.version" ) ) );
    midPanel.add( new JLabel( "Middle" ) );
    bottomPanel.add( new JLabel( "Bottom" ) );

    return mainPanel;
  }
}



 - - - - -


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.