j2se的几种常用组件例子
2015-03-03 15:58
176 查看
public class my_element extends JFrame{ //JFrame可用的界面组件 JPanel jp1 = new JPanel(); //panel JPanel jp2 = new JPanel(); JButton jb = new JButton("按钮"); //JButton jb = new JButton(new ImageIcon("图片地址"));按钮为这个图片 //jb.setToolTipText("鼠标放在按钮上时的tip提示内容"); JLabel jlab = new JLabel("标签"); JTextField jtext = new JTextField(10); //数字为长度 JPasswordField jpass = new JPasswordField(10); //复选框 JCheckBox jcheck1 = new JCheckBox("复选框1"); JCheckBox jcheck2 = new JCheckBox("复选框2"); JCheckBox jcheck3 = new JCheckBox("复选框3"); //单选按钮 JRadioButton jradio1 = new JRadioButton("单选框1"); JRadioButton jradio2 = new JRadioButton("单选框2"); JRadioButton jradio3 = new JRadioButton("单选框3"); //下拉框 String[] com = {"北京","天津","火星"}; JComboBox jbox = new JComboBox(com); //列表 String[] list = {"北京","天津","火星"}; JList jlist = new JList(list); //滚动面板 JScrollPane jsp = new JScrollPane(jlist); public static void main(String[] args) { // TODO Auto-generated method stub my_element me = new my_element(); } // 构造函数 public my_element(){ //设置布局管理 this.setLayout(new GridLayout(3,1)); //加入组件 jp1.add(jlab); jp1.add(jtext); jp1.add(jpass); jp1.add(jb); jp1.add(jcheck1); jp1.add(jcheck2); jp1.add(jcheck3); jp1.add(jradio1); jp1.add(jradio2); //创建buttongroup ButtonGroup group = new ButtonGroup(); //单选框需要先创建buttongroup group.add(jradio1); group.add(jradio2); group.add(jradio3); jp1.add(jradio1); jp1.add(jradio2); jp1.add(jradio3); jp2.add(jbox); //设置list最大显示数 jlist.setVisibleRowCount(2); jp2.add(jsp); //把panel放入JFrame this.add(jp1); this.add(jp2); //给窗体设置标题 this.setTitle("控件组合"); //设置大小 this.setSize(640, 240); //设置初始位置 this.setLocation(100, 200); //设置当关闭窗口时jvm也退出。 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //显示 this.setVisible(true); }
相关文章推荐
- android常用组件属性-- Gridview属性详解及例子[搜索集合]
- 常用的几种文本组件(JTextComponent)
- ExtJs 一些常用啊例子如界面布局,组件的使用等之类的
- Android Layout布局使用总结Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件。 帧布局(FrameLayout):组件从
- Vue 组件传值几种常用方法【总结】
- 几种常用的swing组件------文本框/密码框/标签 ----------复选框和/单选框 -----下拉框/列表框/滚动窗格组件
- 常用的几种OCR方法/组件小结(C#)
- Scikit-learn提供的例子介绍几种常用的特征选择
- 微信小程序例子——使用icon组件显示常用图标
- 几种Android布局layout组件主要常用属性
- android几种布局组件的常用属性
- 几种常用的像素混合方法
- js 几种常用的表单输入判断
- js 几种常用的表单输入判断
- [总结]发送邮件共有几种方法,测试成功的例子
- 组件的几种方法VC中使用COM
- 正则表达式几种常用功能——查询,提取,替换,分割
- 常用Email组件发送函数
- 将Java对象转为String的几种常用方法剖析
- 目前在Java中几种常用的XML解析器的比较