因此,我在JButton ActionListener中有一个名称为重命名的JFrame。以下是
JFrame rename = new JFrame("Rename File");
//other code
JButton renameb = new JButton();
renameb.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
Console.file = namef.getText();
dispose();
}
});
每当我运行它时,它只显示:
http://sp.itbind.com/s/misha/Screen%20Shot%202016-11-17%20at%2011.05.27%20PM.png (我必须提供一个链接,因为复制粘贴不起作用)
答案 0 :(得分:0)
将String filen = file + ".txt";
更改为String filen = file.getText() + ".txt";
现在Exception in thread AWT-EventQueue-0 java.lang.IllegalArgumentException
的根本原因是您缺少以下行
rename.setLayout(new GridBagLayout());
之后
JFrame rename = new JFrame("Rename File");
注意:要使用GridBagConstraints
,您需要将Layout
设为GridBagLayout