#navi(contents-page-name): No such page: ST

FrontPage

Terai Atsuhiro 2021-10-12 (火) 10:34:36

BorderLayout

http://terai.s55.xrea.com/swing/gridbag/screenshot.png

GridBagLayout

public class PanelFactory{
  public JPanel createCompButtonPanel(JComponent cmp, JButton btn, String str){
    GridBagConstraints c = new GridBagConstraints();
    JPanel panel = new JPanel(new GridBagLayout());
    
    c.gridheight = 1;
    c.gridwidth  = 1;
    c.gridy = 0;
    
    c.gridx = 0;
    c.weightx = 0.0;
    c.insets = new Insets(5, 5, 5, 0);
    c.anchor = GridBagConstraints.WEST;
    panel.add(new JLabel(str), c);
    
    c.gridx = 1;
    c.weightx = 1.0;
    c.insets = new Insets(5, 5, 5, 0);
    c.fill = GridBagConstraints.HORIZONTAL;
    panel.add(cmp, c);
    
    c.gridx = 2;
    c.weightx = 0.0;
    c.insets = new Insets(5, 5, 5, 5);
    c.anchor = GridBagConstraints.WEST;
    panel.add(btn, c);
    
    return panel;
  }
}

GridBagLayout