In Java swing, I cannot edit a JTextField from within a popup window. The following code is a simple program that allows me to push a button and JTextField with the number 0 filled in appears. I want to be able to edit that 0 but I don't seem to be able to do it.
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PopupTest { public static void main(String[] args) { final JFrame MainFrame = new JFrame(); MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JPanel MainPanel = new JPanel(); MainPanel.setLayout(new BoxLayout(MainPanel,BoxLayout.Y_AXIS)); MainFrame.add(MainPanel); final JLabel TheLabel = new JLabel("Test"); MainPanel.add(TheLabel); final JButton PopUpButton = new JButton("Open PopUp"); MainPanel.add(PopUpButton); PopUpButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { JPanel PopUpPanel = new JPanel(); PopUpPanel.setLayout(new BoxLayout(PopUpPanel,BoxLayout.Y_AXIS)); PopupFactory factory = PopupFactory.getSharedInstance(); final Popup ThePopUp = factory.getPopup(MainPanel,PopUpPanel,40,40); JTextField Text1 = new JTextField("0"); PopUpPanel.add(Text1); ThePopUp.show(); } }); MainFrame.pack(); MainFrame.setVisible(true); } }