File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Trouble implementing a GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Trouble implementing a GUI" Watch "Trouble implementing a GUI" New topic

Trouble implementing a GUI

John Meehan

Joined: Oct 28, 2011
Posts: 12

Hi everyone, I'm having some issues with a programming assignment. I'm trying to implement a GUI for some backend code our professor gave us, but I can't seem to get anything to show. Basically the GUI is supposed to have some image manipulation buttons (implemented by the backend) up top, open/save buttons at the bottom, and an image in the center using ImageIcon, which only appears after an image has been opened. I'm trying to make a big JPanel with a Border Layout, and smaller JPanels with FlowLayout to contain the buttons and image icon. When I run the code the JPanel opens, but there's nothing inside. I'm thinking the smaller panels are implementing, but not getting placed into the larger one. Any way you guys could help would be appreciated.

I'm not trying to implement the backend yet, just get the GUI to look correct. The ImageIcon for the center hasn't been implemented yet either, I'm working on that now.
Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 208

You're absolutely right, the smaller panels aren't getting placed into the larger one. You have to add the panel in your SnapShopPanel to the SnapShopPanel itself.

Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
John Meehan

Joined: Oct 28, 2011
Posts: 12

Ah, I new it was something simple I was missing. How would I go about doing that? Do I just add another pack(); at the end of SnapShopPanel, then call add(SnapShopPanel.panel); instead of add(panel);?
John Meehan

Joined: Oct 28, 2011
Posts: 12

Actually, I think part of my problem is I'm going too hog wild on the helper classes. I'll try to make things a little more contained, see if that helps.

Edit: nevermind, I've got it now. Instead of adding to panel in SnapShopPanel I should have just added. Oh well, at least things will go quicker now.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46380
Welcome to the Ranch

I think I shall move this discussion to our GUIs forum.
You ought to consider developing the backend first. Get it working from the command line, then you can put the display on top of it. You should also consider starting very small with GUIs. Your first GUI should be very simple, like this one. Beware: you will have to scroll down to find out what the two errors in that code are. When building a bigger GUI, you should compile and run it after adding every component. That way you will see early that something is wrong, and be able to correct it sooner.
I agree. Here's the link:
subject: Trouble implementing a GUI
It's not a secret anymore!