wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JDesktopPane creates inner frame menuItem actionPerformed does not. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDesktopPane creates inner frame menuItem actionPerformed does not." Watch "JDesktopPane creates inner frame menuItem actionPerformed does not." New topic
Author

JDesktopPane creates inner frame menuItem actionPerformed does not.

James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
Hello could someone help me figure out how to make my menu item work? It calls createFrame() to add an additional inner frame. It runs but nothing is added to the JDesktopPane.




Rok Štelcer
Ranch Hand

Joined: Nov 03, 2009
Posts: 101
Your example is almost "the same" as the one from Sun's for internal frames:
- InternalFrameDemo.java
- MyInternalFrame.java


SCJP, SCWCD
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
Yes, it is. But I can't get it to load more than one internal frame
thanks
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
The only differences are that I have a class tho add to the frame.add() and the JMenu is created in the Menu.java.

I have to do something to the action performed or something because it calls createFrame.
Something is wrong with my menuItem.

It can create how ever many frames I want if I call createFrame over and over in the class
'
I tried the .addActionListener

I tried the



no new frames
thanks








E
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
what do you think this line does? (in mousePressed)

dp=new DesktopPane();
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
the desktop runs from main creating

the first internal frame perfect

it says it created more (too many

infact)

but nothing gets painted to JDesktopPane

is there a way to get the Jmenu to

create one more internalframe?



Desktop class



Jmenu actionEvent




output


back in the create Frame() number of frames= 0
internal frame openFrameCount= 1
start obj() type= guide
createGuideInternalFrame
back in the create Frame() number of frames= 1
internal frame openFrameCount= 2
start obj() type= guide
back in the create Frame() number of frames= 2
internal frame openFrameCount= 3
start obj() type= guide

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
read your code

DesktopPane frame = new DesktopPane();
JDesktopPane jdp;
setContentPane(jdp);
...and in createFrame();
InternalFrame frame=new InternalFrame();
jdp.add(frame);

and in your actionListener
DesktopPane dp = new DesktopPane();
dp.createFrame();

how many DesktopPane()'s are shown?
hint: 'new' means another one
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
It looks like in my actionListener I am making a new JDesktopPane which calls createFrame();

I guess I am not sure how to have the actionListener call the createFrame(); without the importing the DeskTopPane class a dp so it knows what the createFrame() is "dp.createFrame();"






Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> It looks like in my actionListener I am making a new JDesktopPane which calls createFrame();

actually, you are creating another instance of 'DesktopPane' (a JFrame),
which calls createFrame()

>I guess I am not sure how to have the actionListener call the createFrame();
> without the importing the DeskTopPane class a dp so it knows what the createFrame() is "dp.createFrame();"

usual way is:

DesktopPane.this.createFrame();
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
The only thing I could think of:

My JDesktop.class makes the JDesktop pane
a new internal frame class is called that creates and returned to it and adds it fine.

I used a setter to set the JDesktopPane into This new class

my actionPerformed calls the void method that of this new class and it tries the same thin only it tries to have the JDesktopPane that is now in the class
add the InternalFRame.

JMenu item



the new CreateNewGuide.class


the error



output
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
just looking at the code, you would need to call this
public void setJdp(JDesktopPane jdp) {
before calling this
CreateNewGuide() ---> jdp.add(frame);
otherwise jdp will be null

curious line this
public void CreateNewGuide() throws FileNotFoundException, IOException, PropertyVetoException {

why have the method name the same as the class name - most will think it should be a constructor, with errant 'void'm included
why all the unrelated throws exceptions
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
I changed the order of jdp creation
it still runs good from main but the
It does not want to deal with jdp.add(frame) in the createNewFrame()
JMenu item



the new CreateNewGuide.class


the error

Thanks for your time.
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
My getter method had code to Jdp=null I removed that but same error
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you still haven't addressed the problem mentioned in my earlier post

in CreateNewGuide() you have this
public JDesktopPane jdp;

then, when you call cnf.CreateNewGuide(); (assuming [CreateNewFrame] cnf=new CreateNewGuide() is a typo)
includes
jdp.add(frame);

so, jdp has to be null

you can either use a constructor to pass a reference of the desktoppane to jdp, or
CreateNewFrame cnf=new CreateNewGuide();
cnf.setJdp(ref to desktoppane);//<----------------add this line
cnf.CreateNewGuide();
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
since it did not like setting the frame from the InternalFrame class

I tried to set the frame created in the jdp class.

and told the setter to add the frame to jdp.

but there needs to be something in the JDesktopPane class to be waiting for the new frame.

should I be trying a Runnable class?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> should I be trying a Runnable class?

I can't see how a runnable class would help, you need to pass a reference of the
visible JFrame's desktoppane all the way down the line to where it is used in CreateNewGuide()

It might be worth you starting another project, just to simplify everything
only include the desktoppane and internal frame stuff, along with a single menuitem with actionListener.
if you still can't get it working, you'll have something small and complete to post here.

your code posted so far is very difficult to follow, things like
public class CreateNewGuide extends JInternalFrame

why would it extend JIternalFrame, when it uses an inner class that also extends JInternalFrame
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
My original mission was to make more packages and classes to make more generic classes.

That is why I couldn't call my JDesktopPane from my JMenuBar

I had to move it to my JDesktopPane and it makes sense now.
The menu is for a the window

here is the code it works good. On to the next problem. One problem solved 12 more created.

Thanks again for your help.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDesktopPane creates inner frame menuItem actionPerformed does not.
 
Similar Threads
Adding Components in to JInternalFrame
InternalFrame not resizing
adding an InternalFrameListener to a JMenu Item
JDesktopPane
JInternalFrames + JSliders