2016-01-10 77 views
3

我在獲取工具欄的高度時遇到了問題。Codenmae一個工具欄高度

添加組件之前,高度爲「0」,添加組件後結果相同。

那麼,有沒有辦法獲得真正的工具欄高度?

btnCnt = new Container(); 
btnCnt.setUIID(null); 
btnCnt.addComponent(btnBack); 
btnCnt.addComponent(btnHome); 
btnCnt.addComponent(btnExit); 

currentForm.setToolBar(homeToolBar); 
currentForm.addCommand(SideLogoCommand); 
homeToolBar.addCommandToSideMenu(MenuCommand); 
homeToolBar.setTitleComponent(btnLogo); 

Container commandCnt = new Container(new BorderLayout()); 
commandCnt.addComponent(BorderLayout.EAST, btnCnt); 
commandCnt.setUIID(null); 
commandCnt.setPreferredH(homeToolBar.getHeight()); 
stateMachine.findCntHomeV2Header(currentForm).removeAll(); 
stateMachine.findCntHomeV2Header(currentForm).repaint(); 
stateMachine.findCntHomeV2Header(currentForm).addComponent(commandCnt); 

回答

2

你需要的是setSameHeight()setPrefferedH()

setPrefferedH()已棄用。

但如果你仍然想這樣做的,用homeToolBar.getPreferredH()而不是homeToolBar.getHeight()

btnCnt = new Container(); 
btnCnt.setUIID(null); 
btnCnt.addComponent(btnBack); 
btnCnt.addComponent(btnHome); 
btnCnt.addComponent(btnExit); 

currentForm.setToolBar(homeToolBar); 
currentForm.addCommand(SideLogoCommand); 
homeToolBar.addCommandToSideMenu(MenuCommand); 
homeToolBar.setTitleComponent(btnLogo); 


Container commandCnt = new Container(new BorderLayout()); 
commandCnt.addComponent(BorderLayout.EAST, btnCnt); 
commandCnt.setUIID(null); 
Component.setSameHeight(homeToolBar, commandCnt); 
stateMachine.findCntHomeV2Header(currentForm).removeAll(); 
stateMachine.findCntHomeV2Header(currentForm).repaint(); 
stateMachine.findCntHomeV2Header(currentForm).addComponent(commandCnt); 
+0

感謝@Diamond – Adnane17