Hello
I want to create a JPanel with a background image, and on that background image I want to arrange my buttons and text feilds etc in a border layout. Is this possibe? Having real trouble accomplishing this. Any assistence will be appreciated. I am using Java 2 at the moment. Thanks in advance
Code:import java.awt.event.*; import javax.swing.*; import java.awt.*; import java.awt.BorderLayout; public class GUI2 extends JFrame { ImageIcon icon; Image image; public GUI2() { icon = new ImageIcon("background.jpg"); JPanel panel = new JPanel() { protected void paintComponent(Graphics g) { // Dispaly image at full size g.drawImage(icon.getImage(), 0, 0, null); super.paintComponent(g); } }; panel.setOpaque( false ); panel.setPreferredSize( new Dimension(400, 400) ); getContentPane().add( panel ); panel.setLayout(new BorderLayout()); JPanel southPanel = new JPanel(); JButton button = new JButton( "Hello" ); southPanel.setOpaque(true); button.setOpaque(true); southPanel.add(button); add(southPanel, BorderLayout.NORTH); // southPanel.add(button); // southPanel.add(b); } public static void main(String [] args) { GUI2 frame = new GUI2(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(450, 250); frame.setLocationRelativeTo( null ); frame.setVisible(true); } }




Reply With Quote