简体   繁体   English

Netbeans topcomponent初始化组件

[英]Netbeans topcomponent initComponents

I have a topComponent's constructor like this: 我有一个像这样的topComponent的构造函数:

public BrowserTopComponent()
{
    initComponents();
    System.out.println("TopComponent size: "+this.getSize());
    System.out.println("TopComponnet prefered size: "+this.getSize());
    setName(NbBundle.getMessage(BrowserTopComponent.class,
                                "CTL_BrowserTopComponent"));
    setToolTipText(NbBundle.getMessage(BrowserTopComponent.class,
                                       "HINT_BrowserTopComponent"));

    System.out.println("JPanel size: "+jPanel1.getSize());
    System.out.println("JScrollPane1 size: "+jScrollPane1.getSize());

    //  setIcon(ImageUtilities.loadImage(ICON_PATH, true));

}

The problem is with all getSize() calls on components. 问题在于组件上的所有getSize()调用。 They all return [width=0, height=0]. 它们都返回[width = 0,height = 0]。 I don't understand when getSize() is initialized, to get right sizes? 我不知道何时初始化getSize()以获得正确的大小? How can I get actually sizes of my components in constructor? 如何在构造函数中实际获取组件的大小?

Thank you 谢谢

Try this.getPrefferedSize().width & this.getPrefferedSize().length instead. 尝试使用this.getPrefferedSize()。width和this.getPrefferedSize()。length。 This will return to you the preferred (or actual) dimensions of the component. 这将返回给您组件的首选(或实际)尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM