请问java的GUI界面如何实现缩放窗口时组件不跟着变形,100分发上兑现 contentPane.setLayout(null);// orimport com.borland.jbcl.layout.*;contentPane.setLayout( new XYLayout() ); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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(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();}} orimport 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();}} getToolkit().getScreenSize()用这个可以取得屏幕尺寸,剩下的自己想把 定义组键的尺寸,可以用GridBagConstraints里的,ipadx和ipday确定,也可以用setPreferredSize(new Dimension(int x,int y))来设置大小! 只要布局用borderlayout就可以实现。 可以尝试:setLayout(null);再用setBounds(x,y,width,height);定位.应该可以,虽然很多书上不推荐用setLayout(null) maybe you need to use multi-layouts to solve that problem. I am not sure of what results you want ultimately. 关于绝对路径与相对路径的问题 好久没来问问题啦。这个好久没搞定。在读取快逸报表模板时候出错。。。。。。 想不明白的问题! 哪里来的类库? 怎么对STRING型做INPUT VALIDATION 急需解决的问题,请帮忙! 怎样在.setText()或println()中输出回车呀?哪位大哥讲一下 关于MICROSOFT OFFICE 的问题 求教:逢3退1哪里出错了? 各位大侠:推荐几本好书和好的网站吧 关于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)