Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do you control the distance between rows in a GridLayout

Posted on 2003-10-26
6
Medium Priority
?
274 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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:
Suggested Courses

773 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