Results 1 to 2 of 2
Thread: Simple Swing problem
- 02-11-2012, 04:27 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
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
- 02-11-2012, 05:50 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: Simple Swing problem
Posted code looks reasonable.
Post your Short, Self Contained, Correct Example that demonstrates the problem.
Similar Threads
-
Changing squares to rectangles in simple Swing program
By codeRunner1 in forum AWT / SwingReplies: 0Last Post: 03-02-2011, 05:40 AM -
Simple swing program, help please!
By N00Bie in forum New To JavaReplies: 5Last Post: 02-17-2011, 05:16 PM -
Java Swing Simple Addition help
By dbasenoob in forum New To JavaReplies: 4Last Post: 04-27-2010, 01:26 PM -
Java Swing JTable Simple Doubt
By hemanthjava in forum AWT / SwingReplies: 1Last Post: 11-26-2008, 01:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks