Solved

How do you control the distance between rows in a GridLayout

Posted on 2003-10-26
6
264 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now