AnsweredAssumed Answered

Need help with java swing GridBagConstraints

Question asked by wroot Champion on Jul 11, 2015

I'm trying to add two more radio buttons into Spark's preferences Chat section (additional time formats). And two of them overlap, and i can't figure out why. I'm reading in the internet, but most examples are using different gridbaglayout format than Spark and there are just huge and talk about all in general. I will have to invest a week to learn how they actually work. But i already have a solution and just need two buttons to add. Maybe someone can point me in the right direction. I suspect those radio buttons do not feet into some set boundaries.

 

Original code (Spark/ChatPreferencePanel.java at master · igniterealtime/Spark · GitHub  line 117):

chatWindowPanel.add(showTimeBox, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
chatWindowPanel.add(format24, new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
chatWindowPanel.add(format12, new GridBagConstraints(2, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));

 

So it looks like:

[  ] Show time in chat window     (  ) 24:00         (  ) 12:00 PM

 

I modify it to:

chatWindowPanel.add(showTimeBox, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
chatWindowPanel.add(format24, new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
chatWindowPanel.add(format24s, new GridBagConstraints(2, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));        
chatWindowPanel.add(format12, new GridBagConstraints(3, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
chatWindowPanel.add(format12s, new GridBagConstraints(4, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));

 

So it should look like:

[  ] Show time in chat window    (   ) 24:00    (   ) 24:00:00   (   ) 12:00 PM   (   ) 12:00:00 PM

 

But the second radio button is overlapping with the third one. As i said, i suspect i'm adding too much columns into layout, but i can't figure out how to change that.

Outcomes