本文介绍了SetBounds无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想制作3个面板,其中一个在西侧,一个在东侧,一个在南侧.当我对此进行编译时,它给我提供了一个全都是另一种颜色的框架,并且没有给我按钮.
I want to make 3 panels, where one is to the west side, one to the east, and one to the south. When I complie this, it gives me frame with colors all one above another and it doesn't give me buttons.
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);
推荐答案
请勿使用空布局.不要使用setBounds().
Don't use a null layout. Don't use setBounds().
相反,您应该为自己使用 BorderLayout 控制板.您的子面板还应该使用适当的布局管理器.
Instead you should be using a BorderLayout for you main panel. Your child panels should also use an appropriate layout manager.
这篇关于SetBounds无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!