Jump to content

How do I add buttons inside a background

Recommended Posts

Please see the code, background image, and the buttons which are currently outside the background image. I would like to find out how to add the buttons inside the the background. tools used: notepadd++ and command prompt. Thanks


Link to post
Share on other sites
  • 2 weeks later...

Maybe u fixed it already :) import javax.swing.JFrame;import javax.swing.ImageIcon;import javax.swing.JLabel;import java.awt.Container;import javax.swing.JTextField;import javax.swing.JButton;import java.awt.FlowLayout; class ShowPicture{public static void main(String args[]) {JFrame frame;Container contentPane;JTextField textfield;JButton button;FlowLayout layout;String sorry; frame = new JFrame();frame.setTitle("Coffee Table"); ImageIcon icon = new ImageIcon("background.png");JLabel label = new JLabel(icon); /****************************/frame.setContentPane(label);contentPane = frame.getContentPane();/****************************/ textfield = new JTextField("Type your text here.");sorry = "This button is temporarily out of order.";button = new JButton(sorry); contentPane.add(textfield);contentPane.add(button);layout = new FlowLayout();contentPane.setLayout(layout); /****************************///contentPane.add(label);/****************************/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.pack();frame.setVisible(true);}}

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...