Home » Eclipse Projects » Eclipse Platform » How to set background image of a JFrame in Spring Designer/Application Window with eclipse
How to set background image of a JFrame in Spring Designer/Application Window with eclipse [message #1831123] |
Wed, 12 August 2020 00:36 |
Eric Zuo Messages: 14 Registered: October 2014 |
Junior Member |
|
|
Dear experts,
I have a class, type: WindowBuilder/Spring Designer/Application Window.
I need a background image, and based on this image, I will add a lot of buttons, text fields. My code to set background image is:
frame.setBackground(Color.WHITE);
frame.setBounds(1, 1, 788, 655);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null); //have to use absolute layout.
JPanel contentPane = new JPanel() {
public void paintComponent(Graphics g) {
URL url = null;
try {
url = new URL("http://localhost:8080/hayward_shop.png");
Image img = Toolkit.getDefaultToolkit().getImage( url);
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
} catch(Exception e) {
System.out.println(e.toString());
}
}
};
contentPane.setBorder(new EmptyBorder(1, 1, 1, 1));
contentPane.setBounds(1, 1, 788, 655);
frame.setContentPane(contentPane);
contentPane.setLayout(null);
When I run the class (run as Java Application in Eclipse), I can see the image, and buttons I added . but in code design mode, I cannot see this background image. Please tech me how to make it visible in design mode.
Thank you in advance.
Eric
[Updated on: Wed, 12 August 2020 15:59] Report message to a moderator
|
|
| | |
Goto Forum:
Current Time: Wed Sep 18 04:00:23 GMT 2024
Powered by FUDForum. Page generated in 0.03189 seconds
|