GameControlEditor better Interface?

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);
}
}

Is there any specific reason you don’t use GridLayout for this? It is a lot easier to set up.

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.

Not exactly what I asked, but thanks for the information. It's good to know!



The problem is, that I have so many commands, that I need more space than the small window offer!

So I want to make two rows, looking like that—>





AIM: [][] FIRE:[][]



AIM: [][] FIRE:[][]



AIM: [][] FIRE:[][]



AIM: [][] FIRE:[][]


ONGOING

Looks at the moment like:


AIM: [_______][_______]
FIRE:[_______][_______]
FIRE:[_______][_______]
FIRE:[_______][_______]
FIRE:[_______][_______]
FIRE:[_______][_______]
FIRE:[_______][_______]
FIRE:[_______][_______]



Gotcha', well GameControlEditor was meant more as an example than anything.  I always expected most games to write their own anyway. :slight_smile:



GridLayout has a lot of limitations that make it not very friendly to use (most of which that every cell is exactly the same size).

darkfrog said:

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.

hevee said:
...you should install NetBeans and just play around with it's gui editor...


I only have one word in response, "Yuck!"

…you should install NetBeans and just play around with it's gui editor…



As tempting that sound, I think I pass :stuck_out_tongue:





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 ^^

Well, thanks for the information

hehe…some might say by using code I've written in your games you'll end up in hell. :wink: