I have add some key elements, but the problem is for this much keys ist not enough space.
I would like to change the Layout. For each row, two tables!
Now:
X
X
X
X
X
Wish:
XX
XX
XX
I have read about GridBagLayout, but everything I tried, doesn't work.
Hope someone can help me!!
Thanks
Code:
private void init() {
listener = new ControlFieldListener(this);
GridBagLayout layout = new GridBagLayout();
setLayout(layout);
GridBagConstraints constraints = new GridBagConstraints();
for (String name : manager.getControlNames()) {
GameControl control = manager.getControl(name);
// Add the label
JLabel label = new JLabel(name + ":");
label.setHorizontalAlignment(JLabel.LEFT);
constraints.gridwidth = 1;
constraints.anchor = GridBagConstraints.EAST;
//constraints.insets = new Insets(5, 5, 5, 5);
constraints.insets = new Insets(1, 1, 1 , 1);
layout.setConstraints(label, constraints);
add(label);
// Add bindings
ControlField[] fields = new ControlField[bindings];
for (int i = 0; i < fields.length; i++) {
Binding binding = null;
if (control.getBindings().size() > i) {
binding = control.getBindings().get(i);
}
fields = new ControlField(control, binding);
fields.addMouseListener(this);
if (i == fields.length - 1) {
constraints.gridwidth = GridBagConstraints.REMAINDER;
}
layout.setConstraints(fields, constraints);
add(fields);
}
controls.put(control, fields);
}
}
You mean you want to have two fields for specifying a binding per control? If that's what you mean simply set "binding" to 2 in the constructor…or 3 if you want and you'll have the ability to set multiple bindings per control.
GridLayout has a lot of limitations that make it not very friendly to use
GridLayout is way easier to intitialize for the average Swing novice. In my understanding DarkPhoenixX seems to have enough on his mind already even without the complexity of GridBadLayout's constraint mechanism, that's why I'd still suggest GridLayout for now.
That might be only an intermediate "solution", nothing final, but the day might come when DPX will have more time to deal with GridBagLayout and replace the uglier looking GridLayout with something nicer.
Of course this is a philosophy of doing things that many may oppose, and I'm fine with that :)
hevee, he was asking specifically about GridBagLayout because that is what I used in GameControlEditor when I wrote it and I think he's just trying to extend it.
OK - In that case there is some work ahead of you either way, DPX - you may as well learn how to deal with GridBagLayout properly. I don't know which IDE you are using, but to play with GBL, you should install NetBeans and just play around with it's gui editor. It is the easiest way I know of to learn how GBL works, because of the immediate visual feedback to your actions.
…you should install NetBeans and just play around with it's gui editor…
As tempting that sound, I think I pass
Because Darkfrog has written this class, i thought of it like the Holy Grail, but now I 'm reliefed, that if I change the layout type, I'm not going to hell ^^