为什么下面的java程序运行后按钮组件不显示
importjava.awt.event.*;importjavax.swing.*;importjava.awt.BorderLayout;importjava.awt...
import java.awt.event.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestJrame {
private JButton button1,button2,button3;
JPanel panel = new JPanel(new GridLayout(1,7,0,0));
JPanel panel1 = new JPanel(new GridLayout(1,1,0,0));
JPanel panel2 = new JPanel(new GridLayout(2,1,0,0));
JPanel panel3 = new JPanel(new GridLayout(2,1,0,0));
button1 = new JButton("JButton");
button1.setFont(new Font("宋体", Font.BOLD, 12));
button2 = new JButton("Check/Radio");
button2.setFont(new Font("宋体", Font.BOLD, 12));
button3 = new JButton("JComboBox");
button3.setFont(new Font("宋体", Font.BOLD, 12));
panel2.add(button1);
panel2.add(button2);
panel3.add(button3);
panel.add(panel1);
panel.add(panel2);
panel.add(panel3);
public static void main(String args[]){
JFrame frm=new JFrame("组件皮肤定制预览工具");
frm.setJMenuBar(mb);
frm.setBounds(10,10,800,600);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
}
} 展开
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestJrame {
private JButton button1,button2,button3;
JPanel panel = new JPanel(new GridLayout(1,7,0,0));
JPanel panel1 = new JPanel(new GridLayout(1,1,0,0));
JPanel panel2 = new JPanel(new GridLayout(2,1,0,0));
JPanel panel3 = new JPanel(new GridLayout(2,1,0,0));
button1 = new JButton("JButton");
button1.setFont(new Font("宋体", Font.BOLD, 12));
button2 = new JButton("Check/Radio");
button2.setFont(new Font("宋体", Font.BOLD, 12));
button3 = new JButton("JComboBox");
button3.setFont(new Font("宋体", Font.BOLD, 12));
panel2.add(button1);
panel2.add(button2);
panel3.add(button3);
panel.add(panel1);
panel.add(panel2);
panel.add(panel3);
public static void main(String args[]){
JFrame frm=new JFrame("组件皮肤定制预览工具");
frm.setJMenuBar(mb);
frm.setBounds(10,10,800,600);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
}
} 展开
1个回答
展开全部
你的程序我帮你改好了,改动的地方见注释.现在程序运行后按钮组件可以显示了.
完整的Java程序如下:
import java.awt.event.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestJFrame { //这里TestJrame改成TestJFrame
private JButton button1,button2,button3;
JPanel panel = new JPanel(new GridLayout(1,7,0,0));
JPanel panel1 = new JPanel(new GridLayout(1,1,0,0));
JPanel panel2 = new JPanel(new GridLayout(2,1,0,0));
JPanel panel3 = new JPanel(new GridLayout(2,1,0,0));
TestJFrame(){//这里加构造函数
button1 = new JButton("JButton");
button1.setFont(new Font("宋体", Font.BOLD, 12));
button2 = new JButton("Check/Radio");
button2.setFont(new Font("宋体", Font.BOLD, 12));
button3 = new JButton("JComboBox");
button3.setFont(new Font("宋体", Font.BOLD, 12));
panel2.add(button1);
panel2.add(button2);
panel3.add(button3);
panel.add(panel1);
panel.add(panel2);
panel.add(panel3);
}
public static void main(String args[]){
TestJFrame f=new TestJFrame();//这里创建对象
JFrame frm=new JFrame("组件皮肤定制预览工具");
frm.add(f.panel); //这里把组件加入JFrame中
frm.setBounds(10,10,800,600);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
}
}
追问
谢谢!果然出现了。我想只让那些按钮出现在右上角右下部分把下面空出来,而不是铺满整个右边应该怎么弄呀?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询