Results 1 to 2 of 2
  1. #1
    Arom is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Simple Swing problem

    Hi,

    I've started learning Swing recently. I've built a simple application, however, whenever I am trying to add a new JTextField to the top (NORTH) of my panel, it just does not want to appear. Here's a chunk of code ;

    Java Code:
    public class CounterPanel extends JPanel {
        private CounterModel counter;
        private JLabel valueLabel;
        JButton upButton, downButton, resetButton;
     private JTextField inputField;
    
        public CounterPanel() {
            //setup the layout
            this.setLayout(new BorderLayout());
            
            //create model and its display:
            counter = new CounterModel();    
            valueLabel = new JLabel(""+counter.getValue(),SwingConstants.CENTER);
            this.add(valueLabel,BorderLayout.CENTER);
    
            //setup the listener (include a link back to here so that it can update)
            CounterListener countList = new CounterListener(this);  
            
            //now do the buttons
    
         inputField = new JTextField("0");    //Text Field
    this.add(inputField,BorderLayout.NORTH); // Position
    
    upButton = new JButton("Up"); //create a button
    this.add(upButton,BorderLayout.WEST); //position it
    upButton.addActionListener(countList); //set listener to listen 
    
    downButton = new JButton("Down"); //ditto
    this.add(downButton,BorderLayout.EAST);
    downButton.addActionListener(countList);
    
    resetButton = new JButton("Reset"); //ditto
    this.add(resetButton,BorderLayout.SOUTH);
    resetButton.addActionListener(countList);
        }

    Obviously, I have been adding JTextField in other projects, and they seem to work perfectly. I just cannot understand why it doesn't appear on this example.

    Thanks

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default Re: Simple Swing problem

    Posted code looks reasonable.

    Post your Short, Self Contained, Correct Example that demonstrates the problem.

Similar Threads

  1. Changing squares to rectangles in simple Swing program
    By codeRunner1 in forum AWT / Swing
    Replies: 0
    Last Post: 03-02-2011, 05:40 AM
  2. Simple swing program, help please!
    By N00Bie in forum New To Java
    Replies: 5
    Last Post: 02-17-2011, 05:16 PM
  3. Java Swing Simple Addition help
    By dbasenoob in forum New To Java
    Replies: 4
    Last Post: 04-27-2010, 01:26 PM
  4. Java Swing JTable Simple Doubt
    By hemanthjava in forum AWT / Swing
    Replies: 1
    Last Post: 11-26-2008, 01:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •