Design Tab not displaying images [message #1218829] |
Fri, 29 November 2013 13:03 |
Peter Popoola 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 #1219096 is a reply to message #1219071] |
Sun, 01 December 2013 20:08 |
Peter Popoola 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
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07755 seconds