#GUI how to put jlabel image behind the buttons

4 messages · Page 1 of 1 (latest)

raw halo
#

I want to make the buttons appear in front of the image I put using a jlabel but i can't seem to find how to do it 😦
current code shortened:
'''
private void initialize() {

    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JPanel panel = new JPanel();
    frame.getContentPane().add(panel, BorderLayout.CENTER);
    
    JButton btnNewButton = new JButton("LOUER");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getSource()==btnNewButton) {
            LOUER myWindow = new LOUER();
            frame.dispose();    
            }                
        }
    });
    
    JPanel bgPanel = new JPanel() {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            ImageIcon img = new ImageIcon(getClass().getResource("/louscoot_MainFrame_BG.png"));
            g.drawImage(img.getImage(), 0, 0, getWidth(), getHeight(), null);
        }
    };

    frame.setContentPane(bgPanel);
    frame.setLayout(new BorderLayout());

    JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 10, 10));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

}

}
'''

upper thunderBOT
#

This post has been reserved for your question.

Hey @raw halo! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

versed pendant