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?
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 simpleGridLayout
.