如何在jframe中的jpanel中设置单选按钮?

s98

单选按钮似乎没有正确组合在一起,因为其中一个稍微向左倾斜。我不确定错误是什么。代码中的所有内容对我来说似乎都很好...我不确定丢失了什么。我已在下面附上一张显示问题的图像。我正在使用的Ide是NetBeans。

谢谢高级!:)

烧烤稍微向左倾斜

 package pizzaorder2;

 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
 import java.awt.FlowLayout;
 import javax.swing.SwingUtilities;
 import javax.swing.JRadioButton;

public class PizzaOrder2 extends JFrame { 


public static void main(String[] args) {

  JFrame frame = new PizzaOrder2();


   JRadioButton tomato = new JRadioButton("Tomato");
   JRadioButton barbeque = new JRadioButton("Barbeque");  
   ButtonGroup group = new ButtonGroup();
   group.add(tomato);
   group.add(barbeque);
   JPanel radiopanel = new JPanel();
   radiopanel.add(tomato);
   radiopanel.add(barbeque);
   frame.getContentPane().add(radiopanel);
   radiopanel.setBounds(240,330,110,70);
   radiopanel.setOpaque(false);
   tomato.setForeground(Color.white);
   barbeque.setForeground(Color.white);


    frame.setLayout(null);
    frame.setSize(600, 700);
    frame.getContentPane().setBackground(new Color(40, 80, 120));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);


    }

   }
牛肉

尝试将无线面板调整为此:

JPanel radiopanel = new JPanel(new FlowLayout(FlowLayout.LEFT));

为了更好地说明,您只是在进行设置,使项目在左侧而不是在中心对齐(我相信这是默认设置)。您将需要为此导入FlowLayout。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章