java图形用户界面,本人代码效果如下,但是行间距有点大,按钮之类的组件过大,怎么解决?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java图形用户界面,本人代码效果如下,但是行间距有点大,按钮之类的组件过大,怎么解决?相关的知识,希望对你有一定的参考价值。
class Frame1 extends JFrame implements ActionListener
JTextField text_name;
String[] JComboBoxItem="JComboBoxItem";
JComboBox aJComboBox;
JRadioButton aJRadioButton[];
JCheckBox aJCheckBox[];
JTextArea aTextArea;
JList aJList;
JSpinner aJSpinner;
JButton aJButton;
public Frame1()
super("javax.swing包中基本组件的形状");
this.setBounds(100,100,500,600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(new GridLayout(5,1));
//第一行
JPanel jpanel1=new JPanel();
jpanel1.setLayout(new GridLayout(1,3));
jpanel1.add(new JLabel("JLabel:",SwingConstants.RIGHT));
text_name=new JTextField(5);
jpanel1.add(text_name);
aJComboBox=new JComboBox(JComboBoxItem);
jpanel1.add(aJComboBox);
this.add(jpanel1);
//第二行
JPanel jpanel2=new JPanel();
jpanel2.setLayout(new GridLayout(1,3));
jpanel2.add(new JLabel("JCheckBox:",SwingConstants.RIGHT));
aJCheckBox=new JCheckBox[2];
aJCheckBox[0]=new JCheckBox("JCheckBox1");
aJCheckBox[1]=new JCheckBox("JCheckBox2");
jpanel2.add(aJCheckBox[0]);
jpanel2.add(aJCheckBox[1]);
this.add(jpanel2);
//第三行
JPanel jpanel3=new JPanel();
jpanel3.setLayout(new GridLayout(1,3));
jpanel3.add(new JLabel("JRadioButton:",SwingConstants.RIGHT));
ButtonGroup aButtonGroup=new ButtonGroup();
aJRadioButton=new JRadioButton[3];
aJRadioButton[0]=new JRadioButton("JRadioButton1");
aJRadioButton[1]=new JRadioButton("JRadioButton2");
aJRadioButton[2]=new JRadioButton("JRadioButton3");
aButtonGroup.add(aJRadioButton[0]);
aButtonGroup.add(aJRadioButton[1]);
aButtonGroup.add(aJRadioButton[2]);
jpanel3.add(aJRadioButton[0]);
jpanel3.add(aJRadioButton[1]);
jpanel3.add(aJRadioButton[2]);
this.add(jpanel3);
//第四行
JPanel jpanel4=new JPanel();
jpanel4.setLayout(new GridLayout(1,3));
jpanel4.add(new JLabel("JTextArea In JScrollPane:",SwingConstants.RIGHT));
aTextArea=new JTextArea(5,10);
JScrollPane scrollpane=new JScrollPane(aTextArea);
jpanel4.add(scrollpane);
jpanel4.add(new JLabel("JList:",SwingConstants.RIGHT));
String[] informationOfList="one","two","three";
aJList=new JList(informationOfList);
jpanel4.add(aJList);
this.add(jpanel4);
//第五行
JPanel jpanel5=new JPanel();
jpanel5.setLayout(new GridLayout(1,3));
jpanel5.add(new JLabel("JSpinner:",SwingConstants.RIGHT));
aJSpinner=new JSpinner();
jpanel5.add(aJSpinner);
aJButton=new JButton("JButton");
jpanel5.add(aJButton);
this.add(jpanel5);
this.setVisible(true);
拖拽式的界面编程... 你想怎么放就怎么放本回答被提问者和网友采纳
以上是关于java图形用户界面,本人代码效果如下,但是行间距有点大,按钮之类的组件过大,怎么解决?的主要内容,如果未能解决你的问题,请参考以下文章