本文介绍了我的布局代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,当我启动程序时,我的按钮变得混乱,并且整个屏幕上都出现了一个巨大的JButton.这是代码:
So, when I start my program, my buttons get mixed up and I get a huge JButton accross whole screen. Here is the code:
super ("Title"); okvir = new JFrame(); okvir.setSize(1350, 768); okvir.setLocation (0, 0); okvir.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); okvir.setVisible(true); sab = new JButton("sabiranje"); sab.setBounds (20 , 20 , 50 , 20); okvir.add(sab); od = new JButton ("oduzimanje"); od.setBounds (20 , 40 , 50 , 20); okvir.add(od); rez = new JLabel ("rezultat"); rez.setBounds (20 , 60 , 50 , 20); okvir.add(rez); x = new JTextField ("",4); x.setBounds (20 , 80 , 50 , 20); okvir.add(x); y = new JTextField("",4); y.setBounds (20 , 100 , 50 , 20); okvir.add(y); mnoz = new JButton("mnozenje"); mnoz.setBounds (20 , 120 , 50 , 20); okvir.add(mnoz); delj = new JButton ("deljenje"); delj.setBounds (20 , 140 , 50 , 20); okvir.add(delj);推荐答案
您将所有按钮放置在框架的BorderLayout.CENTER位置,这不仅考虑了其子组件的引用大小,而且还替换了每个后续按钮.创建一个新面板来容纳按钮.
You're placing all the buttons in the BorderLayout.CENTER position of the frame which not only respect referred sizes of its child components but replaces each subsequent button. Create a new panel to accomodate the buttons.
由于您使用布局管理器,因此调用setBounds无效,因此可以删除这些语句
Calling setBounds will have no effect since youre using a layout manager so these statements can be deleted
更多推荐
我的布局代码有什么问题?
发布评论