ablong 2009-04-13 09:59
浏览 233
已采纳

swing

swing: 程序运行后只显示一个jframe,只有将窗口最小化再最大化后才会显示jframe上的内容,该怎么解决呢?

[b]问题补充:[/b]
能说得再具体点不?
[b]问题补充:[/b]
uiupdate是哪里的类?
[b]问题补充:[/b]
[code="java"]package print;

import java.awt.*;
import java.util.List;

import javax.swing.*;

public class MyFrame {

private static final int WIDTH = 700;
private static final int HEIGHT = 500;
JPanel mainpanel = null;    //在框架上添加的主面板
JPanel downpanel = null;    //在主面板的下面的一个面板
public static UpRightPanel rightPanel ;

public MyFrame(){
    JFrame jf = new JFrame();
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setSize(WIDTH, HEIGHT);
    jf.setVisible(true);
    jf.setResizable(false);

    //设置顶层框架居中显示
    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();
    int screenWidth = screenSize.width;
    int screenHeight = screenSize.height;
    int x = (screenWidth - WIDTH)/2;
    int y = (screenHeight - HEIGHT)/2;
    jf.setLocation(x, y);

    GridLayout lay = new GridLayout(2,1);
    //jf.setLayout(lay);

    mainpanel = new JPanel();
    mainpanel.setBackground(new Color(220,220,200));
    jf.add(mainpanel);
    mainpanel.setLayout(new FlowLayout(FlowLayout.LEFT));

    UpLeftPanel upanel = new UpLeftPanel();
    mainpanel.add(upanel);

    UpCenterPanel centerPanel = new UpCenterPanel();
    mainpanel.add(centerPanel);

    UpRightPanel rightPanel = new UpRightPanel();
    mainpanel.add(rightPanel);

    DownPanel downPanel = new DownPanel();
    mainpanel.add(downPanel);

}

public MyFrame(List stus){
    JFrame jf = new JFrame();
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setSize(WIDTH, HEIGHT);
    jf.setVisible(true);
    jf.setResizable(false);

    //设置顶层框架居中显示
    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();
    int screenWidth = screenSize.width;
    int screenHeight = screenSize.height;
    int x = (screenWidth - WIDTH)/2;
    int y = (screenHeight - HEIGHT)/2;
    jf.setLocation(x, y);

    GridLayout lay = new GridLayout(2,1);
    //jf.setLayout(lay);

    mainpanel = new JPanel();
    mainpanel.setBackground(new Color(220,220,200));
    jf.add(mainpanel);
    mainpanel.setLayout(new FlowLayout(FlowLayout.LEFT));

    //左上方的面板
    UpLeftPanel upanel = new UpLeftPanel();
    mainpanel.add(upanel);

    //中上方的面板
    UpCenterPanel centerPanel = new UpCenterPanel(stus);
    mainpanel.add(centerPanel);

    //右上方的面板类
    rightPanel = new UpRightPanel();
    mainpanel.add(rightPanel);

    DownPanel downPanel = new DownPanel();
    mainpanel.add(downPanel);
}

}
[/code]

  • 写回答

3条回答 默认 最新

  • iteye_14762 2009-04-13 12:52
    关注

    将你的jf.setVisible(true); 这句放到最后执行,也就是你把所有的panel加进去后,整个jframe构造好了之后,在执行!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 游戏盾如何溯源服务器真实ip?
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。