我试图定位我的jlabel在jpanel什么是最终的,因为一个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);
}
}
});
到目前为止我运气不太好。因为标签位于jpanel的中间。怎么会? 因为JPanel的默认布局管理器是FlowLayout,它将东西居中。阅读本教程