我有一个Jwindow,当我向它添加一个Jtextfield时,textfield就变得不可编辑了。
JWindow window = new JWindow();
window.setBounds(400, 100, 700,500);
window.setVisible(true);
window.setLayout(null);
JTextField text = new JTextField();
text.setBounds(300, 300, 150, 30);
text.setEditable(true);
window.getContentPane().add(text);但是,当我尝试使用Jframe作为jwindow的所有者时,textfield现在是可编辑的,但是这个框架与jwindow一起出现了:
JFrame frame = new JFrame();
frame.setVisible(true);
JWindow window = new JWindow();
window.setBounds(400, 100, 700,500);
window.setVisible(true);
window.setLayout(null);
JTextField text = new JTextField();
text.setBounds(300, 300, 150, 30);
text.setEditable(true);
window.getContentPane().add(text);所以,我有两个问题:
发布于 2012-03-12 06:54:16
编辑,
只有当
JDialog而不是JWindow,jDialog不导致non_accesible内容,。。。
1. Why JTextField is uneditable in JWindow and how could i let it able to edit?真的不知道
import java.awt.*;
import javax.swing.*;
public class WindowTest {
private JFrame frame;
public JPanel createContentPane() {
JTextField text = new JTextField("Whatewer");
JPanel panel = new JPanel();
panel.add(text);
createAndShowWindow();
return panel;
}
void createAndShowGUI() {
frame = new JFrame("Window Test");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setContentPane(createContentPane());
frame.setLocation(50, 50);
frame.pack();
frame.setVisible(true);
}
private void createAndShowWindow() {
JTextField text = new JTextField("Whatewer");
JWindow win = new JWindow(frame);
win.setLayout(new GridLayout(0, 1));
win.add(text);
win.pack();
win.setLocation(150, 50);
win.setVisible(true);
}
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new WindowTest().createAndShowGUI();
}
});
}
}编辑
Yes, both are editable, and i wannt only JWindow to be displayed. Thanks!! 默认情况下,对于正确的workaround
frame.setDefaultClose中删除这些代码行.从我的示例ActionListener
frame.setVisible(true); (当前JVM实例从未从内存中删除),直到您的PC重新启动或关闭为止,您必须在frame.setVisible(true);中添加带有代码行System.exit(0)的分隔出口JButton。发布于 2012-03-12 06:50:10
JWindow应该是可聚焦的。使用public void setFocusable(boolean focusable)方法。
https://stackoverflow.com/questions/9662761
复制相似问题