Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Display a JPanel

Reply
Thread Tools

Display a JPanel

 
 
Jenny
Guest
Posts: n/a
 
      08-10-2004
Hi All,

I have two code. Could you tell me why first one hide the JPanel
initially but second one does not? Pleaes run them and see the
result. Thanks a lot

Jenny

First:
import java.awt.*;
import javax.swing.*;
public class Mango {
public static void main(String[] args) {
JFrame f = new JFrame("The Frame");
f.setLocation(100, 100);
Container content = new JPanel( );
content.add(new JLabel("Mango"));
content.add(new JButton("Mango"));
f.setContentPane(content);
f.setVisible(true);
}
}

second:

import java.awt.*;
import javax.swing.*;

public class LottoMadness extends JFrame {

// set up row 1
JPanel row1 = new JPanel();
ButtonGroup option = new ButtonGroup();
JCheckBox quickpick = new JCheckBox("Quick Pick", false);
JCheckBox personal = new JCheckBox("Personal", true);
// set up row 2
JPanel row2 = new JPanel();
JLabel numbersLabel = new JLabel("Your picks ", JLabel.RIGHT);
JTextField[] numbers = new JTextField[6];
JLabel winnersLabel = new JLabel("Winners ", JLabel.RIGHT);
JTextField[] winners = new JTextField[6];
// set up row 3
JPanel row3 = new JPanel();
JButton stop = new JButton("Stop");
JButton play = new JButton("Play");
JButton reset = new JButton("Reset");
// set up row 4
JPanel row4 = new JPanel();
JLabel got3Label = new JLabel("3 of 6 ", JLabel.RIGHT);
JTextField got3 = new JTextField();
JLabel got4Label = new JLabel("4 of 6 ", JLabel.RIGHT);
JTextField got4 = new JTextField();
JLabel got5Label = new JLabel("5 of 6 ", JLabel.RIGHT);
JTextField got5 = new JTextField();
JLabel got6Label = new JLabel("6 of 6 ", JLabel.RIGHT);
JTextField got6 = new JTextField(10);
JLabel drawingsLabel = new JLabel("Drawings ", JLabel.RIGHT);
JTextField drawings = new JTextField();
JLabel yearsLabel = new JLabel("Years ", JLabel.RIGHT);
JTextField years = new JTextField();

public LottoMadness() {
super("Lotto Madness");
setSize(550, 270);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout layout = new GridLayout(5, 1, 10, 10);
Container pane = getContentPane();
pane.setLayout(layout);

FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER,
10, 10);
option.add(quickpick);
option.add(personal);
row1.setLayout(layout1);
row1.add(quickpick);
row1.add(personal);
pane.add(row1);

GridLayout layout2 = new GridLayout(2, 7, 10, 10);
row2.setLayout(layout2);
row2.setLayout(layout2);
row2.add(numbersLabel);
for (int i = 0; i < 6; i++) {
numbers[i] = new JTextField();
row2.add(numbers[i]);
}
row2.add(winnersLabel);
for (int i = 0; i < 6; i++) {
winners[i] = new JTextField();
winners[i].setEditable(false);
row2.add(winners[i]);
}
pane.add(row2);

FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER,
10, 10);
row3.setLayout(layout3);
stop.setEnabled(false);
row3.add(stop);
row3.add(play);
row3.add(reset);
pane.add(row3);

GridLayout layout4 = new GridLayout(2, 3, 20, 10);
row4.setLayout(layout4);
row4.add(got3Label);
got3.setEditable(false);
row4.add(got3);
row4.add(got4Label);
got4.setEditable(false);
row4.add(got4);
row4.add(got5Label);
got5.setEditable(false);
row4.add(got5);
row4.add(got6Label);
got6.setEditable(false);
row4.add(got6);
row4.add(drawingsLabel);
drawings.setEditable(false);
row4.add(drawings);
row4.add(yearsLabel);
years.setEditable(false);
row4.add(years);
pane.add(row4);
setContentPane(pane);
setVisible(true);
}

public static void main(String[] arguments) {
LottoMadness frame = new LottoMadness();
}
}
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      08-10-2004
On 10 Aug 2004 10:51:00 -0700, Jenny wrote:

> Could you tell me why first one hide the JPanel
> initially but second one does not?


Dunno.. But I noticed you did not call
validate() on either if them..

Try that at the end of the constructor and
see if the behaviour changes..

HTH

BTW, do you realize that another group
concentrates on GUI matters?
<http://www.physci.org/codes/javafaq.jsp#cljg>

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
 
andrewh1
Guest
Posts: n/a
 
      08-11-2004


Jenny wrote:
> Hi All,
>
> I have two code. Could you tell me why first one hide the JPanel
> initially but second one does not? Pleaes run them and see the
> result. Thanks a lot
>
> Jenny
>
> First:
> import java.awt.*;
> import javax.swing.*;
> public class Mango {
> public static void main(String[] args) {
> JFrame f = new JFrame("The Frame");
> f.setLocation(100, 100);


try adding

f.setSize(550, 270);

which is the line taken from your "LottoMadness" class.

> Container content = new JPanel( );
> content.add(new JLabel("Mango"));
> content.add(new JButton("Mango"));
> f.setContentPane(content);
> f.setVisible(true);
> }
> }
>


 
Reply With Quote
 
Jenny
Guest
Posts: n/a
 
      08-11-2004
Thanks a lot.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JPanel inside JPanel inside JFrame t1m1976 Java 1 11-07-2010 09:47 PM
[JPanel] Drop Down JPanel Raphael Jolivet Java 1 07-18-2008 12:30 AM
How to make a JPanel display another java project Kenny via JavaKB.com Java 1 02-25-2005 05:59 PM
Using ImageJ to display images in a JPanel jfalter@gmail.com Java 1 01-18-2005 02:43 PM
Add a JPanel to a JPanel... Andreas Beresko Java 6 07-16-2004 12:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57