Mailing Lists: Apple Mailing Lists

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

SpringLayout seems unworkable on OSX



I've been using SpringLayout as my most-preferred layout manager since Java 1.4 came out. I'm no expert, but I think I know how it works, and I've coded numerous apps on Window with it. 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.

The GUI has three top-level panes laid out vertically, and I set the constraints so that (on Windows) the three panes are right where I want them. But on the Mac, I had to explicitly set the preferred size of the top and bottom panes, even though I had specified constraints in the layout manager for position and size. I tried the same "fix" for the middle pane, but it's a lot more complex internally than the other two. And what I've found by experimenting is that I have to explicitly set the size of every single component inside the middle pane if I want it to show up, even though I have all the constraints specified so that SpringLayout should lay them out properly.

I've paste below the code for the top level container and how the three panes inside it are laid out using SpringLayout. The middle pane, the one that seems to require each contained component to have sizes explicitly set, is itself managed by SpringLayout, while the other two are BorderLayout. I've laid out the middle pane in pretty much the same fashion as you see the top level pane laid out below. Can anyone see what I might be missing, some reason why the SpringLayout constraints are not being followed?

-Mark

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)));
setSize(new Dimension(w,h));
JPanel mainPanel = new JPanel();
SpringLayout mainLayout, listPanelLayout, midLeftLayout, midMidLayout, midRightLayout;
SpringLayout.Constraints cons;
mainPanel.setLayout(mainLayout = new SpringLayout());


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);


_______________________________________________
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.