Java中的组件显示不全,这是怎么回事?
我明明写了12行空的Text,却只显示4行空的Textimportjava.awt.*;importjava.awt.event.ActionEvent;importja...
我明明写了12行空的Text,却只显示4行空的Textimport java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class 备忘录 extends JFrame implements ActionListener { JMenuBar menuBar = new JMenuBar();JMenu[] menu = new JMenu[3];JMenuItem item1 = new JMenuItem("退出");JMenuItem item2 = new JMenuItem("增加");JPanel p = new JPanel();JTextField data = new JTextField("日期",10); JTextField time = new JTextField("时间",10);JTextField incident = new JTextField("事件",40); JTextField[][] text = new JTextField[12][3]; public 备忘录() {setTitle("备忘录");setBounds(100,100,700,600);setResizable(false);setVisible(true);setDefaultCloseOperation(EXIT_ON_CLOSE); add(menuBar,BorderLayout.NORTH);menu[0] = new JMenu("文件");menu[1] = new JMenu("编辑");menu[2] = new JMenu("帮助");menu[0].add(item1);menu[1].add(item2);
for (int i = 0; i < 3; i++) {menuBar.add(menu[i]);}data.setHorizontalAlignment(JTextField.CENTER);time.setHorizontalAlignment(JTextField.CENTER);incident.setHorizontalAlignment(JTextField.CENTER);
data.setEditable(false); time.setEditable(false); incident.setEditable(false);
p.add(data);p.add(time);p.add(incident);p.setLayout(new FlowLayout());add(p); for (int i = 0; i < 12; i++) {text[i][0] = new JTextField(10);text[i][1] = new JTextField(10); text[i][2] = new JTextField(40); p.add(text[i][0]); p.add(text[i][1]); p.add(text[i][2]); }}
public void actionPerformed(ActionEvent e) { } public static void main(String[] args) {new 备忘录(); }}
问题已经解决…原来把setVisible(true)放在最后就好了… 展开
for (int i = 0; i < 3; i++) {menuBar.add(menu[i]);}data.setHorizontalAlignment(JTextField.CENTER);time.setHorizontalAlignment(JTextField.CENTER);incident.setHorizontalAlignment(JTextField.CENTER);
data.setEditable(false); time.setEditable(false); incident.setEditable(false);
p.add(data);p.add(time);p.add(incident);p.setLayout(new FlowLayout());add(p); for (int i = 0; i < 12; i++) {text[i][0] = new JTextField(10);text[i][1] = new JTextField(10); text[i][2] = new JTextField(40); p.add(text[i][0]); p.add(text[i][1]); p.add(text[i][2]); }}
public void actionPerformed(ActionEvent e) { } public static void main(String[] args) {new 备忘录(); }}
问题已经解决…原来把setVisible(true)放在最后就好了… 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询