Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 16th, 2013, 12:23 AM
jumpman8947 jumpman8947 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 5 jumpman8947 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 46 sec
Reputation Power: 0
Java exception in thread

I programmed a screen where it supposed to show different labels, text areas, buttons, etc, and it compiles with no errors but when I run the program the command prompt shows a lot of exceptions I can't figure out why its there, and my window isn't showing up... here's my code thanks
Code:
import java.awt.*;
import java.io.*;
import sun.audio.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Color.*;
import javax.swing.JFrame.*;
import java.awt.EventQueue.*;

public class EncMain extends JFrame
{
	private JLabel imageIcon;
	private JComboBox box1;
	private JButton button1;
	private JLabel label1;
	private JLabel label2;
	private JTextField field1;


	public EncMain()
	{
		JLabel label1 = new JLabel();
		JLabel label2 = new JLabel();
		JButton button1 = new JButton();
		JTextField text1 = new JTextField();
		JComboBox box1 = new JComboBox();

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("Main Menu");
		setBackground(new Color(204, 102, 0));

		label1.setIcon(new ImageIcon ("bible3.gif"));
		label1.setBorder(BorderFactory.createLineBorder(Color.blue));

		label2.setIcon(new ImageIcon ("seed.jpg"));
		label2.setPreferredSize(new Dimension(414,330));

		button1.setBackground( new Color(0, 0, 0));
		button1.setForeground(new Color(255, 0, 0));
		button1.setText("Exit");

		text1.setBackground(new Color(0, 102, 102));
		text1.setFont(new Font("Times New Roman", 1, 24));
		text1.setText("Welcome to Wisdom");

		box1.setModel(new DefaultComboBoxModel(new String[]
		{
			"Gospel", "Raeggae", "Hip-Hop"

		}));
		GroupLayout layout = new GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
			layout.createParallelGroup(GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
			.addComponent(label2, GroupLayout.PREFERRED_SIZE, 340, GroupLayout.PREFERRED_SIZE)
			.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 286, Short.MAX_VALUE)
			.addComponent(label1, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE))
			.addGroup(layout.createSequentialGroup()
				.addGap(300, 300, 300)
				.addComponent(button1, GroupLayout.PREFERRED_SIZE, 156, GroupLayout.PREFERRED_SIZE)))
			.addContainerGap())
			.addGroup(layout.createSequentialGroup()
				.addGap(262, 262, 262)
				.addComponent(text1, GroupLayout.PREFERRED_SIZE, 228, GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 116, Short.MAX_VALUE)
				.addComponent(box1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
				.addGap(108, 108, 108))

		);

                          pack();
                          setVisible(true);



		layout.setVerticalGroup(
			layout.createParallelGroup(GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
			.addGap(8, 8, 8)
			.addComponent(field1, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
			.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
			.addComponent(label2, GroupLayout.PREFERRED_SIZE, 275, GroupLayout.PREFERRED_SIZE))
			.addGroup(layout.createSequentialGroup()
			.addGap(16, 16, 16)
			.addComponent(box1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
			.addGap(18, 18, 18)
			.addComponent(label1)))
			.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
			.addComponent(button1, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE)
			.addContainerGap())

			);
			pack();
			setVisible(true);
		}
		public static void main(String[] args)
		{
			new EncMain();
		}

}





The exception threads are as followed

Exception in thread "main" java.lang.IllegalStateException: javax.swing.JTextField[,0,0,0x0,invalid,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0 .0,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@1c843d62,flags=296,maximumSize= ,minimumSize=,pre
ferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selection
Color=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=0,columnWidth=0,command=,horizontalAlignment=LEADING] is not attached to a vertical group
at javax.swing.GroupLayout.checkComponents(GroupLayout.java:1090)
at javax.swing.GroupLayout.prepare(GroupLayout.java:1040)
at javax.swing.GroupLayout.preferredLayoutSize(GroupLayout.java:878)
at java.awt.Container.preferredSize(Container.java:1788)
at java.awt.Container.getPreferredSize(Container.java:1773)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1662)
at javax.swing.JRootPane$RootLayout.preferredLayoutSize(JRootPane.java:917)
at java.awt.Container.preferredSize(Container.java:1788)
at java.awt.Container.getPreferredSize(Container.java:1773)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1662)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:719)
at java.awt.Container.preferredSize(Container.java:1788)
at java.awt.Container.getPreferredSize(Container.java:1773)
at java.awt.Window.pack(Window.java:809)
at EncMain.<init>(EncMain.java:73)
at EncMain.main(EncMain.java:102)

Reply With Quote
  #2  
Old March 16th, 2013, 06:07 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,956 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 56 m 11 sec
Reputation Power: 345
There are two calls to pack(). try removing one of them.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Java exception in thread

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap