List of usage examples for java.awt GridBagConstraints HORIZONTAL
int HORIZONTAL
To view the source code for java.awt GridBagConstraints HORIZONTAL.
Click Source Link
From source file:cz.alej.michalik.totp.client.AddDialog.java
public AddDialog(final Properties prop) { System.out.println("Pridat novy zaznam"); this.setTitle("Pidat"); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setMinimumSize(new Dimension(600, 150)); this.setLocationByPlatform(true); // Panel pro vytvoen okraj JPanel panel = new JPanel(); panel.setBorder(new EmptyBorder(10, 10, 10, 10)); panel.setLayout(new GridBagLayout()); // Vlastnosti pro popisky GridBagConstraints label = new GridBagConstraints(); label.insets = new Insets(2, 2, 2, 2); label.fill = GridBagConstraints.NONE; label.weightx = 1;/*w ww . j ava2 s .c o m*/ // Vlastnosti pro pole GridBagConstraints field = new GridBagConstraints(); field.insets = new Insets(2, 2, 2, 2); field.fill = GridBagConstraints.HORIZONTAL; field.weightx = 10; this.add(panel); // Nastavm ikonu okna try { String path = "/material-design-icons/content/drawable-xhdpi/ic_create_black_48dp.png"; this.setIconImage(Toolkit.getDefaultToolkit().getImage(App.class.getResource(path))); } catch (NullPointerException ex) { System.out.println("Icon not found"); } // Pole pro pojmenovn zznamu // Ikona ImageIcon icon = null; try { String path = "/material-design-icons/editor/drawable-xhdpi/ic_format_color_text_black_18dp.png"; icon = new ImageIcon(App.class.getResource(path)); } catch (NullPointerException ex) { System.out.println("Icon not found"); } // Pidn labelu s ikonou a nastavm velikost psma label.gridy = 0; field.gridy = 0; JLabel nameLabel = new JLabel("Nzev: ", icon, JLabel.CENTER); nameLabel.setFont(nameLabel.getFont().deriveFont(App.FONT_SIZE * 2 / 3)); panel.add(nameLabel, label); // Pole pro jmno final JTextField name = new JTextField(); name.setMaximumSize(new Dimension(Integer.MAX_VALUE, 50)); name.setFont(name.getFont().deriveFont(App.FONT_SIZE * 2 / 3)); panel.add(name, field); // Pole pro zadn sdlenho hesla // Ikona icon = null; try { String path = "/material-design-icons/hardware/drawable-xhdpi/ic_security_black_18dp.png"; icon = new ImageIcon(App.class.getResource(path)); } catch (NullPointerException ex) { System.out.println("Icon not found"); } // Pidn labelu s ikonou label.gridy = 1; field.gridy = 1; JLabel secretLabel = new JLabel("Heslo: ", icon, JLabel.CENTER); secretLabel.setFont(secretLabel.getFont().deriveFont(App.FONT_SIZE * 2 / 3)); panel.add(secretLabel, label); // Pole pro heslo final JTextField secret = new JTextField(); secret.setMaximumSize(new Dimension(Integer.MAX_VALUE, 50)); secret.setFont(secret.getFont().deriveFont(App.FONT_SIZE * 2 / 3)); panel.add(secret, field); this.setVisible(true); // Akce pro odesln formule ActionListener submit = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { submit(prop, name, secret, false); } }; // Pi stisku klvesy Enter odele formul name.addActionListener(submit); secret.addActionListener(submit); // Pi zmn pole pro heslo se vstup okamit zformtuje final Runnable sanitizer = new Runnable() { @Override public void run() { sanitize(secret); } }; secret.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { } @Override public void insertUpdate(DocumentEvent e) { SwingUtilities.invokeLater(sanitizer); } @Override public void changedUpdate(DocumentEvent e) { } }); // Pi zaven okna odele formul this.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { // Ignorovat } @Override public void windowIconified(WindowEvent e) { // Ignorovat } @Override public void windowDeiconified(WindowEvent e) { // Ignorovat } @Override public void windowDeactivated(WindowEvent e) { // Ignorovat } @Override public void windowClosing(WindowEvent e) { // Odeslat submit(prop, name, secret, true); } @Override public void windowClosed(WindowEvent e) { // Ignorovat } @Override public void windowActivated(WindowEvent e) { // Ignorovat } }); }
From source file:cool.pandora.modeller.ui.jpanel.base.NewBagFrame.java
/** * layoutBagVersionSelection./*ww w .j a v a2 s. c o m*/ * * @param contentPane JPanel * @param row int */ private static void layoutBagVersionSelection(final JPanel contentPane, final int row) { // contents GridBagConstraints glbc; final JLabel spacerLabel = new JLabel(); glbc = LayoutUtil.buildGridBagConstraints(0, row, 1, 1, 5, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); glbc = LayoutUtil.buildGridBagConstraints(1, row, 1, 1, 40, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); glbc = LayoutUtil.buildGridBagConstraints(2, row, 1, 1, 40, 50, GridBagConstraints.NONE, GridBagConstraints.EAST); contentPane.add(spacerLabel, glbc); }
From source file:FocusEventDemo.java
public void addComponentsToPane(final Container pane) { GridBagLayout gridbag = new GridBagLayout(); pane.setLayout(gridbag);/*from w ww . j a v a 2 s. c o m*/ GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; // Make column as wide as possible. JTextField textField = new JTextField("A TextField"); textField.setMargin(new Insets(0, 2, 0, 2)); textField.addFocusListener(this); gridbag.setConstraints(textField, c); add(textField); c.weightx = 0.1; // Widen every other column a bit, when possible. c.fill = GridBagConstraints.NONE; JLabel label = new JLabel("A Label"); label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); label.addFocusListener(this); gridbag.setConstraints(label, c); add(label); String comboPrefix = "ComboBox Item #"; final int numItems = 15; Vector<String> vector = new Vector<String>(numItems); for (int i = 0; i < numItems; i++) { vector.addElement(comboPrefix + i); } JComboBox comboBox = new JComboBox(vector); comboBox.addFocusListener(this); gridbag.setConstraints(comboBox, c); add(comboBox); c.gridwidth = GridBagConstraints.REMAINDER; JButton button = new JButton("A Button"); button.addFocusListener(this); gridbag.setConstraints(button, c); add(button); c.weightx = 0.0; c.weighty = 0.1; c.fill = GridBagConstraints.BOTH; String listPrefix = "List Item #"; Vector<String> listVector = new Vector<String>(numItems); for (int i = 0; i < numItems; i++) { listVector.addElement(listPrefix + i); } JList list = new JList(listVector); list.setSelectedIndex(1); // It's easier to see the focus change // if an item is selected. list.addFocusListener(this); JScrollPane listScrollPane = new JScrollPane(list); gridbag.setConstraints(listScrollPane, c); add(listScrollPane); c.weighty = 1.0; // Make this row as tall as possible. c.gridheight = GridBagConstraints.REMAINDER; // Set up the area that reports focus-gained and focus-lost events. display = new JTextArea(); display.setEditable(false); // The setRequestFocusEnabled method prevents a // component from being clickable, but it can still // get the focus through the keyboard - this ensures // user accessibility. display.setRequestFocusEnabled(false); display.addFocusListener(this); JScrollPane displayScrollPane = new JScrollPane(display); gridbag.setConstraints(displayScrollPane, c); add(displayScrollPane); setPreferredSize(new Dimension(450, 450)); ((JPanel) pane).setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:org.mbs3.juniuploader.gui.pnlWoWDirectories.java
private void initGUI() { try {/*from w ww. j a v a 2 s .c om*/ GridBagLayout thisLayout = new GridBagLayout(); this.setLayout(thisLayout); { /*dlmWoWDirs = new DefaultListModel(); Vector dirs = frmMain.getUploader().getLocalSystem().getWowDirectories(); Iterator i = dirs.iterator(); while(i.hasNext()) dlmWoWDirs.addElement(i.next()); */ lstWoWDirs = new JList(); //dlmWoWDirs); lstWoWDirs.setModel(frmMain.wowDirectories); this.add(lstWoWDirs, new GridBagConstraints(1, 1, 1, 4, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); lstWoWDirs.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED)); } { btnAddDirectory = new JButton(); this.add(btnAddDirectory, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); btnAddDirectory.setText("Add Directory to List"); btnAddDirectory.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnAddDirectoryActionPerformed(evt); } }); } { btnRemoveSelected = new JButton(); this.add(btnRemoveSelected, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); btnRemoveSelected.setText("Remove Selected Directory"); btnRemoveSelected.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnRemoveSelectedActionPerformed(evt); } }); } thisLayout.rowWeights = new double[] { 0.0, 0.1, 0.1, 0.0, 0.1, 0.0 }; thisLayout.rowHeights = new int[] { 9, 20, 7, 8, 7, 9 }; thisLayout.columnWeights = new double[] { 0.0, 0.1, 0.0, 0.0, 0.0 }; thisLayout.columnWidths = new int[] { 11, 20, 9, 217, 11 }; this.setPreferredSize(new java.awt.Dimension(614, 382)); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraphGUI.java
/** * Load the GUI./*from ww w . j a v a 2 s .c o m*/ */ protected final void initGUI() { this.setLayout(new BorderLayout()); this.add(createOptionPanel(), BorderLayout.NORTH); pnlGraph = new ChartPanel(null); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1; constraints.weighty = 1; constraints.anchor = GridBagConstraints.NORTHWEST; panel.add(pnlGraph, constraints); panel.setBackground(Color.white); this.add(panel, BorderLayout.CENTER); }
From source file:org.openmicroscopy.shoola.agents.metadata.util.FilesetInfoDialog.java
/** * Sets the data to display//ww w . ja v a 2 s .c om * * @param set * The fileset which paths should be shown * @param importType * The import type */ public void setData(Set<FilesetData> set, ImportType importType) { if (set == null) return; JPanel content = new JPanel(); content.setLayout(new GridBagLayout()); content.setBackground(UIUtilities.BACKGROUND_COLOR); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.NORTHEAST; if (CollectionUtils.isEmpty(set)) { JLabel l = new JLabel("No information available."); l.setBackground(UIUtilities.BACKGROUND_COLOR); content.add(l, c); } else { int size = 0; FilesetData fsd = set.iterator().next(); if (Fileset.class.isAssignableFrom(fsd.asIObject().getClass())) { size = ((Fileset) fsd.asIObject()).sizeOfUsedFiles(); } String txt = size <= 1 ? "Image file" : "Image files"; JLabel l = new JLabel(size + " " + txt); l.setBackground(UIUtilities.BACKGROUND_COLOR); content.add(l, c); c.gridy++; JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); sep.setBackground(UIUtilities.BACKGROUND_COLOR); content.add(sep, c); c.gridy++; String header = (importType == ImportType.HARDLINK || importType == ImportType.SOFTLINK) ? "Imported with <b>--transfer=" + importType.getSymbol() + "</b> from:" : "Imported from:"; ExpandableTextPane t1 = new ExpandableTextPane(); t1.setBackground(UIUtilities.BACKGROUND_COLOR); t1.setText(header + "<br/>" + getOriginPaths(set)); content.add(t1, c); c.gridy++; JSeparator sep2 = new JSeparator(JSeparator.HORIZONTAL); sep2.setBackground(UIUtilities.BACKGROUND_COLOR); content.add(sep2, c); c.gridy++; ExpandableTextPane t2 = new ExpandableTextPane(); t2.setBackground(UIUtilities.BACKGROUND_COLOR); t2.setText("Path on server:<br/>" + getServerPaths(set)); content.add(t2, c); } setCanvas(new JScrollPane(content)); }
From source file:GetOpenProperties.java
public void init() { //Set up the layout. GridBagLayout gridbag = new GridBagLayout(); setLayout(gridbag);// w ww . j a va2s . c om GridBagConstraints labelConstraints = new GridBagConstraints(); GridBagConstraints valueConstraints = new GridBagConstraints(); labelConstraints.anchor = GridBagConstraints.WEST; labelConstraints.ipadx = 10; valueConstraints.fill = GridBagConstraints.HORIZONTAL; valueConstraints.gridwidth = GridBagConstraints.REMAINDER; valueConstraints.weightx = 1.0; //Extra space to values column. //Set up the Label arrays. Label[] names = new Label[numProperties]; values = new Label[numProperties]; String firstValue = "not read yet"; for (int i = 0; i < numProperties; i++) { names[i] = new Label(propertyNames[i]); gridbag.setConstraints(names[i], labelConstraints); add(names[i]); values[i] = new Label(firstValue); gridbag.setConstraints(values[i], valueConstraints); add(values[i]); } new Thread(this, "Loading System Properties").start(); }
From source file:EditorPaneExample9.java
public EditorPaneExample9() { super("JEditorPane Example 9"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/* w ww.j a v a 2s.co m*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; textField = new JTextField(32); panel.add(textField, c); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Change page based on text field textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String url = textField.getText(); try { // Check if the new page and the old // page are the same. URL newURL = new URL(url); URL loadedURL = pane.getPage(); if (loadedURL != null && loadedURL.sameFile(newURL)) { return; } // Try to display the page textField.setEnabled(false); // Disable input textField.paintImmediately(0, 0, textField.getSize().width, textField.getSize().height); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Busy cursor loadingState.setText("Loading..."); loadingState.paintImmediately(0, 0, loadingState.getSize().width, loadingState.getSize().height); loadedType.setText(""); loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height); timeLabel.setText(""); timeLabel.paintImmediately(0, 0, timeLabel.getSize().width, timeLabel.getSize().height); startTime = System.currentTimeMillis(); // Choose the loading method if (onlineLoad.isSelected()) { // Usual load via setPage pane.setPage(url); loadedType.setText(pane.getContentType()); } else { pane.setContentType("text/html"); loadedType.setText(pane.getContentType()); if (loader == null) { loader = new HTMLDocumentLoader(); } HTMLDocument doc = loader.loadDocument(new URL(url)); loadComplete(); pane.setDocument(doc); displayLoadTime(); } } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); textField.setEnabled(true); setCursor(Cursor.getDefaultCursor()); } } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); } } }); }
From source file:FocusEventDemo.java
public FocusEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; //Make column as wide as possible. JTextField textField = new JTextField("A TextField"); textField.setMargin(new Insets(0, 2, 0, 2)); textField.addFocusListener(this); gridbag.setConstraints(textField, c); add(textField);//from w w w. j a v a2s.c o m c.weightx = 0.1; //Widen every other column a bit, when possible. c.fill = GridBagConstraints.NONE; JLabel label = new JLabel("A Label"); label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); label.addFocusListener(this); gridbag.setConstraints(label, c); add(label); String comboPrefix = "ComboBox Item #"; final int numItems = 15; Vector vector = new Vector(numItems); for (int i = 0; i < numItems; i++) { vector.addElement(comboPrefix + i); } JComboBox comboBox = new JComboBox(vector); comboBox.addFocusListener(this); gridbag.setConstraints(comboBox, c); add(comboBox); c.gridwidth = GridBagConstraints.REMAINDER; JButton button = new JButton("A Button"); button.addFocusListener(this); gridbag.setConstraints(button, c); add(button); c.weightx = 0.0; c.weighty = 0.1; c.fill = GridBagConstraints.BOTH; String listPrefix = "List Item #"; Vector listVector = new Vector(numItems); for (int i = 0; i < numItems; i++) { listVector.addElement(listPrefix + i); } JList list = new JList(listVector); list.setSelectedIndex(1); //It's easier to see the focus change //if an item is selected. list.addFocusListener(this); JScrollPane listScrollPane = new JScrollPane(list); //We want to prevent the list's scroll bars //from getting the focus - even with the keyboard. //Note that in general we prefer setRequestFocusable //over setFocusable for reasons of accessibility, //but this is to work around bug #4866958. listScrollPane.getVerticalScrollBar().setFocusable(false); listScrollPane.getHorizontalScrollBar().setFocusable(false); gridbag.setConstraints(listScrollPane, c); add(listScrollPane); c.weighty = 1.0; //Make this row as tall as possible. c.gridheight = GridBagConstraints.REMAINDER; //Set up the area that reports focus-gained and focus-lost events. display = new JTextArea(); display.setEditable(false); //The method setRequestFocusEnabled prevents a //component from being clickable, but it can still //get the focus through the keyboard - this ensures //user accessibility. display.setRequestFocusEnabled(false); display.addFocusListener(this); JScrollPane displayScrollPane = new JScrollPane(display); //Work around for bug #4866958. displayScrollPane.getHorizontalScrollBar().setFocusable(false); displayScrollPane.getVerticalScrollBar().setFocusable(false); gridbag.setConstraints(displayScrollPane, c); add(displayScrollPane); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); this.add(new JLabel(getLabelFor("CODE"), SwingConstants.RIGHT), c); c.gridx++;//from www . ja v a2 s . c o m c.weightx = 1; c.fill = GridBagConstraints.NONE; final JTextField code = new JTextField(6); this.add(code, c); c.gridx = 0; c.gridy++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c); c.gridx++; c.weightx = 1; final JTextField nom = new JTextField(25); this.add(nom, c); c.gridy++; c.anchor = GridBagConstraints.NORTHWEST; c.weighty = 1; final JCheckBox checkBox = new JCheckBox(getLabelFor("TYPE_BANQUE")); this.add(checkBox, c); this.addView(nom, "NOM", REQ); this.addView(code, "CODE", REQ); this.addView(checkBox, "TYPE_BANQUE"); } @Override protected SQLRowValues createDefaults() { final SQLRowValues rowVals = new SQLRowValues(getTable()); rowVals.put("TYPE_BANQUE", Boolean.TRUE); return rowVals; } }; }