This is my first attempt at using the GridBagLayout. Here is a screen shot of the program I made with C# that I am trying to remake in Java:
GBL.jpg
Here is my code:
package ISAPI; import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JTextField; public class MainFrame extends JFrame { final int WIDTH = 850; final int HEIGHT = 600; private String[] ComboArry ={" ", "IAgentManagement", "IContactManagment", "ISessionManagement"}; public MainFrame(String title) { super(title); Dimension size = getPreferredSize(); size.width = WIDTH; size.height = HEIGHT; setPreferredSize(size); JLabel hostLabel = new JLabel("IS Host"); JLabel generatedLabel = new JLabel("Generated URL to Post to integration Services"); JLabel responseHtmlLabel = new JLabel("Response from the API in HTML"); JLabel responseTextLabel = new JLabel("Response from the API in Text"); JLabel interfaceLabel = new JLabel("Interface"); JTextField hostTextField = new JTextField(22); JTextArea generatedTextArea = new JTextArea(3, 20); JTextArea responseHTMLTextArea = new JTextArea(10, 10); JTextArea responseTextTextArea = new JTextArea(10, 4); JButton createURLButton = new JButton("Create URL"); JButton postButton = new JButton("Post"); JComboBox interfaceBox = new JComboBox(ComboArry); interfaceBox.setPreferredSize(new Dimension(250,20)); ActivityPanel Ap = new ActivityPanel(); Container pane = getContentPane(); pane.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); //first row gc.fill = GridBagConstraints.HORIZONTAL; gc.weightx = 0.2; gc.weighty = 1; gc.gridx = 0; gc.gridy = 0; add(hostLabel, gc); gc.fill = GridBagConstraints.HORIZONTAL; gc.weightx = 0.5; gc.gridx = 1; gc.gridy = 0; add(hostTextField, gc); gc.fill = GridBagConstraints.HORIZONTAL; gc.weightx = 2; gc.gridx = 2; gc.gridy = 0; add(generatedLabel, gc); //second row gc.fill = GridBagConstraints.HORIZONTAL; gc.weightx = 0.5; gc.weighty = 1; gc.gridx = 0; gc.gridy = 1; add(interfaceLabel, gc); gc.fill = GridBagConstraints.HORIZONTAL; gc.weightx = 0.5; gc.gridx = 1; gc.gridy = 1; add(interfaceBox, gc); gc.fill = GridBagConstraints.HORIZONTAL; gc.weightx = 0.5; gc.weighty = 10; gc.gridx = 2; gc.gridy = 1; add(generatedTextArea, gc); //third row gc.fill = GridBagConstraints.HORIZONTAL; gc.weightx = 0.5; gc.weighty = 10; gc.gridx =0; gc.gridy = 2; add(Ap, gc); } }
Here is a screen shot of what I have so far:
GBL.jpg
The ActivityPanel has a set width and height of 250 x 450 with a red background(which I did just to see what was going on).
I tried using the GridBagConstraint Constants to no avail.
is there a way to set a margin or padding in between cells?
basically I am lost, I have to use the gridbaglayout, I went through the demo at docs.oracle.com, if someone could point me in the right direction I would appreciate it.
Thanks in advance!