0

I'm tring to centrare one JLabel in a GridLayout.

For Example

JPanel p=new JPanel();
p.setLayout(new GridLayout(0,3));
p.add(new JLabel("a"));
p.add(new JLabel("b"));
p.add(new JLabel("c"));

The problem is that the JLabel are in the left part and not in the center part. Anyone can help me?

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
doflamingo
  • 77
  • 1
  • 1
  • 9
  • **Next three comments migrated from deleted answer** – Paul Samsotha Oct 25 '14 at 14:54
  • 1
    You can pass the horizontal alignment to the constructor.. `new JLabel("text", JLabel.CENTER);` – Paul Samsotha Oct 25 '14 at 14:54
  • **doflamingo** but I can use this method also in a BoxLayout? – Paul Samsotha Oct 25 '14 at 14:55
  • 1
    I don't see why not. But it all depends on the complete picture whether or not the labels will be centered. The method above just centers the text inside the label. But the actual position of the label depends on the layout manager. If you want help with a specific problem, then we need to see more code, preferably a [runnable example](http://stackoverflow.com/help/mcve) that demonstrates the problem – Paul Samsotha Oct 25 '14 at 14:55

0 Answers0