Running Frame [message #38019] |
Thu, 20 May 2004 06:54  |
Eclipse User |
|
|
|
Originally posted by: pts.uninova.pt
Hi, I would like some help, if possible
When I run my frame, the swing components donŽt appear.
Can any body tell me why is that?
Thanks, in advance.
|
|
|
|
|
Re: Running Frame [message #38211 is a reply to message #38179] |
Thu, 20 May 2004 11:02  |
Eclipse User |
|
|
|
Originally posted by: myersj.nospam.us.ibm.com
Pedro,
You're missing a brace ending the declaration of the main() method, so
the JButton's method declaration is messed up. I'm surprised this code
will even compile.
Note: in your main() method you probably should also add the line:
frame.show();
after the construction of the frame.
Good luck,
- Jeff
Pedro Teves wrote:
> This code shows that I am tried to create a frame with a button.
> And when I run the code the ContentPane doesn't appear.
>
> Thank you very much.
>
> public static void main(String[] args) {
> Myframe frame = new Myframe();
> private javax.swing.JButton getJButton() {
> if (jButton == null) {
> jButton = new javax.swing.JButton();
> jButton.setBounds(195, 65, 87, 62);
> jButton.setText("OK");
> jButton.setOpaque(false);
> jButton.setVisible(true);
> }
> return jButton;
> }
>
>
|
|
|
Re: Running Frame [message #588899 is a reply to message #38019] |
Thu, 20 May 2004 08:37  |
Eclipse User |
|
|
|
Are you using an AWT Frame or a Swing JFrame as the container? Please
post a code sample that exhibits your problem.
- Jeff
Pedro Teves wrote:
> Hi, I would like some help, if possible
>
> When I run my frame, the swing components donŽt appear.
>
> Can any body tell me why is that?
>
> Thanks, in advance.
>
|
|
|
Re: Running Frame [message #588953 is a reply to message #38051] |
Thu, 20 May 2004 10:36  |
Eclipse User |
|
|
|
Originally posted by: pts.uninova.pt
This code shows that I am tried to create a frame with a button.
And when I run the code the ContentPane doesn't appear.
Thank you very much.
public class Myframe extends JFrame {
private javax.swing.JPanel jContentPane = null;
private javax.swing.JButton jButton = null;
/**
* This is the default constructor
*/
public Myframe() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setTitle("XPTO");
this.setSize(316, 250);
this.setContentPane(getJContentPane());
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.out.println("windowClosing()"); // TODO Auto-generated Event
stub windowClosing()
System.exit(0);
}
});
}
private javax.swing.JPanel getJContentPane() {
if(jContentPane == null) {
jContentPane = new javax.swing.JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
}
return jContentPane;
}
public static void main(String[] args) {
Myframe frame = new Myframe();
private javax.swing.JButton getJButton() {
if (jButton == null) {
jButton = new javax.swing.JButton();
jButton.setBounds(195, 65, 87, 62);
jButton.setText("OK");
jButton.setOpaque(false);
jButton.setVisible(true);
}
return jButton;
}
|
|
|
Re: Running Frame [message #588963 is a reply to message #38179] |
Thu, 20 May 2004 11:02  |
Eclipse User |
|
|
|
Pedro,
You're missing a brace ending the declaration of the main() method, so
the JButton's method declaration is messed up. I'm surprised this code
will even compile.
Note: in your main() method you probably should also add the line:
frame.show();
after the construction of the frame.
Good luck,
- Jeff
Pedro Teves wrote:
> This code shows that I am tried to create a frame with a button.
> And when I run the code the ContentPane doesn't appear.
>
> Thank you very much.
>
> public static void main(String[] args) {
> Myframe frame = new Myframe();
> private javax.swing.JButton getJButton() {
> if (jButton == null) {
> jButton = new javax.swing.JButton();
> jButton.setBounds(195, 65, 87, 62);
> jButton.setText("OK");
> jButton.setOpaque(false);
> jButton.setVisible(true);
> }
> return jButton;
> }
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.06019 seconds