Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to run JDesktopPane

 
Joonas Järvinen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quick review to my program. It has many smaller windows that are called to the JDesktopPane and one of these windows is menu, which calls other windows to appear. These smaller windows are in another class than JDesktopPane and this menu window(duh).
The problem is. When I'am trying to call these windows from menu. Windows don't appear. No error messages are given. But when I'am doing it from the same class as the JDesktopPane. It calls these windows without problems.
Here's the code:
This is from the JDesktopPane:

And from the menu window:

It works fine when I'am calling openServer() from the same class as this method. But not when calling it from the outside. Any ideas what is causing this?
 
Maneesh Godbole
Saloon Keeper
Posts: 11341
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you getting any exceptions? If yes, can you post the stack trace?

Moving to a more appropriate forum.
 
Joonas Järvinen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No exceptions. I have printStackTraced everything but nothing is coming out.
 
Maneesh Godbole
Saloon Keeper
Posts: 11341
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joonas Järvinen wrote:No exceptions. I have printStackTraced everything but nothing is coming out.


I don't see any e.printStackTrace() here

 
Joonas Järvinen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh. Sorry about that. Bad example. Other similar methods tho do have those and nothing is coming out. Anyway. I made a simple three class program that has one JDesktopPane and two windows in it. One calls another. And ofcourse this call doens't work.
Here is the whole code of the program:
JDesktopPane. Which is also holds the main method.

Button windows which is supposed to call label window when button is pressed:

And finaly the label window:


I'am only getting errors when I try to call automically openBtnWindow() at the start of the calss. Why it doesn't work like that but work fine when calling it manually?
Here is StackOverflowError:

It pretty much just repeats the last three lines couple hundred times so I didn't copy all of it.
So. What I'am doing wrong here? Thanks in advance is you are considerate enought to review this code.
 
Maneesh Godbole
Saloon Keeper
Posts: 11341
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The culprit is your call to as the first line of your constructor. Take it out.

Change it to something like


Also you have not set any default exit operation for the JFrame. When you close your JFrame, the jvm is still running. You need to terminate the JVM when you close the jframe.
 
Joonas Järvinen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But this still don't answer to my main problem. Why can't succesfully call WindowA (the window with label) from BtnWindow?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Why can't succesfully call WindowA (the window with label) from BtnWindow?

reason is you create an entirely now RPanel in the Btnpanel class
private RPanel rear = new RPanel();

this one is not visible (visbility is set to true via main(), which is not called in the above line)
so, your rear.openWindow() calls that method in the 'invisible' RPanel frame.

you need to get a handle of the RPanel frame that is the parent of the Btnpanel internalFrame

here's one of the ways to do that:



[EDIT]
or, it might be easier for you to pass a reference of the parentFrame to the Btnpanel class via its constructor
 
Joonas Järvinen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uhhuh. Back again. This time I'am using CardLayout. But because my problem is so similar. I didn't bother making new thread about it.
So. I have exactly the same problem. But with CardLayout. I have stack of cards(classes). And I'an unable to call them from the Main class.
Also. I'am not sure how I should modify this SwingUtilities.getAncestorOfClass to be constructor compatible. It would be much more handy if it were in the constrctor.
Eitherway. It doesn't work with the cardLayout as it works with JDesktopPane. I don't quite understand why. Because as I see it. The idea is same.
Here's how it looks at the moment:


And the error message:
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joonas Järvinen!

Do you know this site http://stackoverflow.com/? lol
You are in an infinite loop. hauua
From your third post, change the following:

RPanel:
private static JDesktopPane rearpanel = new JDesktopPane();
public static void openWindow() {

Btnpanel:
remove => private RPanel rear = new RPanel();
btna.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
RPanel.openWindow();
}
});
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic