Java显示白框_当我尝试在框架上添加多个组件时,Swing显示白框

我正在开发java swing应用程序 . 我尝试在我的主JFrame上添加2个JPanel .

我的主要JPanel类:

public class DrawingPanel extends JPanel {

//mouse variables here

//Point mPt = new Point(0,0);

public DrawingPanel() {

setBackground(COLOURBACK);

MyMouseListener ml = new MyMouseListener();

addMouseListener(ml);

}

public Dimension getPreferredSize() {

return new Dimension(width, height);

}

....

....

....

}

当我添加为主框架上的唯一组件时工作正常 . 但是当我尝试在框架上添加另一个JPanel时,我的DrawingPanel显示为小白框 .

private void createAndShowGUI()

{

DrawingPanel panel = new DrawingPanel();

JFrame frame = new JFrame("Hex Testing 4");

frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

Container content = frame.getContentPane();

JPanel aggregationFrame = new JPanel(new GridBagLayout());

aggregationFrame.add(panel);

aggregationFrame.add(new JLabel("Enter username:"));

content.add(aggregationFrame);

//this.add(panel); -- cannot be done in a static context

//for hexes in the FLAT orientation, the height of a 10x10 grid is 1.1764 * the width. (from h / (s+t))

frame.setSize( (int)(SCRSIZE/1.23), SCRSIZE);

frame.setResizable(false);

frame.setLocationRelativeTo( null );

frame.setVisible(true);

}

看起来像这样

我尝试将getPreferredSize()方法添加到DrawingPanel中,如JPanel appears as a small white box问题中所建议的那样,但它不能正常工作 .

你能帮我解决这个问题吗?

UPDATE:

我已经改变了布局,现在我看到了一半的JPanel . 我认为问题与JPanels和JFrame的固定大小有关 . 将调查它 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值