gpt4 book ai didi

java - 设置包含 JRadioButton 的 JPanel 的大小

转载 作者:行者123 更新时间:2023-11-30 03:53:21 25 4
gpt4 key购买 nike

我有一些问题,我希望我的 jpanel 看起来像这样 enter image description here但在编码之后我有这个观点,但我没有找到解决方案, enter image description here我需要一些帮助。

我把单选按钮放在jScrollPan里面//listmateriel是单选按钮的列表( vector )----------//imagebox是jpanel,包含jradio按钮和图像---------

//gridlayoutPanel2是Jpanel,包含两个文本字段和jlabel以及一个JComboBox

package tpjava;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Image;
import java.awt.event.ActionEvent;
i.......


public class Frame extends JFrame implements ActionListener {
private static final int Haut = 550;
private static final int Larg = 720;
private final JPanel utilisateur;
private final JButton recherche;
private final JRadioButton radioButton,radioButton2;
private Vector listmateriel;
private final JLabel label;

public Frame()
{
super("Gestion des materiels");
setSize(Larg,Haut);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTabbedPane menu = new JTabbedPane();








JPanel emprunt = new JPanel();
emprunt.setPreferredSize(new Dimension(Larg, Haut ));
emprunt.setLayout(new BoxLayout(emprunt, BoxLayout.Y_AXIS));
emprunt.setBorder(BorderFactory.createEmptyBorder(20,20, 20, 20));


JPanel emp1 = new JPanel();
emp1.setPreferredSize(new Dimension(Larg-40, 200 ));
emp1.setLayout(new BorderLayout());


JLabel title2 = new JLabel("Nouvel emprunt:");
title2.setBorder(BorderFactory.createEmptyBorder(20,20,0,0));


JPanel box2 = new JPanel();
box2.setPreferredSize(new Dimension(Larg, 40 ));
box2.setLayout(new BoxLayout(box2, BoxLayout.X_AXIS));
box2.add(title2);
box2.add(Box.createHorizontalStrut(650));
emprunt.add(box2);



JLabel label3 = new JLabel("test");
JButton dispo = new JButton("Disponibilité");
dispo.addActionListener((ActionListener) this);
dispo.setPreferredSize(new Dimension(200, 30));

JPanel box1 = new JPanel();
box1.setLayout(new BoxLayout(box1, BoxLayout.X_AXIS));
box1.add(dispo);
box1.add(Box.createHorizontalStrut(450));
box1.add(label3);
emp1.add(box1,BorderLayout.SOUTH);




listmateriel = new Vector();
for(int k =0 ;k <10 ; k++)
listmateriel .add(new JRadioButton(res.getString("nom"+k)));


......

ImageIcon newIcon = new ImageIcon(bi);
JLabel picture = new JLabel(newIcon);
picture.setBorder(BorderFactory.createEmptyBorder(0,450,0,0));


JPanel jplRadio = new JPanel();
jplRadio.setLayout(new GridLayout(0, 1));

for(int i = 0 ; i < listmateriel.size() ;i++)
{
jplRadio.add((Component) listmateriel.elementAt(i));

}



JPanel imagebox = new JPanel();
imagebox.setLayout(new BorderLayout());
JScrollPane scroll3 = new JScrollPane(jplRadio);
scroll3.setPreferredSize(new Dimension(200, 30));

imagebox.add(scroll3, BorderLayout.WEST);
imagebox.add(picture, BorderLayout.CENTER);
emp1.add(imagebox,BorderLayout.CENTER);

JPanel box3 = new JPanel();
box3.setLayout(new BoxLayout(box3, BoxLayout.X_AXIS));
JLabel title3 = new JLabel("Remplir les champs suivants:");
box3.add(title3);
box3.add(Box.createHorizontalStrut(650));



JPanel gridlayoutPanel2 = new JPanel();

........

JPanel util5 = new JPanel();
util5.setLayout(new GridLayout(0,1));
util5.setBorder(BorderFactory.createLineBorder(Color.black));

JLabel resul2 = new JLabel("bsfgbsdg");
JScrollPane scroll2 = new JScrollPane();

util5.add(resul2);

emprunt.add(emp1);
emprunt.add(box3);
emprunt.add(gridlayoutPanel2);
emprunt.add(util5);


menu.add("emprunts",emprunt);

//---------------------
getContentPane().add(menu);
pack();
setVisible(true);

}


}

最佳答案

GridLayout(0, 1) 而不是 BoxLayout 是解决方案,谢谢@trashgod

关于java - 设置包含 JRadioButton 的 JPanel 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23838828/

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