Read-only archive of the Armageddon Games Forums Archive (2000–2026) · About this archive

Any Java Swing programmers here? (help needed!)

5 replies · 1,285 views · Started 03 May 2005

I'm working on a project for my Java class that involves making a program with swing components that lets you draw shapes onto a JPanel. I'm pretty much done, but there is one thing I'm trying to do for the project than I have not been able to figure out how to do.

Basically the app is made of a JFrame with a JMenuBar and a JPanel (which I added to the JFrame). What I'm trying to do is enable/disable menu items items when a certain action happens in JPanel (I extend JPanel and have my own class). I've tried using the getParent method in the JPanel, but I don't think it gives me a reference to the JFrame.

Anyone able to help me out?

I managed to get it working - I had to chain getParent() together like four times to get a reference to my DrawingFrame cause the parent of my DrawingPanel was JPanel, whose parent was JLayeredPane, whose parent was JRootPane, whose parent was (finally!) DrawingFrame.

I like your's better though Saffith, it's much cleaner to read and understand, plus it works! Thanks a lot! 😃

It's not too bad. We had to learn to write the GUI stuff ourselves, where in a real development environment you'd use an IDE or something to make the GUI, and just code in the the event handlers, etc.

Yeah, I had a semester of GUI writing in Java both with and without Swing... it makes you appreciate the Windows Form designer. 😊