How to remove the space between a JComponent and its Grid border while using GridBagLayout?

How to remove the space between a JComponent and its Grid border while using GridBagLayout?

Hi, I had try to design a UI using GridBagLayout.I had a problem in that ie,the name of the Label is small(for example."Hai"),ane the gridwidth=1;when I try to add a JTextBox ater the Label,there I find huge space between the Label text and the TextBox.Could anyone help me to reduce the space between those Components?

Thanks for ur help in advance.

View Answers

August 4, 2011 at 3:12 PM

import java.awt.*;
import javax.swing.*;

public class GridBagLayoutExample {

  public static void main(String[] args) {
    JFrame f = new JFrame();
    JPanel p = new JPanel();

    p.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 2, 2); 
    c.gridx = 0; 
    c.gridy = 0;
    c.ipadx = 5;
    c.ipady = 5; 
    p.add(new JLabel("Java"), c); 
    c.gridx = 1; 
    c.ipadx = 0; 
    c.ipady = 0;
    p.add(new JTextField(20), c);
    f.getContentPane().add(p);
    f.setSize(300, 200);
    f.show();
  }
}

August 4, 2011 at 3:44 PM

What I exactly want is......1 JLabel name "Hai" another Label name is "Welcome" then the textBox next to Hai and welcome starts from same X axis position.I want the textbox after Hai to start before the welcome TB position

Ads









Related Tutorials/Questions & Answers:
How to remove the space between a JComponent and its Grid border while using GridBagLayout?
Remove Extra Space At End
Advertisements
Diff between Runnable Interface and Thread class while using threads
Diff between Runnable Interface and Thread class while using threads
space between buttons iPhone SDK
How To get DgroupId while using maven.
How to set the border in header and footer from login page using swings/awt
How to declare a Combobox without using a string in its declaration?
How to delete the row from the Database by using while loop in servlet
How to make a horizontally Scrollable grid in jsp using div, table, css, javascript?
How to make an animated text border, make an animated text border, animated text border
using java.lang.OutOfMemoryError: Java heap space
How to export grid into excel
How to make a double border text, make a double border text, double border text
how to space images in html code
java code using while loop
How to make a border shine text effect, make a border shine text effect, border shine text effect
How to access the image file from project folder itself while writing to pdf using itext?
How to develope web service with exachanging xml message between computers using SOAP
Set Space Ratio and Alignment
How to use between in mysql.
Finding a Factorial using while loop
days between two given dates using PHP
Email queue while sending mail using Struts Class
Email queue while sending mail using Struts Class
how to remove virtual environment in anaconda
how to remove virtual environment in anaconda
How to write a loop and a while loop
Using while loop to loop through a cursor
get data between date using jsp with msaccess
Exception while inserting image in oracle using java

Ads