2014-09-25 4 views
0

나는 자바로 UI를 만들려고 노력하고 있는데, 이것에 관해서는 매우 미안하다. 쉬운 질문이다. 여기 java gui setbounds doesnt work

public class viewDeneme extends JFrame { 

private static final long serialVersionUID = -7284396337557548747L; 
private JTextField nameTxt = new JTextField(10); 
private JTextField passwordTxt = new JTextField(10); 
private JButton loginBtn = new JButton("Giriş"); 
private JLabel nameLbl = new JLabel("Kullanıcı adi:"); 
private JLabel passwordLbl = new JLabel("Şifre:"); 

public viewDeneme(){ 
    JPanel loginPanel = new JPanel(); 
    this.setSize(600,200); 
    this.setLocation(600, 300); 
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    nameLbl.setBounds(200, 200, 100, 50); 

    loginPanel.add(nameTxt); 
    loginPanel.add(passwordTxt); 
    loginPanel.add(loginBtn); 
    loginPanel.add(nameLbl); 
    loginPanel.add(passwordLbl); 

    this.setVisible(true); 
    this.add(loginPanel); 
} 

public static void main(String[] args) { 
    new viewDeneme(); 

} 
} 

내 code.I 레이블 및 텍스트 상자에 대한 경계를 설정하기 위해 노력하고있다지만 뭐든 들어를 변경하지 않는 것은 내가 모르는 뭔가가 있어야하므로, 어떠한 오류가 아닙니다하지만 난 웹에서 검색으로 찾을 수 없습니다 당신의 도움에 대한 .Thanks는

답변

0

What is setBounds and how do I use it?

JPanel의 레이아웃은 절대 위치를 사용하는 null이어야합니다 참조하십시오. JPanel을 만들 때 다르게 지정하지 않으면 JPanel 객체가 FlowLayout을 사용하도록 초기화됩니다. 따라서 작성해야합니다.

loginPanel.setLayout(null);