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:EditorPaneExample3.java
public EditorPaneExample3() { super("JEditorPane Example 3"); 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;//from w w w.jav a 2s.c om 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.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.weightx = 1.0; 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); getContentPane().add(panel, "South"); // Change page based on text field textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String url = textField.getText(); try { // Try to display the page 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); pane.setPage(url); loadingState.setText("Loaded"); loadedType.setText(pane.getContentType()); } catch (IOException e) { JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); } } }); }
From source file:EditorPaneExample4.java
public EditorPaneExample4() { super("JEditorPane Example 4"); 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;/*from w w w. j av a2s . 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.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.weightx = 1.0; 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); 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); pane.setPage(url); loadedType.setText(pane.getContentType()); } 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")) { loadingState.setText("Page loaded."); textField.setEnabled(true); // Allow entry of new URL setCursor(Cursor.getDefaultCursor()); } } }); }
From source file:de.fhg.iais.asc.ui.parts.TopLabeledElementJPanelBuilder.java
public TopLabeledElementJPanelBuilder(String prefix) { this.prefix = (StringUtils.isEmpty(prefix)) ? "" : (prefix + "."); this.cLabel.gridx = 0; this.cLabel.gridy = 0; this.cLabel.weightx = 0.1; this.cLabel.weighty = WEIGHTY_LABEL; this.cLabel.fill = GridBagConstraints.HORIZONTAL; this.cElement.gridx = 0; this.cElement.gridy = 1; this.cLabel.weightx = 0.1; this.cElement.weighty = WEIGHTY_ELEMENT; this.cElement.fill = GridBagConstraints.HORIZONTAL; }
From source file:com.github.pemapmodder.pocketminegui.gui.server.ConsolePanel.java
public ConsolePanel(ServerMainActivity activity) { this.activity = activity; setLayout(new GridBagLayout()); setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 10)); title = new JLabel("PocketMine-MP"); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.HORIZONTAL; c.weighty = 0.1;/*from ww w .j ava2 s.c o m*/ add(title, c); stdout = new JEditorPane(); stdout.setContentType("text/html"); stdout.setText("<html><body style='font-family: monospace; color: #FFFFFF;'><p id='p'></p></body></html>"); doc = (HTMLDocument) stdout.getDocument(); para = doc.getElement("p"); // stdout.setEditable(false); // People NEED to see this to feel happy stdout.setForeground(Color.WHITE); stdout.setBackground(Color.BLACK); Style style = doc.getStyleSheet().addStyle(null, null); // style.addAttribute(StyleConstants.Foreground, Color.WHITE); // style.addAttribute(StyleConstants.Background, Color.RED); doc.setParagraphAttributes(para.getStartOffset(), 1, style, true); stdout.setBorder(BorderFactory.createDashedBorder(new Color(0x80, 0x80, 0x80))); c.gridy = 1; c.weightx = 0.9; c.weighty = 0.9; c.weighty = 0.6; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.NORTH; add(stdout, c); Timer timer = new Timer(50, e -> updateConsole()); timer.start(); }
From source file:EditorPaneExample10A.java
public EditorPaneExample10A() { super("JEditorPane Example 10 - using getIterator"); 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;/* ww w . j av a2 s . c om*/ 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; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); 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 combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); try { // Check if the new page and the old // page are the same. URL url; if (selection instanceof URL) { url = (URL) selection; } else { url = new URL((String) selection); } URL loadedURL = pane.getPage(); if (loadedURL != null && loadedURL.sameFile(url)) { return; } // Try to display the page urlCombo.setEnabled(false); // Disable input urlCombo.paintImmediately(0, 0, urlCombo.getSize().width, urlCombo.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(url); loadComplete(); pane.setDocument(doc); displayLoadTime(); populateCombo(findLinks(doc, null)); enableInput(); } } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", selection.toString() }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); enableInput(); } } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); enableInput(); } } }); }
From source file:org.mutoss.gui.dialogs.TellAboutOnlineUpate.java
public TellAboutOnlineUpate(JFrame mainFrame) { super(mainFrame, "License", true); getContentPane().setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); JTextArea jta3 = new JTextArea("Crossover\n" + "Copyright (C) 2010-2014 by K. Rohmeyer\n" + "\n" + "This program is free software; you can redistribute it and/or\n" + "modify it under the terms of the GNU General Public License\n" + "as published by the Free Software Foundation, Version 2.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details. It is included\n" + "in the R distribution (in directory share/licenses) or can be\n" + "found at: http://www.gnu.org/licenses/\n"); jta3.setFont(new Font("Monospaced", Font.PLAIN, 10)); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0;/*from w w w . j a v a 2 s . c om*/ c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 10; c.ipady = 10; c.weightx = 1; c.weighty = 1; jcbHaveRead.setSelected(Configuration.getInstance().getGeneralConfig().checkOnline()); c.gridx = 0; c.weighty = 1; JScrollPane js = new JScrollPane(jta3); (getContentPane()).add(js, c); c.weighty = 0; c.gridy++; (getContentPane()).add(jcbHaveRead, c); Container cp = getContentPane(); cp = WidgetFactory.makeDialogPanelWithButtons(cp, new OKButtonPane(), this); setContentPane(cp); pack(); setLocationRelativeTo(mainFrame); setVisible(true); }
From source file:de.fhg.iais.asc.ui.components.panel.LeftLabeledElementJPanel.java
public LeftLabeledElementJPanel(String prefix) { super(new GridBagLayout()); this.prefix = (StringUtils.isEmpty(prefix)) ? "" : (prefix + "."); this.cLabel.gridx = 0; this.cLabel.gridy = 0; this.cLabel.weightx = WEIGHTX_LABEL; this.cLabel.fill = GridBagConstraints.HORIZONTAL; this.cElement.gridx = 1; this.cElement.gridwidth = 2; this.cElement.gridy = 0; this.cElement.weightx = WEIGHTX_ELEMENT; this.cElement.fill = GridBagConstraints.HORIZONTAL; }
From source file:org.altusmetrum.altosuilib_2.AltosUIEnable.java
public void add(String name, AltosUIGrapher grapher, boolean enabled) { GraphElement e = new GraphElement(name, grapher, enabled); GridBagConstraints c = new GridBagConstraints(); /* Add element */ c = new GridBagConstraints(); c.gridx = x;// ww w . j a v a 2s . c o m c.gridy = y; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.CENTER; c.insets = ir; add(e.enable, c); /* Next row */ y++; if (y == max_rows) { x++; y = 0; } }
From source file:events.FocusEventDemo.java
public void addComponentsToPane(final Container pane) { GridBagLayout gridbag = new GridBagLayout(); pane.setLayout(gridbag);// w w w. j a va 2s. co 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:cz.alej.michalik.totp.client.OtpPanel.java
/** * Pid jeden panel se zznamem/*from w w w . j av a2s . co m*/ * * @param raw_data * Data z Properties * @param p * Properties * @param index * Index zznamu - pro vymazn */ public OtpPanel(String raw_data, final Properties p, final int index) { // Data jsou oddlena stednkem final String[] data = raw_data.split(";"); // this.setBackground(App.COLOR); this.setLayout(new GridBagLayout()); // Mkov rozloen prvk GridBagConstraints c = new GridBagConstraints(); this.setMaximumSize(new Dimension(Integer.MAX_VALUE, 100)); // Tla?tko pro zkoprovn hesla final JButton passPanel = new JButton(""); passPanel.setFont(passPanel.getFont().deriveFont(App.FONT_SIZE)); passPanel.setBackground(App.COLOR); // Zabere celou ku c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 100; this.add(passPanel, c); passPanel.setText(data[0]); // Tla?tko pro smazn JButton delete = new JButton("X"); try { String path = "/material-design-icons/action/drawable-xhdpi/ic_delete_black_24dp.png"; Image img = ImageIO.read(App.class.getResource(path)); delete.setIcon(new ImageIcon(img)); delete.setText(""); } catch (Exception e) { System.out.println("Icon not found"); } delete.setFont(delete.getFont().deriveFont(App.FONT_SIZE)); delete.setBackground(App.COLOR); // Zabere kousek vpravo c.fill = GridBagConstraints.NONE; c.weightx = 0.5; c.anchor = GridBagConstraints.EAST; this.add(delete, c); // Akce pro vytvoen a zkoprovn hesla do schrnky passPanel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Generuji kod pro " + data[1]); System.out.println(new Base32().decode(data[1].getBytes()).length); clip.set(new TOTP(new Base32().decode(data[1].getBytes())).toString()); System.out.printf("Kd pro %s je ve schrnce\n", data[0]); passPanel.setText("Zkoprovno"); // Zobraz zprvu na 1 vteinu int time = 1000; // Animace zobrazen zprvy po zkoprovn final Timer t = new Timer(time, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { passPanel.setText(data[0]); } }); t.start(); t.setRepeats(false); } }); // Akce pro smazn panelu a uloen zmn delete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.printf("Odstrann %s s indexem %d\n", data[0], index); p.remove(String.valueOf(index)); App.saveProperties(); App.loadProperties(); } }); }