これはそれが出力するものです:
左端の「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にコントロールを配置する際の助けがあれば、大いに感謝します! どうもありがとうございました!