gpt4 book ai didi

java - SetBounds 无法正常工作

转载 作者:行者123 更新时间:2023-12-01 22:36:31 26 4
gpt4 key购买 nike

我想制作 3 个面板,一个在西侧,一个在东侧,一个在南侧。当我执行此操作时,它会给我一个框架,其颜色全部在另一个之上,并且不会给我按钮。

frame = new JFrame();
frame.setBounds(600, 200, 500, 350);
frame.setTitle("Dr. Idrizovic");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

panelWest = new JPanel();
panelWest.setBounds(0, 0, 175, 310);
panelWest.setLayout(null);
panelWest.setBackground(Color.green);

regUslugaButt = new JButton("Registar usluga");
regUslugaButt.setBounds(12, 35, 150, 25);

regMaterijalaButt = new JButton("Registar materijala");
regMaterijalaButt.setBounds(12, 95, 150, 25);

regIntervencijaButt = new JButton("Registar intervencija");
regIntervencijaButt.setBounds(12, 155, 150, 25);

regDijagnozaButt = new JButton("Registar dijagnoza");
regDijagnozaButt.setBounds(12, 215, 150, 25);


panelEast = new JPanel();
panelEast.setBounds(325, 0, 175, 310);
panelEast.setLayout(null);
panelEast.setBackground(Color.red);

evidencijaPacButt = new JButton("Evidencija pacijenata");
evidencijaPacButt.setBounds(324, 35, 150, 25);

zakazivanjePacButt = new JButton("Zakazivanje pacijenata");
zakazivanjePacButt.setBounds(12, 95, 150, 25);

evidencijaStomatologaButt = new JButton("Evidencija stomatologa");
evidencijaStomatologaButt.setBounds(12, 155, 150, 25);

izvrseneUslugeButt = new JButton("Izvrsene usluge");
izvrseneUslugeButt.setBounds(12, 215, 150, 25);






panelSouth = new JPanel();
panelSouth.setBounds(175, 310, 150, 40);
panelSouth.setLayout(null);
panelSouth.setBackground(Color.black);

exitButt = new JButton("Kraj rada");
exitButt.setBounds(174, 260, 150, 25);






panelWest.add(regUslugaButt);
panelWest.add(regMaterijalaButt);
panelWest.add(regIntervencijaButt);
panelWest.add(regDijagnozaButt);

panelEast.add(evidencijaPacButt);
panelEast.add(zakazivanjePacButt);
panelEast.add(evidencijaStomatologaButt);
panelEast.add(izvrseneUslugeButt);

panelSouth.add(exitButt);

frame.add(panelWest);
frame.add(panelSouth);
frame.add(panelEast);

最佳答案

I want to make 3 panels where one is to the west side,one to the east and one to the south.

不要使用空布局。不要使用 setBounds()。

相反,您应该使用 BorderLayout为您提供主面板。您的子面板还应该使用适当的布局管理器。

关于java - SetBounds 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26784502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com