I was making a tool in which i had to put an image as the background image and over it put some JTextField. i have made this code: Code: package firstTry; import java.awt.*; import javax.swing.*; public class Second extends JFrame { public JPanel mainpanel = new JPanel(); JLabel mainhead = new JLabel("Population Forecast Tool"); ImageIcon back = new ImageIcon("year2.jpg"); public JLabel backLabel = new JLabel(back); public Second() { mainpanel.setLayout(null); mainhead.setFont(new Font("Arial", 1, 20)); mainhead.setBounds(240,10,300,30); backLabel.setBounds(40,45, 627, 364); mainpanel.add(mainhead); mainpanel.add(backLabel); add(mainpanel); SecondComp obj = new SecondComp(mainpanel); } public static void main(String[] args) { Second obj = new Second(); obj.setSize(800,550); obj.setVisible(true); obj.setDefaultCloseOperation(EXIT_ON_CLOSE); obj.setResizable(false); obj.setTitle("Population Predictor"); } } the JTextField are added in the SecondComp class which is: Code: package firstTry; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JPanel; import javax.swing.JTextField; public class SecondComp { JTextField firstTf = new JTextField(102); JTextField secondTf = new JTextField(102); JTextField thirdTf = new JTextField(102); JTextField fourthTf = new JTextField(102); JTextField fifthTf = new JTextField(102); public SecondComp(JPanel mainpanel) { firstTf.setBounds(148,107,102,33); secondTf.setBounds(148,142,102,33); thirdTf.setBounds(148,177,102,33); fourthTf.setBounds(148,212,102,33); fifthTf.setBounds(148,247,102,33); firstTf.setHorizontalAlignment(JTextField.CENTER); firstTf.setBorder(BorderFactory.createLineBorder(Color.black)); secondTf.setHorizontalAlignment(JTextField.CENTER); secondTf.setBorder(BorderFactory.createLineBorder(Color.black)); thirdTf.setHorizontalAlignment(JTextField.CENTER); thirdTf.setBorder(BorderFactory.createLineBorder(Color.black)); fourthTf.setHorizontalAlignment(JTextField.CENTER); fourthTf.setBorder(BorderFactory.createLineBorder(Color.black)); fifthTf.setHorizontalAlignment(JTextField.CENTER); fifthTf.setBorder(BorderFactory.createLineBorder(Color.black)); thirdTf.setEnabled(true); mainpanel.add(firstTf); mainpanel.add(secondTf); mainpanel.add(thirdTf); mainpanel.add(fourthTf); mainpanel.add(fifthTf); } } The problem is that when the image is in the background the JTextField donot appear properly. I have to press TAB key in order to enable them. You can see i had tried "thirdTf.setEnabled(true);" but it also didnt work. PLEASE SEE THE IMAGES TO UNDERSTAND
Code: ..... backLabel.setBounds(40,45, 627, 364); backLabel.setOpaque(false);//try inserting this line of code here mainpanel.add(mainhead); ......
maybe this? Code: ...... backLabel.setBounds(40,45, 627, 364); mainpanel.add(backLabel); mainpanel.add(mainhead); add(mainpanel); SecondComp obj = new SecondComp(mainpanel); .......