2012-12-04 79 views
1

我正在使用netbeans RCP桌面應用程序,並且需要動態添加組件。例如,我有一個按鈕,如果我點擊菜單,應該在運行時將組件添加到窗口。我有一個按鈕的actionlistener,我在所執行的操作中添加了以下代碼,但沒有看到添加新組件。任何幫助表示讚賞。在運行時將netbeans rcp添加到topcomponent

TopComponent editorTopComponent = WindowManager.getDefault()。findTopComponent(「componentId」);
editorTopComponent.add(new JButton(「TEST」));
editorTopComponent.validate();
editorTopComponent.repaint();
editorTopComponent.updateUI();

感謝

+0

更新:我不知怎麼把它當我改變了的TopComponent的佈局弗洛工作wLayout,不知道這是否正確,但它的工作。 – user1583261

回答

0

如果你想創建現在實例(不止一個),那麼你可以使用:

MyTopComponent my = new MyTopComponent(); 
my.open(); 
my.requestActive(); 

如果你想在一個實例(只),那麼你可以使用開放TC:

TopComponent editor= WindowManager.getDefault().findTopComponent("componentId"); 
if(editor!=null){ 
    JPanel x =editor.getMyPanel(); 
    x.setVisible(false); 
    //some changes 
    x.setVisible(true); 
    if(!editor.isOpened())editor.open(); 
} 

爾卡

相關問題