Mailing Lists: Apple Mailing Lists

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

horizontal dividing line in swing



Hi- I am trying to add a horizontal dividing line in my JPanel. To act as a visual divider between visually logical components in the GUI.

I have opted to create a JPanel, set its background color to a SystemColor and then including this new horizontal dividing line panel inside of the bigger panel. I am using SpringLayout as my layout manager. However the visual effect is not what I was expecting. Instead of a horizontal dividing line I get a grey square 5 x 5 px large. The grey square appears in the correct location starting location for the horizontal dividing line, but that is all.

Has this display behavior anything to do with my layout manager. because when I set the layout manager to null horizontal dividing line panel the panel vanishes. Any way here is the code, I am using. If you have a better way to create a horizontal dividing line I would love to hear about it.

// =====
// THIS IS THE JPANEL
JPanel divider = new JPanel();
divider.setBackground(new Color(SystemColor.WINDOW_BORDER));
divider.setSize(new Dimension(this.getWidth(), 1));

// ===== Layout
SpringLayout layout = new SpringLayout();
appearancePane.setLayout(layout);

appearancePane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
appearancePane.add(appearancePaneLabel);
appearancePane.add(setLAFLabel);
appearancePane.add(toolbarStyle);
appearancePane.add(setLAFMessageLabel);
appearancePane.add(divider); // HERE I ADD THE DIVIDER JPANEL

SpringLayout.Constraints appearancePaneLabelCons = layout.getConstraints(appearancePaneLabel);
appearancePaneLabelCons.setX(Spring.constant(5));
appearancePaneLabelCons.setY(Spring.constant(5));

SpringLayout.Constraints setLAFLabelCons = layout.getConstraints(setLAFLabel);
setLAFLabelCons.setX(Spring.constant(5));
setLAFLabelCons.setY(Spring.sum( Spring.constant(10), appearancePaneLabelCons.getConstraint(SpringLayout.SOUTH)));

SpringLayout.Constraints toolbarStyleCons = layout.getConstraints(toolbarStyle);
toolbarStyleCons.setX(Spring.sum( Spring.constant(1), setLAFLabelCons.getConstraint(SpringLayout.EAST)));
toolbarStyleCons.setY(Spring.sum( Spring.constant(5), appearancePaneLabelCons.getConstraint(SpringLayout.SOUTH)));

SpringLayout.Constraints setLAFMessageLabelCons = layout.getConstraints(setLAFMessageLabel);
setLAFMessageLabelCons.setX(Spring.sum( Spring.constant(5), setLAFLabelCons.getConstraint(SpringLayout.EAST)));
setLAFMessageLabelCons.setY(Spring.sum( Spring.constant(5), toolbarStyleCons.getConstraint(SpringLayout.SOUTH)));

// ==== THIS IS THE SpringLayout FOR THE divider
SpringLayout.Constraints dividerCons = layout.getConstraints(divider);
dividerCons.setX(Spring.constant(5));
dividerCons.setY(Spring.sum( Spring.constant(5), setLAFMessageLabelCons.getConstraint(SpringLayout.SOUTH)));


// =====
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



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.