Here comes the code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class gridTest {
public static void main(String[] args) {
JFrame frame=new JFrame("Grid Test");
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JPanel panel=new JPanel(new GridBagLayout());
GridBagConstraints c=new GridBagConstraints();
JLabel label1=new JLabel("Label 1");
c.gridx=0;
c.gridy=0;
panel.add(label1, c);
JLabel label2=new JLabel("Label 2");
c.gridx=0;
c.gridy=1;
panel.add(label2, c);
JLabel label3=new JLabel("Label 3");
c.gridx=1;
c.gridy=0;
panel.add(label3, c);
JLabel label4=new JLabel("Label 4");
c.gridx=1;
c.gridy=1;
panel.add(label4, c);
frame.add(panel);
}
}
The problem is when I compile it there is not a single error shown, I don't know whats wrong.

New Topic/Question
Reply



MultiQuote




|