因此,我在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(我必须放置一个链接,因为复制粘贴无效)
更改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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句