Eclipse bug不尊重GUI设定的界限

发布于 2025-02-01 19:23:53 字数 990 浏览 3 评论 0原文

因此,我一直在为学校项目开发这个应用程序的小问题,我相信我的日食已经被漏出了,每当我设置了GUI上的界限时,都会不尊重他们并且始终将我在GUI左侧的中间附近实施的任何内容都放置,如果我实现更多的东西,尽管我设定了什么范围,但它只会将其移至一个随机的位置。

我真的不知道如何解决此问题,我尝试删除课程并再次编写代码,但仍然发生了,我在Google上搜索了任何修复程序,但似乎找不到任何有这个问题的人,对此问题的任何帮助或见解将不胜感激。

问题

JFrame frame = new JFrame();

JLabel ArmaLabel = new JLabel();
JLabel BarC = new JLabel();
JLabel teste = new JLabel("teste");

ArmaP() {

    BarC.setBounds(100,100,100,30);
    BarC.setText("teste12");

    teste.setBounds(400,300,20,20);

    ArmaLabel.setBounds(325,20,200,35);
    ArmaLabel.setText("Armazenamento");
    ArmaLabel.setFont(new Font(null,Font.ROMAN_BASELINE,25));

    frame.add(ArmaLabel);
    frame.add(BarC);
    frame.add(teste);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,600);
    frame.setVisible(true);
    frame.setLayout(null);
    frame.setResizable(false);
}
}

So I've been having this little issue with this app that I'm developing for a school project and I believe my eclipse has bugged out, what happens is, whenever I set the bounds to something on the GUI it doesn't respect them and always puts whatever I implement on near the middle to the left of the GUI, if I implement more stuff it just moves it to a random place despite what bounds I set it to.

I don't really know how to fix this and I've tried deleting the class and writing the code all over again but it still happens, I've searched on google for any fixes but can't seem to find anyone with this problem, any help or insight into this issue would be much appreciated.

The issue

JFrame frame = new JFrame();

JLabel ArmaLabel = new JLabel();
JLabel BarC = new JLabel();
JLabel teste = new JLabel("teste");

ArmaP() {

    BarC.setBounds(100,100,100,30);
    BarC.setText("teste12");

    teste.setBounds(400,300,20,20);

    ArmaLabel.setBounds(325,20,200,35);
    ArmaLabel.setText("Armazenamento");
    ArmaLabel.setFont(new Font(null,Font.ROMAN_BASELINE,25));

    frame.add(ArmaLabel);
    frame.add(BarC);
    frame.add(teste);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,600);
    frame.setVisible(true);
    frame.setLayout(null);
    frame.setResizable(false);
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一瞬间的火花 2025-02-08 19:23:53

不确定这是否有帮助,但是在Java秋千的扩展中,可以在不编码的情况下进行更改的窗口,首先要定义的是您想要的布局类型,有时在创建新项目时他的默认情况更改。
我认为,如果是通过编码,那将是这样的部分:

frame.getContentpane()。setLayout( null );

根据您在“无效”中放入的内容,它可以使您的setbound再次工作,但是我不确定是否仅是扩展的东西。

如果它是通过扩展,则在布局部分:

(绝对布局)让您自由选择要放置对象的位置

Not sure if this help but in the extension of Java Swing that gives a window to change without coding, one of the first things to define is the type of layout you want, and sometimes his default changes when you create a new project.
I think, if it was through coding it will be this part:

frame.getContentPane().setLayout(null);

Depending of what you put in that "null" it can make your setBounds working again, but I dont sure if is that something only from the extension..

And if it is through the extension, is in the Layout section:

(Absolute layout) let you choose freely where you want to place the objects

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文