Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args){
- SwingUtilities.invokeLater(new Runnable(){
- public void run(){
- LeftoverExample.createGUI();
- }
- });
- }
- public static void createGUI(){
- JFrame jF = new JFrame();
- jF.setSize(new Dimension(500,500));
- jF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //GBL Example
- JPanel gBLExamplePanel = new JPanel();
- GridBagLayout gBL = new GridBagLayout();
- gBL.columnWidths = new int[]{0};
- gBL.rowHeights = new int[]{50};
- gBLExamplePanel.setLayout(gBL);
- //Initial Constraints
- GridBagConstraints gBC = new GridBagConstraints();
- gBC.fill = GridBagConstraints.BOTH;
- gBC.gridx = 0;
- gBC.gridy = 0;
- gBC.weightx = 1;
- gBC.weighty = 0;
- gBC.insets = new Insets(0, 0, 0, 0);
- //Add to GBL Panel
- LeftoverExample.addButtons(gBLExamplePanel, gBC);
- LeftoverExample.addButtons(gBLExamplePanel, gBC);
- LeftoverExample.addButtons(gBLExamplePanel, gBC);
- //BoxLayout Example
- JPanel boxLayoutExamplePanel = new JPanel();
- boxLayoutExamplePanel.setLayout(new BoxLayout(boxLayoutExamplePanel, BoxLayout.X_AXIS));
- //Add to BoxLayout Panel
- LeftoverExample.addButtons(boxLayoutExamplePanel);
- LeftoverExample.addButtons(boxLayoutExamplePanel);
- LeftoverExample.addButtons(boxLayoutExamplePanel);
- //Add Panels to ContentPane
- jF.getContentPane().add(gBLExamplePanel);
- jF.getContentPane().add(boxLayoutExamplePanel, BorderLayout.SOUTH);
- //Final
- jF.setVisible(true);
- }
- private static JButton createButton(Color c){
- JButton jB = new JButton();
- jB.setBackground(c);
- jB.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
- return jB;
- }
- private static void addButtons(JComponent jC, GridBagConstraints gBC){
- //Create Buttons
- Color[] colorA = {Color.RED, Color.BLUE, Color.BLACK, Color.GREEN};
- for(Color c : colorA){
- jC.add(LeftoverExample.createButton(c), gBC);
- gBC.gridx++;
- }
- }
- private static void addButtons(JComponent jC){
- //Create Buttons
- Color[] colorA = {Color.BLUE, Color.BLACK, Color.GREEN, Color.RED};
- for(Color c : colorA){
- jC.add(LeftoverExample.createButton(c));
- }
- }
Add Comment
Please, Sign In to add comment