【发布时间】:2020-12-21 16:29:41
【问题描述】:
当我调用我的 JDialog 类时,我一遍又一遍地遇到这个问题,但没有显示任何内容,这是 JDialog 接口的代码:
public JMovie() {
JFrame f = new JFrame();
JDialog jmovie = new JDialog(f,"JMovie Dialog");
jmovie.setLayout(new BorderLayout());
okbutton = new JButton("Ok");
cancelbutton = new JButton("Cancel");
title = new JLabel("Title", SwingConstants.RIGHT);
date = new JLabel("Date made on ", SwingConstants.RIGHT);
price = new JLabel("Price", SwingConstants.RIGHT);
inputdate = new JLabel("dd/mm/yyyy");
Ttitle = new JTextField(null, 15);
TMadeon = new JTextField(null, 10);
TPrice = new JTextField(null, 6);
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jb = new JPanel();
jl = new JPanel();
okbutton.addActionListener(this);
cancelbutton.addActionListener(this);
Ttitle.setName("Title");
TMadeon.setName("Date Made on");
TPrice.setName("Price");
jb.add(okbutton);
jb.add(cancelbutton);
title.setAlignmentX(Component.RIGHT_ALIGNMENT);
date.setAlignmentX(Component.RIGHT_ALIGNMENT);
price.setAlignmentX(Component.RIGHT_ALIGNMENT);
JPanel south = new JPanel(new FlowLayout());
south.add(jb, BorderLayout.SOUTH);
JPanel west = new JPanel(new GridLayout(3,1));
west.add(title,BorderLayout.WEST);
west.add(date,BorderLayout.WEST);
west.add(price,BorderLayout.WEST);
JPanel center = new JPanel(new GridLayout(3,1));
center.add(jp3,FlowLayout.LEFT);
center.add(jp2,FlowLayout.LEFT);
center.add(jp1,FlowLayout.LEFT);
inputdate.setEnabled(false);
jmovie.setSize(350, 150);
jmovie.setLocation(300,300);
jmovie.setVisible(true);
jmovie.add(south);
jmovie.add(west);
jmovie.add(center);
}
这是接口 JMovie DIAlog 的代码,我在另一个类中调用它。
public void actionPerformed(ActionEvent event) {
if(event.getSource().equals(btnMAdd))
{
JMovie ne = new JMovie();
ne.setVisible(true);
}
}
当我运行它时显示:
【问题讨论】:
-
发布您的minimal reproducible example 以证明问题。我们应该能够复制/粘贴/编译和测试。