Question

Iam trying to position my jlabel in a jpanel what is made final because of an actionlistener.

final JPanel panelPayDetails = new JPanel();
panelPayDetails.setBounds(250, 25, 350, 250);

JLabel lblnumber = new JLabel("Insert Number:");         
lblnumber.setFont(Applicatie.FONT_12_BOLD);
lblnumber.setBounds(5, 5, 200, 20);

panelPayDetails.add(lblnumber);
panelPayDetails.setVisible(false);
jpExtraDetails.add(panelPayDetails);

bill.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e)
            {                
              if(bill.getSelectedItem() == "CREDIT CARD")
              {

                   panelPayDetails.setVisible(true);
              }
            }
        });    

im not luck so far.. because the label is positioned in the middle of the jpanel.. how come?

Was it helpful?

Solution

Because the default layout manager for JPanel is FlowLayout, which centers things. Read this tutorial.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top