我的布局代码有什么问题?

编程入门 行业动态 更新时间:2024-10-24 22:28:46
本文介绍了我的布局代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

因此,当我启动程序时,我的按钮变得混乱,并且整个屏幕上都出现了一个巨大的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

更多推荐

我的布局代码有什么问题?

本文发布于:2023-10-22 23:04:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1518997.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   布局   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!