JFrame里的问题

Haisen大王 2015-05-23 08:15:38
package test_book;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
public class test {
public static boolean RIGHT_TO_LEFT=false;
public static void addComponents(Container contentPane){
if(RIGHT_TO_LEFT){
contentPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
}
contentPane.setLayout(new FlowLayout());
contentPane.add(new JButton("Button 1"));
contentPane.add(new JButton("Button 2"));
contentPane.add(new JButton("Button 3"));
contentPane.add(new JButton("long-name Button 4"));
contentPane.add(new JButton("5"));
}
private static void createAndShowGUI(){
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame=new JFrame("FlowLayout Demo"){
@Override
public Dimension getMinimumSize() {
Dimension prefSize=getMinimumSize();
return new Dimension(100,prefSize.height);
}

};
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addComponents(frame.getContentPane());
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable(){

@Override
public void run() {
createAndShowGUI();
}
});
}
}
如代码红色处,内部类重写那个方法有什么用啊??自己代码运行 发现就是 窗口不能随拖大拖小,看了JDK还是不是很理解。

...全文
219 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Haisen大王 2015-05-29
  • 打赏
  • 举报
回复
引用 2 楼 qq118194716 的回复:
这个代码不会引起无限递归么....
JFrame frame=new JFrame("FlowLayout Demo"){ @Override public Dimension getMinimumSize() { Dimension prefSize=getPreferredSize(); return new Dimension(200,prefSize.height); }};黏贴错了
O_森_O 2015-05-25
  • 打赏
  • 举报
回复
@Override
public Dimension getMinimumSize() {
Dimension prefSize=super.getMinimumSize();
return new Dimension(100,prefSize.height);
}
飏飏一蝶 2015-05-24
  • 打赏
  • 举报
回复
这个代码不会引起无限递归么....
Haisen大王 2015-05-23
  • 打赏
  • 举报
回复
这个方法究竟嘛效果。。求大神。如果是设置最小SIze为什么不是Set呢!

62,635

社区成员

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

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