Solved

How do I show this window with my textfields and labels?

Posted on 2009-05-18
2
162 Views
Last Modified: 2012-05-07
I cant get my labels and textfield so show in my window. What do I miss?
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
 
 
 
 
 
public class Registrera extends JFrame {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JFrame thisFrame;
	private Container c;
	private JPanel controlPanel=new JPanel();
	JTextField userNameField = new JTextField("");
	JTextField passwordField = new JPasswordField("");
	JTextField adressField = new JPasswordField("");
	JTextField nameField = new JPasswordField("");
	JTextField teleField = new JPasswordField("");
	JTextField pnrField = new JPasswordField("");
	
	Registrera() {
	      getRegi();
 
	    }
 
	    public void getRegi() {
	      JPanel connectionPanel;
	      JLabel nameLabel = new JLabel("Name:", JLabel.RIGHT);     
	      JLabel userNameLabel = new JLabel("User Name:", JLabel.RIGHT); 
	      JLabel pnrLabel = new JLabel("Personnummer:", JLabel.RIGHT); 
	      JLabel adressLabel = new JLabel("Adress:", JLabel.RIGHT);
	      JLabel teleLabel = new JLabel("Telefon:", JLabel.RIGHT);
	      JLabel passwordLabel = new JLabel("Password:", JLabel.RIGHT);      
	      
	      connectionPanel = new JPanel(false);
	      connectionPanel.setLayout(new BoxLayout(connectionPanel, BoxLayout.X_AXIS));
	      
	      JPanel namePanel = new JPanel(false);
	      namePanel.setLayout(new GridLayout(0, 1));
	      namePanel.add(nameLabel);
	      namePanel.add(adressLabel);
	      namePanel.add(pnrLabel);
	      namePanel.add(teleLabel);
	      namePanel.add(userNameLabel);
	      namePanel.add(passwordLabel);
	      
	      JPanel fieldPanel = new JPanel(false);
	      fieldPanel.setLayout(new GridLayout(0, 1));
	      fieldPanel.add(nameField);
	      fieldPanel.add(adressField);
	      fieldPanel.add(pnrField);
	      fieldPanel.add(teleField);
	      fieldPanel.add(userNameField);
	      fieldPanel.add(passwordField);
	      
	      connectionPanel.add(namePanel);
	      connectionPanel.add(fieldPanel);
	      
	      thisFrame = this;
	      thisFrame.setSize(500,500);
	      this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	      c = getContentPane();
	
	      
	      this.add(controlPanel, BorderLayout.SOUTH);        
 
	      this.setVisible(true);
	      
	    }
	
}

Open in new window

0
Comment
Question by:Mickeys
2 Comments
 
LVL 26

Accepted Solution

by:
ksivananth earned 500 total points
ID: 24410010
you haven't added the panel which holds the fields to frame, put this line before setVisible,

c.add( connectionPanel ) ;
0
 
LVL 15

Expert Comment

by:fsze88
ID: 24410120
missed main and this.add(connectionPanel, BorderLayout.NORTH);
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
 
public class Registrera extends JFrame {
 
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        private JFrame thisFrame;
        private Container c;
        private JPanel controlPanel=new JPanel();
        JTextField userNameField = new JTextField("");
        JTextField passwordField = new JPasswordField("");
        JTextField adressField = new JPasswordField("");
        JTextField nameField = new JPasswordField("");
        JTextField teleField = new JPasswordField("");
        JTextField pnrField = new JPasswordField("");
        
        Registrera() {
              getRegi();
 
            }
 
            public void getRegi() {
              JPanel connectionPanel;
              JLabel nameLabel = new JLabel("Name:", JLabel.RIGHT);     
              JLabel userNameLabel = new JLabel("User Name:", JLabel.RIGHT); 
              JLabel pnrLabel = new JLabel("Personnummer:", JLabel.RIGHT); 
              JLabel adressLabel = new JLabel("Adress:", JLabel.RIGHT);
              JLabel teleLabel = new JLabel("Telefon:", JLabel.RIGHT);
              JLabel passwordLabel = new JLabel("Password:", JLabel.RIGHT);      
              
              connectionPanel = new JPanel(false);
              connectionPanel.setLayout(new BoxLayout(connectionPanel, BoxLayout.X_AXIS));
              
              JPanel namePanel = new JPanel(false);
              namePanel.setLayout(new GridLayout(0, 1));
              namePanel.add(nameLabel);
              namePanel.add(adressLabel);
              namePanel.add(pnrLabel);
              namePanel.add(teleLabel);
              namePanel.add(userNameLabel);
              namePanel.add(passwordLabel);
              
              JPanel fieldPanel = new JPanel(false);
              fieldPanel.setLayout(new GridLayout(0, 1));
              fieldPanel.add(nameField);
              fieldPanel.add(adressField);
              fieldPanel.add(pnrField);
              fieldPanel.add(teleField);
              fieldPanel.add(userNameField);
              fieldPanel.add(passwordField);
              
              connectionPanel.add(namePanel);
              connectionPanel.add(fieldPanel);
              
              thisFrame = this;
              thisFrame.setSize(500,500);
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
              c = getContentPane();
        
              
              this.add(controlPanel, BorderLayout.SOUTH);        
              this.add(connectionPanel, BorderLayout.NORTH);
              
              this.setVisible(true);
              
            }
            
            public static void main(String[] args){
              new Registrera();
            }
        
}

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 120
Weekend adv creator 3 53
map related example 6 55
hibernate example issues from command prompt 10 50
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question