Mailing Lists: Apple Mailing Lists

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

JSeparator and SpringLayout -- used to be "horizontal dividing line in



Hi - I have added a LineBorder to my JSeparator, but nothing happens. No errors no divider. Any suggestions...? The JSeparator and LineBorder works fine in a JFrame without a layout manager. What is it about SpringLayout that disables or hides my JSeparator? Or is it something else. The JSeparator and LineBorder sit in a method that is added to a JPanel, that is used in card layout.

Thanks - K

// ===== CODE EXTRACT

JSeparator divider = new JSeparator();
Border lineBorder = BorderFactory.createLineBorder(Color.black);
divider.setBorder(lineBorder);

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

// LOTS OF CODE

appearancePane.add(divider);

// LOTS OF CODE

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

// =====

// ===== HERE IS THE COMPLETE CODE

package com.depolitic.Mocha.UIComponents;

import com.depolitic.Mocha.*;
import com.depolitic.Mocha.Aqua.*;
import com.depolitic.Mocha.Util.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;

public class Preferences extends JDialog {


protected static final String APPEARANCE = "Appearance";
protected static final String GENERAL = "General";

private AquaButton tbGeneral;
private AquaButton tbAppearance;
private JButton save;
private JButton cancel;

private AquaToolbar toolbar;
private JPanel mainPane;
private JPanel appearancePane;
private JPanel generalPane;
private JPanel footerPane;

private Mocha parent;

public Preferences(Mocha theParent) {
super();
parent = theParent;

// ===== Centers the Preferece Window on Screen
Toolkit theKit = getToolkit();
int width = 520;
int height = 500;
int xPos = (int)(new Dimension(theKit.getScreenSize())).getWidth() / 2 - width / 2;
setBounds(xPos, 160, width, height);

// ===== Use the content pane's default BorderLayout.
Container contentPane = getContentPane();

toolbar = new AquaToolbar(((java.awt.Window) (this)));
addButtons(toolbar);
contentPane.add(toolbar, BorderLayout.NORTH);

mainPane = new JPanel(((java.awt.LayoutManager) (new CardLayout())));
generalPane = new JPanel();
appearancePane = new JPanel();

mainPane.add("General", ((java.awt.Component) (generalPane)));
mainPane.add("Appearance", ((java.awt.Component) (appearancePane)));

generalPaneBuilder();
appearancePaneBuilder();

contentPane.add(mainPane, BorderLayout.CENTER);

cancel = new JButton();
cancel = StyleUtil.aquaButton("Cancel", true, false);
cancel.addActionListener(((ActionListener) (new ButtonListener())));
cancel.setFocusPainted(false);

save = new JButton();
save = StyleUtil.aquaButton("Save", false, false);
save.addActionListener(((ActionListener) (new ButtonListener())));
save.setFocusPainted(false);
getRootPane().setDefaultButton(save);

footerPane = new JPanel();
footerPane.setLayout(new BoxLayout(footerPane, BoxLayout.X_AXIS));
footerPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
footerPane.add(Box.createHorizontalGlue()); // Aligns buttons to the right of the footerPane WHY??
footerPane.add(cancel);
footerPane.add(Box.createHorizontalStrut(10)); // Creates an invisible component that's always the specified size.
footerPane.add(save);

contentPane.add(footerPane, BorderLayout.SOUTH);

setResizable(false);
}

protected void addButtons(AquaToolbar toolbar) {

tbGeneral = new AquaButton("General", "General Tooltip", new ImageIcon("images/preferenceGeneral.png"));
tbGeneral.addActionListener(((ActionListener) (new ButtonListener()))); // ===== adds action listener to button
toolbar.add(tbGeneral);

tbAppearance = new AquaButton("Appearance", "Appearance Tooltip", new ImageIcon("images/preferenceAppearance.png"));
tbAppearance.addActionListener(((ActionListener) (new ButtonListener()))); // ===== adds action listener to button
toolbar.add(tbAppearance);

}

protected void generalPaneBuilder() {
JLabel test = new JLabel("General Preferences");
generalPane.add(test);
}

protected void appearancePaneBuilder() {
Vector items = new Vector();
items.add(" Native ");
items.add(" Metal ");
items.add(" Motif ");
JComboBox toolbarStyle = new JComboBox(items);
// ========== combobox action listener =====
toolbarStyle.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

JComboBox cb = (JComboBox)e.getSource();
String toolbarViewItemName = (String)cb.getSelectedItem();

if ((String)cb.getSelectedItem() == " Native ") {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(parent);
parent.pack();

} catch (Exception a) {}}
else if ((String)cb.getSelectedItem() == " Metal ") {
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
SwingUtilities.updateComponentTreeUI(parent);
parent.pack();
} catch (Exception b) {}}
else if ((String)cb.getSelectedItem() == " Motif ") {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel ");
SwingUtilities.updateComponentTreeUI(parent);
parent.pack();
} catch (Exception c) {}}
}
}
);

// ===== Set LAF Label
JLabel appearancePaneLabel = new JLabel();
appearancePaneLabel = StyleUtil.aquaLargeBoldLabel("Appearance");

JLabel setLAFLabel = new JLabel();
setLAFLabel = StyleUtil.aquaLargeLabel("Look & Feel: ");

JLabel setLAFMessageLabel = new JLabel();
setLAFMessageLabel = StyleUtil.aquaSmallLabel("For the overall look of buttons, menus and windows");

JSeparator divider = new JSeparator();
Border lineBorder = BorderFactory.createLineBorder(Color.black);
divider.setBorder(lineBorder);

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

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

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

}

public class ButtonListener implements ActionListener {

public ButtonListener() {}

public void actionPerformed(ActionEvent event) {

String buttonString = event.getActionCommand();

if(buttonString.equals(((Object) (tbGeneral.getText())))) {
CardLayout theCards = (CardLayout)mainPane.getLayout();
theCards.show(((Container) (mainPane)), "General");
}
if(buttonString.equals(((Object) (tbAppearance.getText())))) {
CardLayout theCards = (CardLayout)mainPane.getLayout();
theCards.show(((Container) (mainPane)), "Appearance");
}
if(buttonString.equals("Save")) {
// savePrefs();
parent.repaint();
setVisible(false);
}
if(buttonString.equals("Cancel")) {
setVisible(false);
}

}
}

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