0
labelNameの下にlabelAddressを追加したいのですが、それはその右側にあります。私は新しいラベルを別のラベルの下に追加し続けたいと思っています。これは採用申請書のようなものです。私はBorderLayoutを使って各ラベルの位置を教えましたが、それは私が望むところには行っていません。 これはどのようにすべきです。おかげでここBorderLayoutを使用して各行にJLabelを入力してください
Enter your name: _________________ Enter your address: _________________ ........
は私のコードです:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
public class Home extends JFrame {
private JButton btnClear, btnNext;
private JTextField txtName, txtAddress, txtCity, txtState,
txtZipCode, txtPhoneNumber, txtEmail;
private JComboBox txtDate, txtYear, txtMonth;
private JLabel labelName, labelAddress, labelCity, labelState,
labelZipCode, labelPhoneNumber, labelEmail;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Home().setVisible(true);
}
});
}
public Home() {
createView();
setTitle("Job Hiring Systems");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(600, 600);
setMinimumSize(new Dimension(600, 600));
setLocationRelativeTo(null);
setResizable(false);
}
private void createView() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBorder(new EmptyBorder(25, 10, 25, 10));
getContentPane().add(panel);
/*
* North Panel
*/
JPanel northPanel = new JPanel();
northPanel.setBackground(Color.GRAY);
panel.add(northPanel, BorderLayout.NORTH);
JLabel labelWelcomeMessage = new JLabel("Welcome to the Job Hiring Systems");
labelWelcomeMessage.setFont(new Font("Serif", Font.BOLD, 25));
northPanel.add(labelWelcomeMessage, BorderLayout.CENTER);
/*
* End of North Panel
*/
/*
* Center Panel
*/
JPanel centerPanel = new JPanel();
centerPanel.setBackground(Color.ORANGE);
panel.add(centerPanel, BorderLayout.CENTER);
labelName = new JLabel("Enter your name: ");
//labelName.setBorder(new EmptyBorder(25,50,10,10));
labelName.setFont(new Font("Serif", Font.PLAIN, 15));
centerPanel.add(labelName, BorderLayout.EAST);
txtName = new JTextField(25);
txtName.setHorizontalAlignment(JTextField.CENTER);
txtName.setHorizontalAlignment(SwingConstants.LEFT);
centerPanel.add(txtName, BorderLayout.EAST);
labelAddress = new JLabel("Enter you address: ");
labelAddress.setFont(new Font("Serif", Font.PLAIN, 15));
// labelAddress.setBorder(new EmptyBorder(0,0,0,20)); // maybe add this, but doesn't align with the labelName
centerPanel.add(labelAddress, BorderLayout.CENTER);
txtAddress = new JTextField(25);
txtAddress.setHorizontalAlignment(JTextField.CENTER);
txtAddress.setHorizontalAlignment(SwingConstants.LEFT);
centerPanel.add(txtAddress, BorderLayout.EAST);
/*
* South Panel
*/
JPanel southPanel = new JPanel();
southPanel.setBackground(Color.GREEN);
panel.add(southPanel, BorderLayout.SOUTH);
btnClear = new JButton("CLEAR");
southPanel.add(btnClear, BorderLayout.CENTER);
btnNext = new JButton("NEXT");
southPanel.add(btnNext, BorderLayout.WEST);
/*
* End of South Panel
*/
}
}
ありがとうございました –