我有一个主平面和4个子平面,分别命名为x,y,z,按钮平面 我分别在每个平面上有3个切换开关。当我点击第一个切换按钮时,我能够显示x平面下方的一个平面。 当我关闭开关时,它必须消失。功能正在运行,但当我试图切换按钮时,飞机消失,并在这些飞机之间增加间隙。
public class OptionScreen extends Screen实现了ActionListener,MouseListener {
public OptionScreen(B b) {
super(b);
font = b.getFont(18, Font.BOLD);
this.b = ckupgrade;
this.getContentPane().setBackground(Color.WHITE.getColor());
this.setPreferredSize(new Dimension(500, 280));
this.setMaximumSize(new Dimension(500, 280));
this.setMinimumSize(new Dimension(500, 280));
this.setLayout(new FlowLayout());
titleLabel = new JLabel();
titleLabel.setFont(font);
titleLabel.setText(Messages.getString("LBl")); //$NON-NLS-1$
titlePanel = new JPanel();
titlePanel.setPreferredSize(new Dimension(500, 40));
titlePanel.setMinimumSize(new Dimension(500, 40));
titlePanel.setMaximumSize(new Dimension(500, 40));
titlePanel.setBackground(color.WHITE.getColor());
titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
titlePanel.add(titleLabel);
font = b.getFont((float) 13.5, Font.BOLD);
Switch = new JSwitchBox("", "****");//$NON-NLS-1$
Switch.setMinimumSize(new Dimension(30, 50));
Switch.setPreferredSize(new Dimension(30, 50));
Switch.setMaximumSize(new Dimension(30, 50));
Switch.setOpaque(false);
Switch.addActionListener(this);
WebletsCheckBox = new JLabel(" Additional Apps");//$NON-NLS-1$
WebletsCheckBox.setOpaque(false);
WebletsCheckBox.setFocusable(false);
WebletsCheckBox.setFont(b.getFont((float) 13.5, Font.PLAIN));
BuiltInApps = new JPanel();
BuiltInApps.setBackground(Color.GRAY_TINT10.getColor());
BuiltInApps.setLayout(new FlowLayout(FlowLayout.LEFT));
BuiltInApps.setMinimumSize(new Dimension(500, 50));
BuiltInApps.setPreferredSize(new Dimension(500, 50));
BuiltInApps.setMaximumSize(new Dimension(500, 50));
BuiltInApps.add(Switch);
BuiltInApps.add(WebletsCheckBox);
PanelSwitch = new JSwitchBox("", "****");
PanelSwitch.setMinimumSize(new Dimension(30, 50));
PanelSwitch.setSelected(true);
PanelSwitch.setPreferredSize(new Dimension(30, 50));
PanelSwitch.setMaximumSize(new Dimension(30, 50));
PanelSwitch.addMouseListener(this);
PanelHeading = new JLabel("******");
PanelHeading.setOpaque(false);
PanelHeading.setFont(b.getFont((float) 13.5, Font.PLAIN));
pPanel = new JPanel();
pPanel.setBackground(Color.GRAY.getColor());
pPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
pPanel.setMinimumSize(new Dimension(500, 50));
pPanel.setPreferredSize(new Dimension(500, 50));
pPanel.setMaximumSize(new Dimension(500, 50));
pPanel.add(pPanelSwitch);
pPanel.add(pPanelHeading);
font = b.getFont(15, Font.BOLD);
NumberLabel = new JLabel(Messages.getString("********"));
NumberLabel.setFont(font);
NumberLabel.setPreferredSize(new Dimension(125, 50));
PortNumberLabel.setMaximumSize(new Dimension(125, 30));
pTextBox = new JTextField("9100");
pTextBox.setBackground(Color.WHITE.getColor());
pTextBox.setBorder(new RoundBorder(Color.GRAY.getColor(),
Color.WHITE.getColor(), 14, 14));
pTextBox.setFont(ckupgrade.getFont(15, Font.BOLD));
pTextBox.setPreferredSize(new Dimension(75, 30));
pTextBox.setMaximumSize(new Dimension(75, 30));
NumberPanel = new JPanel();
NumberPanel.setBackground(Color.GRAY.getColor());
NumberPanel.setLayout(new BoxLayout(NumberPanel, BoxLayout.X_AXIS));
NumberPanel.add(Box.createRigidArea(new Dimension(10, 0)));
NumberPanel.add(NumberLabel);
NumberPanel.add(Box.createRigidArea(new Dimension(5, 0)));
NumberPanel.add(pTextBox);
NumberPanel.add(Box.createHorizontalGlue());
OptionsSwitch = new JSwitchBox("", "***********");//$NON-NLS-1$
OptionsSwitch.setMinimumSize(new Dimension(30, 50));
OptionsSwitch.setPreferredSize(new Dimension(30, 50));
OptionsSwitch.setMaximumSize(new Dimension(30, 50));
OptionsLabel = new JLabel("*********");
OptionsSwitch.setOpaque(false);
OptionsLabel.setFont(ckupgrade.getFont((float) 13.5, Font.PLAIN));
OptionsSwitch.setSelected(true);
OptionsSwitch.addMouseListener(this);
OptionsPanel = new JPanel();
OptionsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
OptionsPanel.setMinimumSize(new Dimension(500, 30));
OptionsPanel.setPreferredSize(new Dimension(500, 30));
OptionsPanel.setMaximumSize(new Dimension(500, 30));
OptionsPanel.add(OptionsSwitch);
OptionsPanel.add(OptionsLabel);
font = b.Font(15, Font.BOLD);
Label = new JLabel(
Messages.getString("*****"));//$NON-NLS-1$
Label.setBackground(Color.GRAY.getColor());
Label.setFont(b.getFont(12, Font.BOLD));
Label.setPreferredSize(new Dimension(225, 50));
sLabel.setMaximumSize(new Dimension(225, 30));
sField = new XTextField("5");
Field.setBackground(Color.WHITE.getColor());
sField.setBorder(new RoundBorder(Colore.WHITE.getColor(),
Color.WHITE.getColor(), 14, 14));
sField.setFont(b.getFont(13, Font.BOLD));
sField.setPreferredSize(new Dimension(50, 30));
sField.setMaximumSize(new Dimension(50, 30));
sField = new XTextField("5");//$NON-NLS-1$
sField.setFont(font);
sField.setPreferredSize(new Dimension(40, 30));
sField.setMinimumSize(new Dimension(40, 30));
sField.setMaximumSize(new Dimension(40, 30));
sField.setFocusTraversalKeysEnabled(false);
sField.requestFocus();
sPanel = new JPanel();
sPanel.setLayout(new BoxLayout(sPanel, BoxLayout.X_AXIS));
sPanel.setBackgroundColor.GRAY.getColor());
sPanel.add(Box.createRigidArea(new Dimension(10, 0)));
sPanel.add(Label);
sPanel.add(Box.createRigidArea(new Dimension(5, 0)));
sPanel.add(sField);
sPanel.add(Box.createHorizontalGlue());
closeButton = new XButton(
Messages.getString("***"),//$NON-NLS-1$
Theme.WhiteOnBlue);
closeButton.setFocusable(false);
closeButton.setFont(font);
closeButton.setBorder(BorderFactory.createEmptyBorder());
closeButton.setFont(be.getFont(15, Font.BOLD));
closeButton.setPreferredSize(new Dimension(100, 37));
closeButton.setMinimumSize(new Dimension(100, 37));
closeButton.setMaximumSize(new Dimension(100, 37));
closeButton.addActionListener(this);
removeLabel = new JLabel("Remove");//$NON-NLS-1$
removeLabel.setFocusable(false);
removeLabel.setForeground(Color.RED.getColor());
removeLabel.setFont(b.getFont(15, Font.BOLD));
removeLabel.setPreferredSize(new Dimension(150, 37));
removeLabel.setMinimumSize(new Dimension(150, 37));
removeLabel.setMaximumSize(new Dimension(150, 37));
removeLabel.addMouseListener(this);
buttonPanel = new JPanel();
buttonPanel.setBackground(Color.GRAY.getColor());
titlePanel.setPreferredSize(new Dimension(500, 40));
titlePanel.setMinimumSize(new Dimension(500, 40));
titlePanel.setMaximumSize(new Dimension(500, 40));
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPanel.add(removeLabel);
buttonPanel.add(Box.createRigidArea(new Dimension(200, 40)));
buttonPanel.add(closeButton);
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
mainPanel = new JPanel();
mainPanel.setBackground(Color.GRAY.getColor());
this.setContentPane(mainPanel);
mainPanel.setBorder(new RoundBorder(Colo.GRAY.getColor(),
Colo.GRAY.getColor(), 10, 10));
mainPanel.setPreferredSize(new Dimension(500, 280));
mainPanel.setMaximumSize(new Dimension(500, 280));
mainPanel.setMinimumSize(new Dimension(500, 280));
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
mainPanel.add(titlePanel);
mainPanel.add(Box.createRigidArea(new Dimension(500, 30)));
mainPanel.add(pPanel);
mainPanel.add(lBuiltInApps);
mainPanel.add(sPanel);
mainPanel.add(Box.createRigidArea(new Dimension(500, 27)));
mainPanel.add(buttonPanel);
pack();
setLocationRelativeTo(getParent());
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getSource() == OptionsSwitch) {
if (!(sPanel.getParent() == mainPanel)) {
OptionScreen.this.setPreferredSize(new Dimension(500, 330));
OptionScreen.this.setMaximumSize(new Dimension(500, 330));
OptionScreen.this.setMinimumSize(new Dimension(500, 330));
mainPanel.setPreferredSize(new Dimension(500, 330));
mainPanel.setMaximumSize(new Dimension(500, 330));
mainPanel.setMinimumSize(new Dimension(500, 330));
mainPanel.remove(buttonPanel);
mainPanel.add(sPanel);
mainPanel.add(buttonPanel);
} else if (sPanel.getParent() == mainPanel) {
OptionScreen.this.setPreferredSize(new Dimension(500, 280));
OptionScreen.this.setMaximumSize(new Dimension(500, 280));
OptionScreen.this.setMinimumSize(new Dimension(500, 280));
mainPanel.setPreferredSize(new Dimension(500, 280));
mainPanel.setMaximumSize(new Dimension(500, 280));
mainPanel.setMinimumSize(new Dimension(500, 280));
mainPanel.remove(sPanel);
}
} else if (e.getSource() == PanelSwitch) {
if (!(NumberPanel.getParent() == mainPanel)) {
OptionScreen.this.setPreferredSize(new Dimension(500, 380));
OptionScreen.this.setMaximumSize(new Dimension(500, 380));
OptionScreen.this.setMinimumSize(new Dimension(500, 380));
mainPanel.setPreferredSize(new Dimension(500, 380));
mainPanel.setMaximumSize(new Dimension(500, 380));
mainPanel.setMinimumSize(new Dimension(500, 380));
mainPanel.remove(BuiltInApps);
mainPanel.remove(sPanel);
mainPanel.remove(buttonPanel);
mainPanel.add(NumberPanel);
mainPanel.add(BuiltInApps);
mainPanel.add(sPanel);
mainPanel.add(Box.createRigidArea(new Dimension(500, 27)));
mainPanel.add(buttonPanel);
} else if (NumberPanel.getParent() == mainPanel) {
OptionScreen.this.setPreferredSize(new Dimension(500, 280));
OptionScreen.this.setMaximumSize(new Dimension(500, 280));
OptionScreen.this.setMinimumSize(new Dimension(500, 280));
mainPanel.setPreferredSize(new Dimension(500, 280));
mainPanel.setMaximumSize(new Dimension(500, 280));
mainPanel.setMinimumSize(new Dimension(500, 280));
mainPanel.remove(NumberPanel);
}
} else if (e.getSource() == removeLabel) {
close();
}
}
please suggest me how to remove the gaps .
I am using Flow layout