java 有没有类似VB.net 的那个 GroupBox 控件
3个回答
2013-09-25
展开全部
import java.awt.Checkbox;
import java.awt.GridLayout;
import java.awt.TextArea;import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class MyFrame extends JFrame {
public MyFrame(String title){
super(title);
this.setSize(400, 300);
this.setLayout(new GridLayout(1,2));
this.addComponent();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
private void addComponent()
{
JPanel leftPanel=new JPanel();
TextArea ta=new TextArea(null,15,24,TextArea.SCROLLBARS_NONE);
leftPanel.add(ta);
JPanel rightPanel=new JPanel();
rightPanel.setLayout(new GridLayout(2,1));
JPanel subPanel1=new JPanel();
subPanel1.setLayout(new GridLayout(2,1));
subPanel1.setBorder(BorderFactory.createTitledBorder("先取文字后再使用如下功能"));
subPanel1.add(new Checkbox("粗体",false));
subPanel1.add(new Checkbox("蓝色字体",false));
JPanel subPanel2=new JPanel();
subPanel2.setBorder(BorderFactory.createTitledBorder("背景颜色"));
subPanel2.setLayout(new GridLayout(2,1));
JRadioButton btn1=new JRadioButton("白色");
JRadioButton btn2=new JRadioButton("兰色");
ButtonGroup bg=new ButtonGroup();
bg.add(btn1);
bg.add(btn2);
subPanel2.add(btn1);
subPanel2.add(btn2);
rightPanel.add(subPanel1);
rightPanel.add(subPanel2);
this.add(leftPanel);
this.add(rightPanel);
}
public static void main(String[] args) {
new MyFrame("测试");
}
}
import java.awt.GridLayout;
import java.awt.TextArea;import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class MyFrame extends JFrame {
public MyFrame(String title){
super(title);
this.setSize(400, 300);
this.setLayout(new GridLayout(1,2));
this.addComponent();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
private void addComponent()
{
JPanel leftPanel=new JPanel();
TextArea ta=new TextArea(null,15,24,TextArea.SCROLLBARS_NONE);
leftPanel.add(ta);
JPanel rightPanel=new JPanel();
rightPanel.setLayout(new GridLayout(2,1));
JPanel subPanel1=new JPanel();
subPanel1.setLayout(new GridLayout(2,1));
subPanel1.setBorder(BorderFactory.createTitledBorder("先取文字后再使用如下功能"));
subPanel1.add(new Checkbox("粗体",false));
subPanel1.add(new Checkbox("蓝色字体",false));
JPanel subPanel2=new JPanel();
subPanel2.setBorder(BorderFactory.createTitledBorder("背景颜色"));
subPanel2.setLayout(new GridLayout(2,1));
JRadioButton btn1=new JRadioButton("白色");
JRadioButton btn2=new JRadioButton("兰色");
ButtonGroup bg=new ButtonGroup();
bg.add(btn1);
bg.add(btn2);
subPanel2.add(btn1);
subPanel2.add(btn2);
rightPanel.add(subPanel1);
rightPanel.add(subPanel2);
this.add(leftPanel);
this.add(rightPanel);
}
public static void main(String[] args) {
new MyFrame("测试");
}
}
2013-09-25
展开全部
有啊!!!!ButtonGroup和JRadioButton
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-25
展开全部
自己用swing实现。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询