내 JMenuBar menuBar
이 표시되지 않는 이유는 누구입니까? JFrame
및 JPanel
을 사용하고 있습니다.JMenuBar가 표시되지 않습니다
내 클래스는 JPanel
으로 확장되고 paint
메서드는 상속되며 (이미 super.paint(g)
) 상속됩니다.
나는 몇 가지 JLabels
및 JTextFields
을 표시 할 내 JMenuBar
내 코드입니다 (I가 그것의 목적이 아니다 알고) :
public void createMenuBar(){
menuBar = new JMenuBar();
menuBar.setBounds(0,0,1463,29);
menuBar.setLayout(null);
this.add(menuBar);
ipLbl = new JLabel("IP-Adresse:");
ipLbl.setBounds(5,2,150,25);
ipLbl.setLabelFor(ip);
menuBar.add(ipLbl);
ip = new JTextField();
ip.setBounds(150,2,100,25);
menuBar.add(ip);
}
내가 JFrame의를 만든 후이 메서드를 호출하고있어 ,하지만 바로 전에 setVisible(true)
.
봐 :
public IceHockey(){
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e){}
fenster = new JFrame("IceHockey");
fenster.setSize(1479, 941);
fenster.setLayout(null);
fenster.addKeyListener(this);
fenster.addMouseListener(this);
fenster.setResizable(false);
fenster.setLocationRelativeTo(null);
fenster.setContentPane(this);
this.addKeyListener(this);
this.addMouseListener(this);
createMenuBar();
fenster.setVisible(true);
fenster.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
** 돈을 ' 널 레이아웃을 사용하십시오 !!! **. 이것은 이전 게시물 중 하나에서 이미 제안되었습니다 : http://stackoverflow.com/questions/36751366/some-swing-components-not-showing-on-jframe. 제안에주의하십시오. 우리는 이유가있어서 그것들을줍니다. 작동 예제는 [메뉴 사용 방법] (http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html)의 스윙 튜토리얼을 참조하십시오. 이 코드는 수업을 더 잘 구조화하는 방법을 보여줍니다. – camickr
camickr 알아요.하지만이 프로그램은 저만을위한 것이며 학교의 선생님조차도 우리에게 null 레이아웃을 사용할 수 있다고 말했습니다. 그래서 내가 사용하는 것은 나에게 달려있다! 게다가 null 레이아웃은 사용하기 쉽다. –
'게다가 null 레이아웃은 사용하기 쉽습니다. '- 아니야. 구성 요소가 얼마나 크게 표시되어야하는지 전혀 알 수 없습니다. 난수를 하드 코드하는 것은 시간 낭비이며, 특히 변경이 필요할 때만 문제가 발생할 것입니다. 글꼴을 변경하는 것과 같은 간단한 작업은 문제를 일으킬 수 있습니다. 네가 할 수 있다고해서 네가해야한다는 뜻은 아니다. Swing을 올바르게 사용하는 법을 배웁니다! Swing 기본 사항을 아직 배웠지 않거나 (또는이 질문을하지 않아도 될 수 있으므로) 무엇이 쉽거나 쉬운 지 전혀 모릅니다. 그것은 단지 경험에서 오는 것입니다. – camickr