GUI won't show

I don't understand what im doing wrong. My GUI won't show

import javax.swing.SpringLayout;

import java.awt.BorderLayout;

import javax.swing.JLabel;

import javax.swing.JTextField;

import javax.swing.JTextArea;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JButton;

import javax.swing.UIManager;

import java.awt.Container;

publicclass layout{

publicstatic JFrame frame;

publicstatic JTextArea Text;

publicstatic JPanel panel;

publicstatic JButton button;

publicstatic JLabel label;

publicstatic Container ContentPane;

publicstaticvoid lookAndFeel(){

try{

UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

}catch (Exception e){}

}

privatestaticvoid LookAndFeel(){

lookAndFeel();

}

privatestaticvoid createAndShowGUI(){

lookAndFeel();

ContentPane=frame.getContentPane();

ContentPane.setLayout(new SpringLayout());

button=new JButton("Click");

frame=new JFrame("JFrame");

Text=new JTextArea();

//JPanel

panel=new JPanel(new SpringLayout());

panel.setLayout(new BorderLayout());

panel.add(new JButton("Klick"),BorderLayout.SOUTH);

panel.setOpaque(true);

//JLabel

label=new JLabel();

label.setOpaque(true);

label.add(button);

LookAndFeel();

frame.setVisible(true);

frame.setSize(300,300);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

publicstaticvoid main(String[]arg){

new layout();

createAndShowGUI();

}

}

[3932 byte] By [Gimlia] at [2007-11-27 1:28:41]
# 1
just look at your compiler output you have to initialise frame before call getcontentpane()and you don't need the method private static void lookandfeelit makes no sense if you got the real mehtod publicMessage was edited by: nobbynobbes
nobbynobbesa at 2007-7-12 0:26:57 > top of Java-index,Desktop,Core GUI APIs...
# 2
hmm, it's still the same. A gray frame with noting in it. Why?
Gimlia at 2007-7-12 0:26:57 > top of Java-index,Desktop,Core GUI APIs...
# 3
Hi...The thing is u r not adding the Panel / JButton /JLabel to ur frame......add those to ur Jframe...eg... frame.add(panel); frame.add(JButton);etc....or specify even where u want to add those components...also...
LeoSuna at 2007-7-12 0:26:57 > top of Java-index,Desktop,Core GUI APIs...
# 4
Okay, but if you had a container you would need to add the buttons and textFields to the container and then add the Container itself to the frame?
Gimlia at 2007-7-12 0:26:57 > top of Java-index,Desktop,Core GUI APIs...
# 5
yes,but where you are adding those objects to the container.....
LeoSuna at 2007-7-12 0:26:57 > top of Java-index,Desktop,Core GUI APIs...
# 6
the frame itself will show up if you did like i said if you want to see other things have a look at http://java.sun.com/docs/books/tutorial/
nobbynobbesa at 2007-7-12 0:26:57 > top of Java-index,Desktop,Core GUI APIs...
# 7

Another thing....

I'd like to possition three JTextFields in a Trailing fashion

and below them a larger TextField but i am unable to do so. If anyone could point out what im doing wrong....

JFrame frame = new JFrame("SpringDemo4");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//The Panel

JPanel Panel=new JPanel(new SpringLayout());

//TExtFields

JTextField textField = new JTextField("Text field", 15);

JTextField textField2 = new JTextField("Text field",15);

//The Labels

JLabel label = new JLabel("Label: ",JLabel.TRAILING);

label.setLabelFor(textField);

JLabel label2 = new JLabel("Label: ",JLabel.TRAILING);

label2.setLabelFor(textField2);

//The panel

Panel.add(label);

Panel.add(label2);

Panel.add(textField);

Panel.add(textField2);

//Set up the content pane.

Container contentPane = frame.getContentPane(); //ContentPane

SpringLayout layout = new SpringLayout();

contentPane.setLayout(layout);

layout.putConstraint(SpringLayout.EAST, contentPane,5,SpringLayout.EAST, textField);

layout.putConstraint(SpringLayout.SOUTH, contentPane,5,SpringLayout.SOUTH, textField);

contentPane.add(Panel);

Panel.setOpaque(true);

//Display the window.

frame.pack();

frame.setVisible(true);

frame.setContentPane(contentPane);

Message was edited by:

Gimli

Gimlia at 2007-7-12 0:26:57 > top of Java-index,Desktop,Core GUI APIs...