This is what im trying to achieve , which is just a sample versus on what is in the actual code.
:
|-----------------------------------------------|
| Group Name :--||||textbox|||||||||||||--------|
|-----------------------------------------------|
|-----------------------------------------------|
|--Description-----Price------Quantity----------|
|-- Hotdog -----12.00------1234 ----------|
|-- Cheese -----34.56------4567 ----------|
|-----------------------------------------------|
|-----------------------------------------------|
|-- Add Button --- Remove Button ---------------|
|-----------------------------------------------|
The problem is i cant seem to show the 2 buttons below. And my mouse have to mouse over on the buttons so they will show up..
Here are the codes modified from the gridbag layout demo from Sun :
import java.awt.*;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTable;
public class ASample {
final static boolean shouldFill = true;
final static boolean shouldWeightX = true;
final static boolean RIGHT_TO_LEFT = false;
final static
String[] columnNames = {"Text Display", "Link Name","Sports","Age","Straight"};
final static Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
//centering the Frame
public static Point getCenteredCorner(Component c)
{
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
return new Point(
(int)((dim.getWidth() - c.getWidth()) / 2),
(int)((dim.getHeight() - c.getHeight()) / 2)
);
}
public static void addComponentsToPane(Container pane) {
if (RIGHT_TO_LEFT) {
pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
}
JButton button;
JLabel label;
JTextField textfield;
JTable table;
JScrollPane scrollPane ;
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
if (shouldFill) {
//natural height, maximum width
c.fill = GridBagConstraints.HORIZONTAL;
//c.fill = GridBagConstraints.NORTH;
}
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
label = new JLabel("Radio Button Group Name :");
buttonPanel.add(label);
textfield = new JTextField("",15);
buttonPanel.add(textfield);
c.weightx = 1.0;
c.gridx = 0; //col
c.gridy = 0; //row
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.insets = new Insets(10,35,100,0); //top,left,bottom,right
//c.gridwidth = 1;
c.gridheight = GridBagConstraints.REMAINDER;
pane.add(buttonPanel,c);
table = new JTable(data, columnNames);
scrollPane = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(400, 100));
c.weightx = 1;
c.gridx = 0;
c.gridy = 1;
c.ipady = 150; //make this component tall
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(50,0,0,0);
//c.gridwidth = 1;
c.gridheight = GridBagConstraints.REMAINDER;
c.anchor = GridBagConstraints.FIRST_LINE_START;
buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(scrollPane);
pane.add(buttonPanel, c);
buttonPanel = new JPanel(new FlowLayout());
button = new JButton("Add");
buttonPanel.add(button);
button = new JButton("Remove");
buttonPanel.add(button);
c.weightx = 0;
c.gridx = 0;
c.gridy = 2;
c.ipady = 0; //make this component tall
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(200,0,0,0);
//c.gridwidth = 1;
c.gridheight = GridBagConstraints.REMAINDER;
//c.anchor = GridBagConstraints.CENTER;
pane.add(buttonPanel, c);
}
/**
* Create the GUI and show it. For
thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
JFrame frame = new JFrame("GridBagLayoutDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Set up the content pane.
addComponentsToPane(frame.getContentPane());
//Display the window.
frame.setSize(500,300);// width, height
//frame.setResizable(false);
frame.setLocation(getCenteredCorner(frame));
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
[ February 08, 2007: Message edited by: Cyrus Serrano ]
[ February 08, 2007: Message edited by: Cyrus Serrano ]