Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JButton Padding with Grid Bags?

264 views
Skip to first unread message

Matt S

unread,
May 27, 2003, 9:10:14 PM5/27/03
to
I am trying to make a really slick looking GUI that I designed in
photoshop. I have cut the image up in to pieces and used grid bags as
my layout manager. The software is designed for a 640x480 screen - it
will be used on a tv monitor in my car. Everything is looking pretty
good when my script loads up, but there are some gaps between the
jbuttons I have made and I would like everything to aliging together.
If someone could help me figure out where I am going wrong I would
really appreciate it. I have been all over google and my sun java book
for about 8 hours with no luck....

http://www.mo-music.org/autopc/ (this is the code and GUI images)

Here is a pasting of the source:

import java.io.*;
import javax.imageio.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class AutoPc {

public static void main(String args[]) {

ButtonFrame frame = new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();

}

}

// A frame with a button panel

class ButtonFrame extends JFrame {

public ButtonFrame() {

setTitle(frameTitle);
setSize(640,480);

// Add a panel to the frame

ImageButton gps_image = new ImageButton("v1.0GUI/GPS_BUTTON.gif");
ImageButton mp3_image = new ImageButton("v1.0GUI/MP3_BUTTON.gif");
ImageButton skin_image = new ImageButton("v1.0GUI/SKIN_BUTTON.gif");
ImageButton off_image = new ImageButton("v1.0GUI/OFF_BUTTON.gif");
ImageButton auto_pc_logo1 = new ImageButton("v1.0GUI/AUTO_PC1.gif");
ImageButton auto_pc_logo2 = new ImageButton("v1.0GUI/AUTO_PC2.gif");
ImageButton direction_bar = new
ImageButton("v1.0GUI/DIRECTION_BAR.gif");
ImageButton default_bg = new ImageButton("v1.0GUI/DEFAULT_BG.gif");

Container contentPane = getContentPane();
GridBagLayout layout = new GridBagLayout();
contentPane.setLayout(layout);
GridBagConstraints constraints = new GridBagConstraints();

constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.fill = GridBagConstraints.BOTH;
//constraints.anchor = GridBagConstraints.NORTH;
constraints.insets = new Insets(0,0,0,0);

contentPane.add(gps_image,constraints);

constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.gridheight = 1;

contentPane.add(mp3_image,constraints);

constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 2;
constraints.gridwidth = 1;
constraints.gridheight = 1;

contentPane.add(skin_image,constraints);

constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;

contentPane.add(off_image,constraints);

constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 4;
constraints.gridwidth = 1;
constraints.gridheight = 1;

contentPane.add(auto_pc_logo1,constraints);

constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 5;
constraints.gridwidth = 1;
constraints.gridheight = 1;

contentPane.add(auto_pc_logo2,constraints);

constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 1;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 5;

contentPane.add(default_bg,constraints);

constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 1;
constraints.gridy = 5;
constraints.gridwidth = 1;
constraints.gridheight = 1;

contentPane.add(direction_bar,constraints);

}

public static final String frameTitle = "Auto Pc v1.0 - Created By
MMS - www.autopc.com";

}

// Creating a panel to put buttons on

class ImageButton extends JPanel {

public ImageButton(String path) {

image_path = path;

// create buttons

JButton button = new JButton(new ImageIcon(image_path));
button.setBorderPainted(false);
button.setMargin(new Insets(0,0,0,0));
button.setOpaque(false);
add(button);

}

private JButton button;
private String image_path;

}

M Series

unread,
May 28, 2003, 6:55:41 AM5/28/03
to
try fiddling around with the ipadx and ipady attributes in your
GridBagContraints


"Matt S" <ma...@sekelsky.com> wrote in message
news:a1c13a20.03052...@posting.google.com...

Matt S

unread,
May 28, 2003, 10:38:20 PM5/28/03
to
Changing the ipadx and ipady didn't do anything. Does anyone else have any ideas?

Thanks!

"M Series" <spa...@127.0.0.1> wrote in message news:<bb248i$foh$1...@newsg3.svr.pol.co.uk>...

Babu Kalakrishnan

unread,
May 29, 2003, 4:07:43 AM5/29/03
to
On 28 May 2003 19:38:20 -0700, Matt S <ma...@sekelsky.com> wrote:

> Changing the ipadx and ipady didn't do anything. Does anyone else have any ideas?

Did you try setting them to negative values ? Positive values will only
increase the spacing between images.

BK

0 new messages