簡體   English   中英

使 TitledBorder 不可見?

[英]Making TitledBorder Invisible?

所以我有以下 JComponent 我想讓它在某些條件下不可見:

private final JComponent createStop()
{
    JPanel          jp;
    GridPlacement   gp;

    jp = new JPanel();
    jp.setOpaque( false );
    jp.setBorder( buildBorder(Res.getIntl(RES+"$Border.Stop")) ); // -----> Here's the problem

    gp = new GridPlacement( jp, INS_SMALL );
    gp.add( stopNo, 0,0,false,"N","NW",1,1 );
    gp.add( stopYes, 1,0,false,"N","NW",1,1 );
    gp.add( stopTimeout, 2,0,false,"N","NW",1,1 );
    gp.add( stopKill, 3,0,false,"N","NW",1,1 );
    //gp.add( new FillArea(0,0), 3,2,true,"H","C",1,1 );
    gp.add( new FillArea(0,0), 100,100,true,"B","C",1,1 );

    return jp;
}

我可以讓所有東西都不可見,除了 titledBorder ,當我這樣做時它不會因為某種原因消失:

    createStop().setVisible(false);

即使我嘗試將其強行設置為 null,它仍然可見:

        createStop().setBorder(null);

當我嘗試這樣做時,同樣的事情:

createStop().setBorder(BorderFactory.createEmptyBorder());

以下是邊框的創建方式:

protected Border buildBorder( String s )
{
    return BorderFactory.createTitledBorder( BORDER_TITLE, s, TitledBorder.LEADING, TitledBorder.TOP, FONT_TITLE );
}

有什么辦法可以讓它像 createStop() 方法的其余元素一樣不可見?

好的,如果其他人遇到同樣的問題,這是我為解決它所做的:

我從createStop()方法中取出變量jp並將其createStop()全局變量。

然后,根據條件,在將 JPanel 的可見性設置為 true 或 false 后,我在 JPanel 上調用了 revalidate():

if (Condition){
    jp.setVisible(false);
    jp.revalidate();
} else {
    jp.setVisible(true);
    jp.revalidate();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM