mercredi 4 mars 2015

How to put a JButton at a specific location?



I know that there are already very similar questions to my question on stackoverflow, but neither one of them answers my question. I want to put my JButton on a specific location on my JFrame in JAVA. Here is my Code:



public class DetectMotion extends JFrame {

private JLabel label = null;

public DetectMotionExample() {

JPanel pnlButton = new JPanel();
label = new JLabel(nothing);
JButton btn = new JButton("Close");

pnlButton.setLayout(new BorderLayout());

setTitle("Motion Detector");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());

btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Close")) {
//TO-DO
}
}
});

WebcamPanel panel = new WebcamPanel(webcam);

add(panel);
pnlButton.add(btn,BorderLayout.SOUTH);
pnlButton.add(label,BorderLayout.NORTH);
add(pnlButton);

pack();
setVisible(true);
}

}


I have a panel on my JFrame (webcamPanel) and a JPanel called pnlButton that includes the JButton (btn) and JLabel (label).


Now, how can I specifically change the location of my button instead of just using BorderLayout.NORTH?


Thanks!




Aucun commentaire:

Enregistrer un commentaire