开发者

design time anomaly in window builder and swing

开发者 https://www.devze.com 2023-04-04 00:51 出处:网络
Im experimenting with window builder for eclipse and Swing. I created a demo calculator project with a custom JPanel

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 JB开发者_StackOverflowutton(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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消