Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Design Tab not displaying images
Design Tab not displaying images [message #1218829] Fri, 29 November 2013 13:03 Go to next message
Peter Popoola is currently offline Peter PopoolaFriend
Messages: 8
Registered: November 2013
Junior Member
Hi, could anyone help me understand what the problem I have is? I wrote a program to display a background image using a JLabel, and when I run the program, the image displays alright. However, when I switch to the design tab, I can't see the image! I really need to see the image on the design tab, because I want to map different sections of the same image to listen to mouse events and respond to them. Can anyone help me?

Right, @Clayberg. Here's the code:

package job;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class MainPage extends JFrame {

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					MainPage frame = new MainPage();
					frame.setVisible(true);
					frame.pack();
					frame.setResizable(false);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	private JPanel contentPane;

	/**
	 * Create the frame.
	 */
	public MainPage() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);

		JMenuItem mntmExit = new JMenuItem("Exit");
		mnFile.add(mntmExit);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		BufferedImage hImage = null;
		BufferedImage mapImage = null;
		try {
			hImage = ImageIO.read(new File("bgnd.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}

		JLabel header = new JLabel(new ImageIcon(hImage));
		header.setLayout(new BorderLayout(0, 0));
		contentPane.add(header, BorderLayout.CENTER);
	}

}

[Updated on: Sat, 30 November 2013 07:10]

Report message to a moderator

Re: Design Tab not displaying images [message #1218903 is a reply to message #1218829] Fri, 29 November 2013 13:51 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
You haven't provided much info to go on here. How are you defining the image? How are you telling the JLabel about it? How about some sample code?
Re: Design Tab not displaying images [message #1219044 is a reply to message #1218903] Sat, 30 November 2013 07:13 Go to previous messageGo to next message
Peter Popoola is currently offline Peter PopoolaFriend
Messages: 8
Registered: November 2013
Junior Member
Thanks, I've just uploaded the code. The reason I didn't bother to upload it in the first place was that the program works alright when it is executed. It's jst that the image doesn't show up in the design tab. The frame itself shows up, by the way.

Here's a screenshot of what shows up on the design tab:


index.php/fa/16895/0/

[Updated on: Sat, 30 November 2013 07:20]

Report message to a moderator

Re: Design Tab not displaying images [message #1219071 is a reply to message #1219044] Sun, 01 December 2013 00:09 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
WindowBuilder is a static UI builder and will intentionally ignore any dynamic UI code. The image creation code you are using falls into that category. If you want WB tp parse and render the code in the design view, try it this way instead:

JLabel header = new JLabel(new ImageIcon(MainPage.class.getResource("bgnd.png")));

That is how the code would be generated, if you selected the image using the icon property in the property pane.

https://developers.google.com/java-dev-tools/wbpro/userinterface/images/property_editor_image1.png

https://developers.google.com/java-dev-tools/wbpro/userinterface/images/property_editor_image3.png

See the warning in the WB FAQ about dynamic UI code:

Quote:
Note that dynamic GUI code can not be rendered or edited. The problem with dynamic code is that it generally relies on runtime calculations that have no meaning at design-time. Widgets created in a loop (where the loop parameters are passed in externally) are a good example. Widgets created in conditionals where the value of the conditional is not known until runtime are another example. Dynamic GUI code constructed from the results of complex database queries is yet another example.
Re: Design Tab not displaying images [message #1219096 is a reply to message #1219071] Sun, 01 December 2013 20:08 Go to previous messageGo to next message
Peter Popoola is currently offline Peter PopoolaFriend
Messages: 8
Registered: November 2013
Junior Member
Thanks A LOT. But, a quick question: How can I add my image to the project so that I can use the Classpath resource option. And, please can you link me to any resources like websites or tutorials were I can get more detailed information about how to work with both Eclipse in general and WindowBuilder in particular. Thanks once again, this is really enlightening.

[Updated on: Sun, 01 December 2013 20:16]

Report message to a moderator

Re: Design Tab not displaying images [message #1219105 is a reply to message #1219096] Mon, 02 December 2013 00:09 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
Have you tried just copying the image to your package hierarchy?

If you want detailed info on using WB, I would recommend starting with the WB docs.
Re: Design Tab not displaying images [message #1220472 is a reply to message #1219105] Thu, 12 December 2013 02:30 Go to previous messageGo to next message
Peter Popoola is currently offline Peter PopoolaFriend
Messages: 8
Registered: November 2013
Junior Member
Yeah. Thanks a lot. Sorry I couldn't reply as quickly as I should have. My internet subscription got finished. Well, I have done that, i.e. adding the image by drag-and-drop on the package explorer, but under the classpath resource option, I can't find anything like that. It's jst a list of resources like the image you showed in your post. Also, please how can I get access to the WB docs? I tried googling it but couldn't find anything.
Here's how mine looks:
index.php/fa/17004/0/
  • Attachment: question.png
    (Size: 24.88KB, Downloaded 12325 times)

[Updated on: Thu, 12 December 2013 02:47]

Report message to a moderator

Re: Design Tab not displaying images [message #1220872 is a reply to message #1220472] Sun, 15 December 2013 00:05 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
Try Googling "WindowBuilder docs" and then click the first link.

They are also available in the Eclipse Help if you have all of WB loaded.
Re: Design Tab not displaying images [message #1220897 is a reply to message #1220872] Sun, 15 December 2013 21:00 Go to previous messageGo to next message
Peter Popoola is currently offline Peter PopoolaFriend
Messages: 8
Registered: November 2013
Junior Member
WOW. Thanks a lot. I saw a windowBuilder pdf document among the results, but it looks like it is designed for Smalltalk or sth like that. I was really intrigued to see that you are the software design and developer and writer of the manual. KUDOS. Thanks so much, once more. In german, I say, Danke Schön!
Re: Design Tab not displaying images [message #1220911 is a reply to message #1220897] Mon, 16 December 2013 05:56 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
WindowBuilder started out in the Smalltalk world back in the early '90's and eventually migrated to Java and Eclipse around 10 years ago. The Smalltalk version is still around though, and that PDF manual you found is 15+ years old at this point.
Re: Design Tab not displaying images [message #1225189 is a reply to message #1220911] Sun, 29 December 2013 01:56 Go to previous messageGo to next message
Peter Popoola is currently offline Peter PopoolaFriend
Messages: 8
Registered: November 2013
Junior Member
Hi, Eric. Just wanted to thank you for all your help. I have finally been able to resolve the issue. I created a jar file which includes all the resources I need, added it to the classpath, and then it appeared in the classpath option in eclipse as we earlier discussed. Muchisimas Gracias!

[Updated on: Sun, 29 December 2013 01:56]

Report message to a moderator

Re: Design Tab not displaying images [message #1225540 is a reply to message #1225189] Mon, 30 December 2013 04:57 Go to previous messageGo to next message
Peter Popoola is currently offline Peter PopoolaFriend
Messages: 8
Registered: November 2013
Junior Member
Hi, Eric. Sorry to bother you. I have another issue. I have a block of code I want have written, and I want the JFrame to repaint after a JToggle button is clicked. Howver, to my consternation, the JFrame refuses to repaint! I've been battling with this issue for a while. Pls what can I do? Here's the code:
This is where the JToggleButton is created
JToggleButton edit = new JToggleButton("Edit");
	auxButtonsLayout.setConstraints(edit, c);
	edit.addItemListener(this);
	auxButtonPanel.add(edit);

And this is the ItemStateChanged method:
@Override
public void itemStateChanged(ItemEvent e) {
	if (e.getStateChange() == ItemEvent.SELECTED){
		editEnabled = true;
	}else{
		editEnabled = false;
	}
	repaint();
}
Re: Design Tab not displaying images [message #1225669 is a reply to message #1225540] Mon, 30 December 2013 13:03 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
No idea. I don't use Swing and greatly prefer SWT for Java UIs.

Also, this forum is here to support using and extending WindowBuilder. General Swing / Java questions are better asked in one of the many Java groups out there.
Re: Design Tab not displaying images [message #1240741 is a reply to message #1225669] Fri, 07 February 2014 02:09 Go to previous message
Peter Popoola is currently offline Peter PopoolaFriend
Messages: 8
Registered: November 2013
Junior Member
Gracias!
Previous Topic:Installing Nebula widgets in palette manager
Next Topic:Jbuilder
Goto Forum:
  


Current Time: Thu Mar 28 11:20:16 GMT 2024

Powered by FUDForum. Page generated in 0.07755 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top