----------------解决方案--------------------------------------------------------
建议你看一下JAVA API.
----------------解决方案--------------------------------------------------------
例子..
/*
* Main.java
*
* Created on 2007年7月29日, 下午10:49
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
//package nb;
/**
*
* @author Administrator
*/
public class Main extends JPanel{
/**
* @param args the command line arguments
*/
private JButton jb1,jb2;
public Main(){
setLayout(null);
jb1=new JButton("button1");
jb1.setBounds(10,10,50,50);
add(jb1);
jb2=new JButton("button2");
jb2.setBounds(70,30,50,50);
add(jb2);
}
public static void main(String[] args) {
JFrame frame=new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new Main());
frame.setSize(300,300);
frame.setVisible(true);
}
}
----------------解决方案--------------------------------------------------------
可能的错误:
frame.setVisible(true);
conPane.add(lb);
只有当setLayout(null)时组件必须用setBounds();
----------------解决方案--------------------------------------------------------
LS的正确,补充一点,要把尺寸设置好,如果尺寸设置的太小了,有时候也看不见,不过你可以先设置首选尺寸。。
----------------解决方案--------------------------------------------------------
还有一点,一定要把Layout设为null不然setBound无效
----------------解决方案--------------------------------------------------------