design time anomaly in window builder and swing

2019-07-23 23:52发布

Im experimenting with window builder for eclipse and Swing.

I created a demo calculator project with a custom JPanel

DigitBoardView extends JPanel  

and assigned the keys using a for loop

String[] digits = {"1", ...} 
for(String digit : digits){
 JButton digButton = new JButton(digit);
 add(digButton);
}

1st problem - DigitBoardView designer doesn't show it, though FAQ says it will not generate and show runtime dependant GUI in design time (which is OK), nothing here is runtime dependant.
Even if I iterate over the digits with an explicitly known at compile time
for(int i = 0; i < 10; i++) loop designer doesn't edge

2nd problem - JFrame designer does show it! If I set the content pane of a JFrame to be new DigitBoardView it will be shown in design time...

Why so strange? Is it bug?

Should I bypass it by flattening the loop?
Isn't it extremely ugly?
Defeats the purpose of not repeating myself principle?

1条回答
啃猪蹄的小仙女
2楼-- · 2019-07-24 00:37

Although it's tangential to the designer issue, you might like to examine KeyPadPanel, which uses actions and key bindings to implement a simple numeric keypad having a simple GridLayout.

查看更多
登录 后发表回答