contentPane.setLayout(null);
// or
import com.borland.jbcl.layout.*;
contentPane.setLayout( new XYLayout() );
// or
import com.borland.jbcl.layout.*;
contentPane.setLayout( new XYLayout() );
解决方案 »
- 有关用poi读取excel的小问题
- ListCellRenderer
- jni中C++本地代码如何取得java中的变量值(非参数传递)
- java.lang.NullPointerException???
- 在Eclipse中新建XML文件 需要什么配置
- 请教高手:我的这个验证密码的算法为什么只认4位及4位以下的密码??????
- 一个关于两个窗体之间的通讯问题
- 请问jBuilder怎样配置jdbc for oracle?
- java命令执行类文件时不在bin的目录下出现Exception in thread "main" java.lang.NoClassDefFoundError:
- 搞JAVA的能赚多少钱???
- 关于System.in.read()的问题:
- jbuilder生成执行文件的问题
JPanel contentPanel=(JPanel)this.getContentPane();
JPanel jp=new JPanel();
JButton jb=new JButton("1");
JButton jb1=new JButton("2");
public myFrame() {
super("myFrame");
this.setSize(800,600);
this.setResizable(true);
this.setLocation(this.getToolkit().getScreenSize().width/2-400,this.getToolkit().getScreenSize().height/2-300);
contentPanel.setLayout(new BorderLayout());
contentPanel.add("Center",jp);
jp.setLayout(null);
jp.add(jb);
jb.setBounds(100,100,100,100);
jp.add(jb1);
jb1.setBounds(2100,210,50,50);
this.setVisible(true);
}public static void main(String args[]) {
new myFrame();
}
}
import javax.swing.*;public class myFrame extends JFrame {
JPanel contentPanel=(JPanel)this.getContentPane();
JPanel jp=new JPanel();
JButton jb=new JButton("1");
JButton jb1=new JButton("2");
public myFrame() {
super("myFrame");
this.setSize(800,600);
this.setResizable(true);
this.setLocation(this.getToolkit().getScreenSize().width/2-400,this.getToolkit().getScreenSize().height/2-300);
contentPanel.setLayout(new BorderLayout());
contentPanel.add("Center",jp);
jp.setLayout(new FlowLayout());
jp.add(jb);
jp.add(jb1);
this.setVisible(true);
}public static void main(String args[]) {
new myFrame();
}
}
也可以用setPreferredSize(new Dimension(int x,int y))来设置大小!
setLayout(null);
再用
setBounds(x,y,width,height);
定位.
应该可以,虽然很多书上不推荐用setLayout(null)