這裏是我的Java代碼:我的JTextField不會出現
JLabel persAdi,persSoyadi,persKodu,ust,alt;
JTextField ad,soyad,tckimlikno;
JButton bul,iptal;
public persBul(){
setSize (400,600);
setResizable(false);
setLocation (20, 20);
setVisible(true);
Container icerik = getContentPane();
icerik.setLayout(null);
icerik.getX();
ust=new JLabel("Bulmak İstediğiniz Personelin;");
ust.setBounds(10, 10, 200, 30);
icerik.add(ust);
persAdi=new JLabel("Adı:");
persAdi.setBounds(10,40,80,15);
icerik.add(persAdi);
ad=new JTextField();
ad.setBounds(50, 40, 80, 20);
icerik.add(ad);
persSoyadi=new JLabel("Soyadı:");
persSoyadi.setBounds(10, 180, 80, 30);
icerik.add(persSoyadi);
soyad=new JTextField();
soyad.setBounds(200, 40, 100, 30);
Icon bulPng=new ImageIcon(getClass().getResource("search.png"));
Icon iptalPng=new ImageIcon(getClass().getResource("cancel.png"));
bul=new JButton("",bulPng);
bul.setBounds(20, 120, 40, 40);
icerik.add(bul);
iptal=new JButton("",iptalPng);
iptal.setBounds(90, 120, 40, 40);
icerik.add(iptal);
}
public static void main(String[] args){
persBul app=new persBul();
}
當我調試代碼,我JTextField
不會出現。只有第一個JLabel
可以出現,我沒有看到任何其他JLabel
或JTextField
或JButton
。當我的光標在上面時,我的按鈕就會出現。我必須做這個項目,但我還沒有創建用戶界面。有誰能夠幫助我?
否認:icerik。的getX(); – umitkilic
我建議您閱讀['Layout' managers](http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html),而不是使用'null'佈局。雖然你在那,仔細閱讀[使用多個JFrames,良好的壞做法](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice/9554657 #9554657)especialy:['CardLayout'](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html)。 – Frakcool
Java GUI可能需要在多種平臺上工作,使用不同的屏幕分辨率並使用不同的PLAF。因此,它們不利於組件的準確放置。爲了組織強大的GUI,請改爲[使用佈局管理器](http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html)或[它們的組合](http:// stackoverflow.com/a/5630271/418556),以及[white space]的佈局填充和邊框(http://stackoverflow.com/q/17874717/418556)。 –