Solved

How do you control the distance between rows in a GridLayout

Posted on 2003-10-26
6
268 Views
Last Modified: 2008-03-06
How do you control the distance between rows in a GridLayout
0
Comment
Question by:rayskelton
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:smitty22
ID: 9624365
You can construct your layout with:  GridLayout(int rows, int cols, int hgap, int vgap), where vgap is the pixel distance between rows, and similarly hgap is the distance between columns.

You can also specify the gaps later with setHgap and setVGap.
0
 

Author Comment

by:rayskelton
ID: 9624417
I have tried this with no affect. Any ideas why this would not work?
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9625481
How do you mean it didn't work?  Could you post some code?

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:rayskelton
ID: 9631109
I am displaying JLabels in a Dialog of queried information and asking confirmation. My GridLayout is in the form of GridLayout(3,2,1,1) and my dialog is sized  setSize(400, 150). Arg 3 and 4 of GridLayout do not appear to control the content the way I would like. The code displays with very large gaps between the grid rows. I can control this spacing to some extent by adjusting arg 2 of setSize(). Below is a code snippet. There may not be a problem, just it is working in a different form than I am expection. If so, how do I control the spacing between grids?
-----------------------
      final JPanel mainPanel = new JPanel(new BorderLayout());
      final JPanel buttonGroupPanel = new JPanel();
     
      JPanel editPanel = new JPanel(new GridLayout());

      // get the edit pane
      editPanel = getEditPane();

      JPanel buttonPanel = new JPanel();
      // decision processing buttons
      buttonPanel = getButtonPane();
     
      mainPanel.add(editPanel);
      mainPanel.add(buttonPanel, BorderLayout.SOUTH);
      c.add(mainPanel);

      JFrame frame = new JFrame();
      Window window = new Window(frame);
      setLocation(CenterWindow.getPosition(window));
      setSize(400, 150);
      show();
------------------------------

 private JPanel getEditPane()
{
     
     JPanel editPanel = new JPanel(new GridLayout(3,2,1,1));
     .......

}
0
 
LVL 15

Accepted Solution

by:
jimmack earned 125 total points
ID: 9640632
Sorry for the late response.  I've had two days where my system couldn't resolve the EE URL :-(

What do you add to the editPanel inside the getEditPane() method?

Two other observations:

Change the following:

>>      JPanel editPanel = new JPanel(new GridLayout());
>>
>>      // get the edit pane
>>      editPanel = getEditPane();

to:

        JPanel editPanel = getEditPane();

I'm not sure what you are doing with the following:

>>      JFrame frame = new JFrame();
>>      Window window = new Window(frame);
>>      setLocation(CenterWindow.getPosition(window));
>>      setSize(400, 150);
>>      show();

Shouldn't this be:

        JFrame frame = new JFrame();
        frame.getContentPane().add(mainPanel);
        frame.setSize(400, 150);
        frame.show();
0
 

Author Comment

by:rayskelton
ID: 9646102
i'll try yor approach. It looks good,so will close out this ticket.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java exception bubble up 2 21
hibernate jars 4 45
SequenceInputStream example 3 19
Setup GlassFish 4 22
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question