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 January 30th, 2013, 07:54 PM
CraigR15 CraigR15 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 CraigR15 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 32 sec
Reputation Power: 0
Solved: Help with application not loading occasionally

I really need help with an error I've been trying to fix for the past 2 days. I'm using a CardLayout and switching between different JPanels. I'm Pulling the JPanel into the Main JPanel which is shown to the user.

I'm having an issue because occasionally my application will load but no GUI components will be shown. Other times when I load the application, it loads perfectly. I really can't figure it out.

I'm using Tomcat Juno IDE to develop the application, when the app loads and doesn't show anything I see a quick glimpse of an error occurring in the console, but it disappears immediately after and I don't know any way to reveal it.

I have created a quick code example if anyone can provide any help. I don't understand why it's working occasionally.
Code:

public class TestClass { 	 	

JFrame MainScreenFrame; // Declare main JFrame
JPanel MainPanel = new JPanel(); // Panel used to set the current layout of the frame to new 

JPanel 	CardLayout cards = new CardLayout(); 

JPanel AddEmployeePanel = new JPanel(newGridBagLayout());
JPanel ShowEmployeePanel = new JPanel(newGridBagLayout());

public TestClass(){  		
MainScreenFrame = new JFrame("TestApplication"); // Create new MainFrame Panel used when opening up the application and set the title 		

MainScreenFrame.setVisible(true);
MainScreenFrame.setSize(900, 650);
MainScreenFrame.setLocationRelativeTo(null);
MainScreenFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JFrame MainScreenFrame.setResizable(false); // Dont allow user to resize frame.

MainPanel.setLayout(cards); // actually set the current layout of MainPanel // E.g. of how im adding components

JLabel enterEmployeeInfo = new JLabel("Hmmm?");
enterEmployeeInfo.setFont(new Font("Arial", Font.BOLD, 16)); 

// SetLayout method used to set gridbagconstraints
AddEmployeePanel.add(enterEmployeeInfo, c); // c defines gridbagconstraints
JLabel lolol = new JLabel("whatever");
lolol.setFont(new Font("Arial", Font.BOLD, 16)); 
// SetLayout method used to set gridbagconstraints
ShowEmployeePanel.add(lolol, c); // c defines gridbagconstraint 

MainPanel.add(AddEmployeePanel, "ADD");
MainPanel.add(ShowEmployeePanel, "SHOW");
MainScreenFrame.add(MainPanel);
cards.show(MainPanel, "ADD"); 	} 	 	

public static void main(String[] args) { 		
new TestClass(); // Call this class  	
}}


[Sorry about indentation Is there no Java Syntax Tag?

I'm sure it's really easy, but I haven't been learning Java too long. Thank you.

Last edited by CraigR15 : January 31st, 2013 at 12:59 PM. Reason: Now solved

Reply With Quote
  #2  
Old January 31st, 2013, 01:49 AM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Oct 2003
Posts: 3,130 MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 1 Day 6 m 48 sec
Reputation Power: 1736
How do you start you program? if you dont see the console, it sounds you are stating it from your editor.
have you tried to open a command prompt and start you program that way?

When posting code, the indention will be how you make it, code tags only preserve your format.
For syntax highlighting, you can use [highlight=java] my code [/highlight] instead of the code tags.

Reply With Quote
  #3  
Old January 31st, 2013, 05:36 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,961 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 3 h 23 m 31 sec
Reputation Power: 345
One possible problem is calling setVisible() BEFORE adding any components to the frame.
Try calling it AFTER the components that you want to see have been added.

Reply With Quote
  #4  
Old January 31st, 2013, 11:25 AM
CraigR15 CraigR15 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 CraigR15 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 32 sec
Reputation Power: 0
Quote:
Originally Posted by NormR
One possible problem is calling setVisible() BEFORE adding any components to the frame.
Try calling it AFTER the components that you want to see have been added.



I havn't used the setVisible at all throughout the application. All components are visible all the time. Is this bad? Any more strain on memory resources?

Thank you, I will use Java code tags from now on. How do you start the program from the command line?

I have managed to solve the problem and it turned out to be very easy. I was adding the JPanels add & show to the mainpanel before adding the mainpanel to the frame. I solved it by doing this:

E.g.

java Code:
Original - java Code
  1.  
  2. MainScreenFrame.add(MainPanel); // Add before JPanels
  3.  
  4. MainPanel.add(AddEmployeePanel, "ADD");
  5. MainPanel.add(ShowEmployeePanel, "SHOW");
  6.  
  7. cards.show(MainPanel, "ADD"); // then show the main panel
  8.  

Reply With Quote
  #5  
Old January 31st, 2013, 11:51 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,961 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 3 h 23 m 31 sec
Reputation Power: 345
Quote:
I havn't used the setVisible at all

Code:

MainScreenFrame.setVisible(true);

Did you do a Find for setVisible? I found the above in the posted code.

Reply With Quote
  #6  
Old January 31st, 2013, 12:35 PM
CraigR15 CraigR15 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 CraigR15 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 32 sec
Reputation Power: 0
Quote:
Originally Posted by NormR
Code:

MainScreenFrame.setVisible(true);

Did you do a Find for setVisible? I found the above in the posted code.



Sorry I thought you was talking about the a GUI component being set to visible which I didn't think was possible, not the frame.

Cheers

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Help with application not loading occasionally

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