在java中实现给checkbox加个带标题的边框
我想给两部分分别加上带标题的边框如:JPanelp=newJPanel();TitledBordertb=BorderFactory.createTitledBorder...
我想给两部分分别加上带标题的边框 如:
JPanel p = new JPanel();
TitledBorder tb = BorderFactory.createTitledBorder ("Dialog type");
tb.setTitleJustification (TitledBorder.TOP);
p.setBorder (tb);
我想将边框加到一个JPanel中然后跟checkbox组合起来 但是弄了半天不知如何实现 求帮助!!
代码如下:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class checkbox extends Frame{
static Frame frm =new Frame("Checkbox Demo!");
static Checkbox chb1=new Checkbox("1111",false);
static Checkbox chb2=new Checkbox("2222",true);
static Checkbox chb3=new Checkbox("3333");
static Checkbox chb4=new Checkbox("4444");
public static void main(String args[]){
CheckboxGroup grp=new CheckboxGroup();
frm.setSize(300,200);
frm.setLayout(null);
frm.setBackground(Color.white);
chb1.setBounds(20,40,140,20);
chb2.setBounds(20,60,140,20);
chb3.setBounds(20,100,140,20);
chb4.setBounds(20,120,140,20);
chb3.setCheckboxGroup(grp);
chb4.setCheckboxGroup(grp);
chb3.setState(true);
frm.add(chb1);
frm.add(chb2);
frm.add(chb3);
frm.add(chb4);
frm.setVisible(true);
frm.addWindowListener(new WindowAdapter(){
public void windowClosing( WindowEvent e ){
System.exit(0);
}
});
}
} 展开
JPanel p = new JPanel();
TitledBorder tb = BorderFactory.createTitledBorder ("Dialog type");
tb.setTitleJustification (TitledBorder.TOP);
p.setBorder (tb);
我想将边框加到一个JPanel中然后跟checkbox组合起来 但是弄了半天不知如何实现 求帮助!!
代码如下:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class checkbox extends Frame{
static Frame frm =new Frame("Checkbox Demo!");
static Checkbox chb1=new Checkbox("1111",false);
static Checkbox chb2=new Checkbox("2222",true);
static Checkbox chb3=new Checkbox("3333");
static Checkbox chb4=new Checkbox("4444");
public static void main(String args[]){
CheckboxGroup grp=new CheckboxGroup();
frm.setSize(300,200);
frm.setLayout(null);
frm.setBackground(Color.white);
chb1.setBounds(20,40,140,20);
chb2.setBounds(20,60,140,20);
chb3.setBounds(20,100,140,20);
chb4.setBounds(20,120,140,20);
chb3.setCheckboxGroup(grp);
chb4.setCheckboxGroup(grp);
chb3.setState(true);
frm.add(chb1);
frm.add(chb2);
frm.add(chb3);
frm.add(chb4);
frm.setVisible(true);
frm.addWindowListener(new WindowAdapter(){
public void windowClosing( WindowEvent e ){
System.exit(0);
}
});
}
} 展开
1个回答
展开全部
JCheckBox checkBox = new JCheckBox("123");
checkBox.setBorderPainted(true);
checkBox.setBorder(new TitledBorder(null, "title", TitledBorder.LEADING, TitledBorder.TOP, null, null));
contentPane.add(checkBox, BorderLayout.CENTER);
checkBox.setBorderPainted(true);
checkBox.setBorder(new TitledBorder(null, "title", TitledBorder.LEADING, TitledBorder.TOP, null, null));
contentPane.add(checkBox, BorderLayout.CENTER);
追答
哦。把想放在一个title框里面的东西加到一个panel里面,
给这个panel加标题边框就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询