Questions tagged [gridbaglayout]

The GridBagLayout is a flexible Java Swing layout manager that aligns components vertically, horizontally or along their baseline without requiring that the components be of the same size. Each GridBagLayout object maintains a dynamic, rectangular grid of cells, with each component occupying one or more cells, called its display area.

The GridBagLayout is a flexible Java Swing layout manager that aligns components vertically, horizontally or along their baseline without requiring that the components be of the same size. Each GridBagLayout object maintains a dynamic, rectangular grid of cells, with each component occupying one or more cells, called its display area. More information on How to use GridBagLayout.

1216 questions
31
votes
2 answers

How to align left or right inside GridBagLayout cell?

I see that GridBagLayout positions it's children with center alignment within cells. How to align left or right? UPDATE Constructing code (I know I could reuse c) // button panel JPanel button_panel = new JPanel(); …
Dims
  • 47,675
  • 117
  • 331
  • 600
26
votes
2 answers

Weightx and Weighty in Java GridBagLayout

I have some trouble understanding these two properties. How should I give weight to components? How are these numbers calculated? I have tried to read several articles on the web but I do not understand it. Thank you.
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
21
votes
2 answers

Margin/padding in GridBagLayout Java

Is it possible to set an margin/padding in GridBagLayout for the whole row/column? I use the inset on the constraints-object however, using this approach I need to set padding from bottom on every single component. Is it possible to pad all of the…
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
19
votes
5 answers

Why does GridBagLayout center my components instead of putting it in the corner?

So far I managed to avoid using the GridBagLayout (by hand code) as much as possible, but I could not avoid it this time and I am reading the SUN's tutorial GridBagLayout So far it is not going well. I think I am missunderstanding something. For…
Cratylus
  • 52,998
  • 69
  • 209
  • 339
17
votes
6 answers

How can I properly center a JPanel ( FIXED SIZE ) inside a JFrame?

Hi all! I'm trying to solve an -apparently- simple problem, but I cannot fix it. I'm working on a sample application with Java/Swing libraries; I have a JFrame and a JPanel. I just want to achieve the following objectives: JPanel MUST be centered…
IT.
  • 311
  • 1
  • 5
  • 24
16
votes
4 answers

JTextField only shows as a slit Using GridBagLayout, need help

Hi thank you in advance for any help, I'm trying to build a simple program to learn GUI's but when I run the code below my JTextFields all show as a slit thats not large enough for even one character. cant post an image but it would look similar to:…
Bill.Caffery
  • 465
  • 1
  • 5
  • 21
14
votes
6 answers

Starting GridBagLayout from top left corner in Java Swing

I'm new to Java Swing and I have been struggling to start the GridBagLayout from top left corner so that c.gridx=0 c.gridy=0 will put my object on the top left corner. I'd appreciate if you could help me by telling what I need to do after this…
Emir
  • 762
  • 2
  • 8
  • 22
14
votes
4 answers

Why does Eclipse say that "errors exist" but shows nothing in console?

I am using Eclipse to build a program and when I go to run it, it says that "errors exist", I run it anyway, there are no errors showing up in the console and the application runs a blank screen. Why is this? Additional Info: I recently have been…
exit_1
  • 1,240
  • 4
  • 13
  • 32
13
votes
5 answers

GridBagLayout: equally distributed cells

Is it possible to completely emulate the behavior of a GridLayout with the GridBagLayout manager? Basically, I have a 8x8 grid in which each cell should have the same width and height. The GridLayout automatically did this. But I want to add another…
poke
  • 369,085
  • 72
  • 557
  • 602
12
votes
2 answers

Java GridBagLayout not working

I'm trying to use GridBagLayout, but I don't get what I expect and I can't find the error in this code: public class GridBagEx1 extends JPanel { private static final long serialVersionUID = 1L; protected void makebutton(String name,…
Emax
  • 1,343
  • 2
  • 19
  • 30
12
votes
2 answers

JSeparator wont show with GridBagLayout

I want to add a vertical JSeparator between two components using a GridBagLayout. The code I have is as follows: public MainWindowBody(){ setLayout(new GridBagLayout()); JPanel leftPanel = new InformationPanel(); JPanel rightPanel = new…
Aly
  • 15,865
  • 47
  • 119
  • 191
11
votes
2 answers

How can I make a component span multiple cells in a GridBagLayout

I have to make this for school: This is the code I have so far: import javax.swing.*; import java.awt.*; public class AddressBookGui1 extends JFrame { public AddressBookGui1(){ GridBagLayout gbl = new GridBagLayout(); GridBagConstraints…
user2503535
11
votes
2 answers

How to get GridBagLayout to respect minimum size of a button or panel?

In the following GridBagLayout code, I'm expecting the specified minimum size of JButton btn2 to be respected when the JFrame is resized to be made smaller. But when I make the JFrame smaller, the btn2 gets smaller than its minimum size and then…
user550738
10
votes
2 answers

Trouble adding a GridBagLayout inside an ActionListener

I have a JMenuItem with an ActionListener, in this ActionListener I want to add a GridBagLayout to my frame (which might or might not have a content pane yet added - for testing purposes it doesn't) and then add components to that frame. The design…
halfmike
  • 101
  • 4
9
votes
2 answers

GridBagLayout: how to fill all empty spaces

I've have a JFrame contains some JPanels using a gridBagLayout (3 rows, one column). That's my code: Container main_container = getContentPane(); GridBagLayout layout = new GridBagLayout(); main_container.setLayout(layout); GridBagConstraints c =…
giozh
  • 9,868
  • 30
  • 102
  • 183
1
2 3
80 81