这就是它输出:我将如何将这些控件与左侧对齐?
我要对齐“Imprimante:MonImprimante”最左边 还有3个复选框。
您可以找到有关我想通过搜索***用CTRL-F对齐的事情代码
这是我的代码: `
package gui;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
public class ImprimanteWindow extends JFrame{
//Declares the panels used to place the controls.
private JPanel JPanelBtn;
private JPanel JPanelChk;
private JPanel JPanelRad;
private JPanel JPanelDrpChk;
private JPanel JPanelWrap;
private JPanel JPanelSuperWrap;
private String[] QltImpression = { "Haute", "Medium", "Bas"};
public ImprimanteWindow(){
//Initialise the panels
JPanelBtn = new JPanel(new GridLayout(4,1, 10, 10));
JPanelChk = new JPanel(new GridLayout(3,1));
JPanelRad = new JPanel(new GridLayout(3,1));
JPanelDrpChk = new JPanel();
JPanelWrap = new JPanel(); //used to put the other panels inside
JPanelSuperWrap = new JPanel(); //used to put everything in 1 big panel
//Initialise the buttons and add them to the button Panel
JPanelBtn.add(new JButton("Ok"));
JPanelBtn.add(new JButton("Annuler"));
JPanelBtn.add(new JButton("Paramètre"));
JPanelBtn.add(new JButton("Aide"));
this.add("East", JPanelBtn);
//***I want to align this to the far left
//adds the check boxes to the checkbox panel
JPanelChk.add(new JCheckBox("Image"));
JPanelChk.add(new JCheckBox("Texte"));
JPanelChk.add(new JCheckBox("Code"));
////adds the radio buttons to the radiobutton panel
JPanelRad.add(new JRadioButton("Selection"));
JPanelRad.add(new JRadioButton("Tous"));
JPanelRad.add(new JRadioButton("Applet"));
//***I want to align this to the far left
//adds the label to the top section of the panel
JPanelSuperWrap.add(new JLabel("Imprimante : MonImprimante"));
//adds the 2 panels and the slider to the middle section
JPanelWrap.add(JPanelChk);
JPanelWrap.add(JPanelRad);
JPanelWrap.add(new JSlider());
JPanelSuperWrap.add(JPanelWrap);
//adds a label, a combobox and a checkbox to the bottom.
JPanelDrpChk.add(new JLabel("Qualite de l'impression :"));
JPanelDrpChk.add(new JComboBox(QltImpression));
JPanelDrpChk.add(new JCheckBox("Imprimer dans un fichier"));
JPanelSuperWrap.add(JPanelDrpChk);
this.add(JPanelSuperWrap);
this.pack();
this.setSize(500,170);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.validate();
}
public static void main(String args[]){
ImprimanteWindow gui = new ImprimanteWindow();
}
}`
在放置控件任何帮助我的gui将会大受欢迎! 非常感谢你们!
我想你会需要使用比'GridLayout'不同的布局管理器,如果这个问题不回答后,我回来吃午饭的形式,我会张贴一些代码。 – 2012-04-13 16:36:15
请学习java命名约定并坚持使用它们。 – kleopatra 2012-04-14 10:24:48