1

The following method extends a JFrame, but I need a swing textbox inside it to receive double values and store them in a variable. the textbox must be added to the container.

    public class myClass extends JFrame{
        Container container;
        container = getContentPane();

        //Item label
        JLabel labelText = new JLabel();        
       ...
        labelText.setText ("Item:");        
        container.add( labelText );

        //Item name: Textbox
        //code to make a textbox, add it to the container, and store the value in a                      variable goes here
mKorbel
  • 109,525
  • 20
  • 134
  • 319
rainhider
  • 49
  • 1
  • 4
  • 13
  • You could look at [How to use Text Fields](http://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html) and [Implementing a Document Filter](http://docs.oracle.com/javase/tutorial/uiswing/components/generaltext.html#filter), you could also have a look at [How to use Spinners](http://docs.oracle.com/javase/tutorial/uiswing/components/spinner.html) – MadProgrammer Mar 21 '13 at 01:58

1 Answers1

6

Use a JTextField:

 JTextField field = new JTextField(10);
 container.add(field, BorderLayout.SOUTH);

To get the value of the field, do Double.parseDouble(field.getText()).

syb0rg
  • 8,057
  • 9
  • 41
  • 81
jedyobidan
  • 876
  • 1
  • 8
  • 14