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









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
space around/between my images
Diff between Runnable Interface and Thread class while using threads
Diff between Runnable Interface and Thread class while using threads
remove space - Java Beginners
space between buttons iPhone SDK
How to set the border in header and footer from login page using swings/awt
How To get DgroupId while using maven.
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
using java.lang.OutOfMemoryError: Java heap space
add row in grid using dojo
How to make an animated text border, make an animated text border, animated text border
How to make a double border text, make a double border text, double border text
How to make a horizontally Scrollable grid in jsp using div, table, css, javascript?
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 start intergrated webcam of a laptop without calling its exe file using java only - Java Beginners
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
How can we know the number of days between two given dates using PHP?
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
How to access the "Add/Remove Programs" list in Control Panel using Java Program? - Java Beginners
Set Space Ratio and Alignment
How to export grid into excel
How to access the image file from project folder itself while writing to pdf using itext?
Image Slide Show using 'Space gallery' plug-in
How do Unzip a directory and all its contents using ZipEntry class in java.
How to develope web service with exachanging xml message between computers using SOAP
remove duplicates from list in java using set
Finding a Factorial using while loop
Tree Grid using JSF - Java Server Faces Questions
days between two given dates using PHP
how to insert a summary values in grid
Show spinner while loading image using JavaScript
how to remove virtual environment in anaconda
how to remove virtual environment in anaconda
border around frames
Email queue while sending mail using Struts Class
Email queue while sending mail using Struts Class
Using while loop to loop through a cursor
Iterator Java While
Exception while inserting image in oracle using java
Difference between getting a document using DOMParser & DocumentBuilderFactory !!!
get data between date using jsp with msaccess
How to use between in mysql.
Finding a Factorial using while loop
Border Layout
How to remove old Docker containers

Ads