protected GridBagConstraints getDefaultConstraints() { GridBagConstraints constraints = new GridBagConstraints(); constraints.weightx = 1.0; constraints.weighty = 1.0; constraints.gridheight = 1; // One row high // Insets() args are top, left, bottom, right constraints.insets = new Insets(4, 4, 4, 4); // fill of NONE means do not change size constraints.fill = GridBagConstraints.NONE; // WEST means align left constraints.anchor = GridBagConstraints.WEST; return constraints; }
private void initializeComponents () { JPanel contentPanel = getContentPanel(); { JLabel label = new JLabel("Value:"); contentPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 0, 0)); } { valueSpinner = new JSpinner(new SpinnerNumberModel(new Float(0), new Float(-99999), new Float(99999), new Float(0.1f))); contentPanel.add(valueSpinner, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } } }
public static void addContent( JPanel panel, int row, int column, JComponent component, boolean addBorders, int anchor, int fill, float wx, float wy){ if(addBorders) component.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, java.awt.Color.black)); panel.add(component, new GridBagConstraints(column, row, 1, 1, wx, wy, anchor, fill, new Insets(0, 0, 0, 0), 0, 0)); }
import java.awt.*; import javax.swing.*; public class Test extends JFrame { public static void main(String arg[]) { JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); JPanel gb = new JPanel(new GridBagLayout()); JLabel content = new JLabel("Some text"); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.NORTH; gbc.weighty = 1; gb.add(content, gbc); // gbc is containing the GridBagConstraints frame.add(gb, BorderLayout.CENTER); frame.setVisible(true); } }
public GridBagHelper(Container container, double[] weights) { this.container = container; this.weights = weights; gridbag = new GridBagLayout(); container.setLayout(gridbag); c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; }
tabPane.addTab(title, tabBody); int index = tabPane.indexOfTab(title); JPanel pnlTab = new JPanel(new GridBagLayout()); pnlTab.setOpaque(false); JLabel lblTitle = new JLabel(title); JButton btnClose = new JButton("x"); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1; pnlTab.add(lblTitle, gbc); gbc.gridx++; gbc.weightx = 0; pnlTab.add(btnClose, gbc); tabPane.setTabComponentAt(index, pnlTab); btnClose.addActionListener(myCloseActionHandler);
private void uiLayout () { title.setLayout(new GridLayout(1, 2)); minimize.setPreferredSize(new Dimension(50, 26)); exit.setPreferredSize(new Dimension(50, 26)); title.add(minimize); title.add(exit); topBar.setLayout(new GridLayout(1, 1)); topBar.add(windowLabel, new GridBagConstraints(0, 0, 0, 0, 0, 0, NORTHWEST, VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); setLayout(new GridBagLayout()); add(topBar, new GridBagConstraints(0, 0, 0, 0, 0, 0, NORTH, HORIZONTAL, new Insets(0, 0, 0, 100), 0, 10)); add(title, new GridBagConstraints(0, 0, 0, 0, 0, 0, NORTHEAST, NONE, new Insets(0, 0, 0, 0), 0, 0)); add(logo, new GridBagConstraints(0, 0, 1, 1, 1, 0, CENTER, HORIZONTAL, new Insets(40, 6, 6, 6), 0, 0)); add(form, new GridBagConstraints(0, 1, 1, 1, 1, 0, CENTER, HORIZONTAL, new Insets(6, 6, 0, 6), 0, 0)); add(buttonPanel, new GridBagConstraints(0, 2, 1, 1, 0, 0, CENTER, NONE, new Insets(0, 0, 0, 0), 0, 0)); add(scrollPane, new GridBagConstraints(0, 3, 1, 1, 1, 1, CENTER, BOTH, new Insets(6, 6, 6, 6), 0, 0)); }
private ExEntryPanel() { setBorder(BorderFactory.createEtchedBorder()); label = new JLabel(" "); entry = new ExTextField(); entry.setBorder(null); setFontForElements(); setForeground(entry.getForeground()); setBackground(entry.getBackground()); label.setForeground(entry.getForeground()); label.setBackground(entry.getBackground()); GridBagLayout layout = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); setLayout(layout); gbc.gridx = 0; layout.setConstraints(this.label, gbc); add(this.label); gbc.gridx = 1; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(entry, gbc); add(entry); setBorder(BorderFactory.createEtchedBorder()); adapter = new ComponentAdapter() { public void componentResized(ComponentEvent e) { positionPanel(); } }; }
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); for (int row = 0; row < 5; row++) { for (int col = 0; col < 5; col++) { add(cellPane, gbc);
private void initializeComponents () { JPanel contentPanel = getContentPanel(); { JLabel label = new JLabel("Value:"); contentPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 0, 0)); } { valueSpinner = new JSpinner(new SpinnerNumberModel(new Float(0), new Float(-99999), new Float(99999), new Float(0.1f))); contentPanel.add(valueSpinner, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } } }
void addEditorRow (JPanel row) { row.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, java.awt.Color.black)); editRowsPanel.add(row, new GridBagConstraints(0, -1, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); }
frame.setTitle("Test vertical alignement"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); JLabel label1 = new JLabel("label1"); JLabel label2 = new JLabel("label2"); panel.add(label1, gbc); panel.add(label2, gbc); frame.add(panel); frame.setSize(300, 300); frame.setVisible(true);
public SettingsGroup(String title) { setBorder(BorderFactory.createTitledBorder(title)); setLayout(new GridBagLayout()); c = new GridBagConstraints(); c.insets = new Insets(5, 5, 5, 5); c.weighty = 1.0; }
this.setLayout(new GridBagLayout()); this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(),"Search pattern: ")); JLabel bigEmptyLabel = new JLabel(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER;
private void initializeComponents () { JPanel contentPanel = getContentPanel(); { JLabel label = new JLabel("Min:"); contentPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 0, 0)); } { minSlider = new Slider(0, 0, 99999, 1, 0, 500); contentPanel.add(minSlider, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } { JLabel label = new JLabel("Max:"); contentPanel.add(label, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 0, 6), 0, 0)); } { maxSlider = new Slider(0, 0, 99999, 1, 0, 500); contentPanel.add(maxSlider, new GridBagConstraints(3, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } } }
void addRow(JPanel panel, JPanel row, float wx, float wy) { row.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, java.awt.Color.black)); panel.add(row, new GridBagConstraints(0, -1, 1, 1, wx, wy, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); }
public ColorSlider (Color[] paletteColors) { this.paletteColors = paletteColors; setLayout(new GridBagLayout()); { slider = new JSlider(0, 1000, 0); slider.setPaintTrack(false); add(slider, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 6), 0, 0)); } { colorPicker = new ColorPicker(); add(colorPicker, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 6), 0, 0)); } slider.addChangeListener(new ChangeListener() { public void stateChanged (ChangeEvent event) { colorPicked(); } }); }
private void initializeComponents () { JPanel contentPanel = getContentPanel(); { JLabel label = new JLabel("Min:"); contentPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 0, 0)); } { minSlider = new Slider(0, 0, 99999, 1, 0, 500); contentPanel.add(minSlider, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } { JLabel label = new JLabel("Max:"); contentPanel.add(label, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 0, 6), 0, 0)); } { maxSlider = new Slider(0, 0, 99999, 1, 0, 500); contentPanel.add(maxSlider, new GridBagConstraints(3, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } } }
void addRow(JPanel panel, JPanel row, float wx, float wy) { row.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, java.awt.Color.black)); panel.add(row, new GridBagConstraints(0, -1, 1, 1, wx, wy, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); }
public ColorSlider (Color[] paletteColors) { this.paletteColors = paletteColors; setLayout(new GridBagLayout()); { slider = new JSlider(0, 1000, 0); slider.setPaintTrack(false); add(slider, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 6), 0, 0)); } { colorPicker = new ColorPicker(); add(colorPicker, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 6), 0, 0)); } slider.addChangeListener(new ChangeListener() { public void stateChanged (ChangeEvent event) { colorPicked(); } }); }