我正在尝试设置 quiz_7 的文本字段,但是,它不像剩余的六个那样显示,我尝试将参数设置为 360,没有文本字段。将其更改为 340,但我只看到半个文本字段。
import java.awt.Container;
import javax.swing.*;
public class QuizEntry {
JPanel textPanel,panelForTextFields;
JLabel Entry_for_Quizes, quiz1, quiz2, quiz3, quiz4, quiz5, quiz6;
JTextField quiz_1, quiz_2, quiz_3, quiz_4, quiz_5, quiz_6;
JTextField quiz_7;
private JLabel quiz7;
public JPanel createContentPane() {
// We create a bottom JPanel to place everything on.
JPanel totalGUI1 = new JPanel();
totalGUI1.setLayout(null);
Entry_for_Quizes = new JLabel("Quiz Entry ");
Entry_for_Quizes.setLocation(0, 0);
Entry_for_Quizes.setSize(400, 400);
Entry_for_Quizes.setHorizontalAlignment(4);
totalGUI1.add(Entry_for_Quizes);
// Creation of a Panel to contain the JLabels
textPanel = new JPanel();
textPanel.setLayout(null);
textPanel.setLocation(10, 35);
textPanel.setSize(100, 600);
totalGUI1.add(textPanel);
// Username Label
quiz1 = new JLabel("Quiz 1");
quiz1.setLocation(-20, 0);
quiz1.setSize(70, 40);
quiz1.setHorizontalAlignment(4);
textPanel.add(quiz1);
// Login Label
quiz2 = new JLabel("Quiz 2");
quiz2.setLocation(-20, 60);
quiz2.setSize(70, 40);
quiz2.setHorizontalAlignment(4);
textPanel.add(quiz2);
// Username Label
quiz3 = new JLabel("Quiz 3");
quiz3.setLocation(-20, 120);
quiz3.setSize(70, 40);
quiz3.setHorizontalAlignment(4);
textPanel.add(quiz3);
// Login Label
quiz4 = new JLabel("Quiz 4");
quiz4.setLocation(-20, 180);
quiz4.setSize(70, 40);
quiz4.setHorizontalAlignment(4);
textPanel.add(quiz4);
// Username Label
quiz5 = new JLabel("Quiz 5");
quiz5.setLocation(-20, 240);
quiz5.setSize(70, 40);
quiz5.setHorizontalAlignment(4);
textPanel.add(quiz5);
// L
quiz6 = new JLabel("Quiz 6");
quiz6.setLocation(-20, 300);
quiz6.setSize(70, 40);
quiz6.setHorizontalAlignment(4);
textPanel.add(quiz6);
quiz7 = new JLabel("Quiz 7");
quiz7.setLocation(-20, 350);
quiz7.setSize(70, 40);
quiz7.setHorizontalAlignment(4);
textPanel.add(quiz7);
//////////////////////////////////////////////////////////////
panelForTextFields = new JPanel();
panelForTextFields.setLayout(null);
panelForTextFields.setLocation(110, 40);
panelForTextFields.setSize(100, 350);
totalGUI1.add(panelForTextFields);
// quiz Textfield
quiz_1 = new JTextField(8);
quiz_1.setLocation(0, 0);
quiz_1.setSize(100, 30);
panelForTextFields.add(quiz_1);
quiz_2 = new JTextField(8);
quiz_2.setLocation(0, 60);
quiz_2.setSize(100, 30);
panelForTextFields.add(quiz_2);
quiz_3 = new JTextField(8);
quiz_3.setLocation(0, 120);
quiz_3.setSize(100, 30);
panelForTextFields.add(quiz_3);
quiz_4 = new JTextField(8);
quiz_4.setLocation(0, 180);
quiz_4.setSize(100, 30);
panelForTextFields.add(quiz_4);
quiz_5 = new JTextField(8);
quiz_5.setLocation(0, 240);
quiz_5.setSize(100, 30);
panelForTextFields.add(quiz_5);
quiz_6 = new JTextField(8);
quiz_6.setLocation(0, 300);
quiz_6.setSize(100, 30);
panelForTextFields.add(quiz_6);
quiz_7 = new JTextField(8);
quiz_7.setLocation(0, 340);
quiz_7.setSize(100, 30);
panelForTextFields.add(quiz_7);
return totalGUI1;
}
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Quiz Entry");
QuizEntry demo = new QuizEntry();
frame.setContentPane(demo.createContentPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(700, 700);
frame.setVisible(true);
}
public static void main(String[] args) {
// Schedule a job for the event-dispatching thread:
// creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}