setBounds设定位置不管用怎么办?

chris_zley 2006-10-20 08:31:44
创建了一个JFrame子类,setBounds()无论设置什么值,位置都是在屏幕左上角。setLocation()也是这样。。。

怎么回事?
...全文
2093 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
chris_zley 2006-10-23
  • 打赏
  • 举报
回复
我自己写的却不行,haisenmai的确实可以。。。
ctu_85 2006-10-23
  • 打赏
  • 举报
回复
环境问题?
ctu_85 2006-10-23
  • 打赏
  • 举报
回复
me too
lanseliuying 2006-10-22
  • 打赏
  • 举报
回复
偶运行也是正常的耶
chris_zley 2006-10-22
  • 打赏
  • 举报
回复
楼上运行我那段代码,位置是正常的?
wzd268 2006-10-21
  • 打赏
  • 举报
回复
不知道怎么回事

我试了一下,也是完全正常的啊

有可能是系统的问题吧
chris_zley 2006-10-21
  • 打赏
  • 举报
回复
挪到最后还是不行,其实运行时有一刹那,位置是正常的,然后闪了一下就到左上角去了。
interpb 2006-10-20
  • 打赏
  • 举报
回复
你的代码在我机器上运行是没有问题的 可以随着setLocation 值改变

你是什么 系统
ctu_85 2006-10-20
  • 打赏
  • 举报
回复
你只要在上面加一句:this.getContentPane.setLayout(null);
只要把布局器取消掉就有用,
这个问题也许是容器本身的布局影响
haisenmai 2006-10-20
  • 打赏
  • 举报
回复


import javax.swing.JFrame;

public class FrameLocate extends JFrame {

/**
* @param args
*/
FrameLocate(String name){
super(name);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FrameLocate fl = new FrameLocate("Myframe");
fl.setBounds(100,200,300,400);
fl.setLocation(100,200);
fl.setVisible(true);
}

}
freewilling 2006-10-20
  • 打赏
  • 举报
回复
setBounds的前两个参数是坐标位置,后两个是大小。setLocation只是设置位置。
把你的程序里面的setVisible(true)挪到最后去试试
interpb 2006-10-20
  • 打赏
  • 举报
回复
看看你的代码

chris_zley 2006-10-20
  • 打赏
  • 举报
回复
package booksystem;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Mainwindow extends JFrame {
public Mainwindow() {
super ("图书管理系统");
setSize(500,500);
setBackground(Color.white);
setVisible(true);
pack();
Container con = getContentPane();
JPanel panel = new JPanel();
JButton button1 = new JButton("借出");
JButton button2 = new JButton("归还");
JButton button3 = new JButton("关于");
JLabel label = new JLabel(new ImageIcon("booksystem/mm.jpg"));

//create Query menu
JMenu query = new JMenu("书籍查询");

//create Login menu
JMenu login = new JMenu("用户登陆");

//create System management menu
JMenu management = new JMenu("系统管理");

//create Students' function menu
JMenu stuFunction = new JMenu("学生功能");

//create Help function menu
JMenu help = new JMenu("帮助");

//create menubar
JMenuBar menubar = new JMenuBar();

//set menu to the menubar
menubar.add(query);
menubar.add(login);
menubar.add(management);
menubar.add(stuFunction);
menubar.add(help);

//set Mainwindow
setBounds(100,50,500,500);
menubar.setBounds(0,0,1024,20);
con.add(menubar);
panel.setBounds(0,0,500,500);
con.add(panel);
panel.setLayout(null);
button1.setBounds(5,25,60,30);
panel.add(button1);
button2.setBounds(70,25,60,30);
panel.add(button2);
button3.setBounds(135,25,60,30);
panel.add(button3);
label.setBounds(0,60,338,450);
panel.add(label);
validate();
}
}

这是我的代码,上面this.getContentPane.setLayout(null); 我试了,好像不管用。。。

各位帮忙看看。。。

setBounds的前两个参数就是设定坐标位置的话,同样的对象用setLocation还有什么用?搞不清楚

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧