List of usage examples for java.awt GridBagConstraints NONE
int NONE
To view the source code for java.awt GridBagConstraints NONE.
Click Source Link
From source file:com.game.ui.views.PlayerEditor.java
public void doGui() { // setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setLayout(new GridBagLayout()); GridBagConstraints c1 = new GridBagConstraints(); c1.fill = GridBagConstraints.NONE; c1.anchor = GridBagConstraints.WEST; c1.insets = new Insets(10, 5, 10, 5); c1.weightx = 0;//from www . j av a 2 s . c o m c1.weighty = 0; JLabel noteLbl = new JLabel("Pls select a value to choose a Player or you can create a new " + "Player entity below. Once selected a Player character, its' details will be available below"); add(noteLbl, c1); DefaultComboBoxModel model = new DefaultComboBoxModel(); for (GameCharacter character : GameBean.playerDetails) { model.addElement(((Player) character).getType()); } c1.gridy = 1; comboBox = new JComboBox(model); comboBox.setSelectedIndex(-1); comboBox.setMaximumSize(new Dimension(100, 30)); comboBox.setActionCommand("dropDown"); comboBox.addActionListener(this); add(comboBox, c1); JPanel wrapperPanel = new JPanel(new GridLayout(1, 2, 10, 10)); wrapperPanel.setBorder(LineBorder.createGrayLineBorder()); leftPanel = new JPanel(); leftPanel.setAlignmentX(0); leftPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(5, 5, 5, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 2; JLabel enemyDtlLbl = new JLabel("Enemy Character Details : "); enemyDtlLbl.setFont(new Font("Times New Roman", Font.BOLD, 15)); leftPanel.add(enemyDtlLbl, c); c.gridwidth = 1; c.gridy = 1; JLabel nameLbl = new JLabel("Name : "); leftPanel.add(nameLbl, c); c.gridx = 1; JTextField name = new JTextField(""); name.setColumns(20); leftPanel.add(name, c); c.gridx = 0; c.gridy = 2; JLabel imageLbl = new JLabel("Image Path : "); leftPanel.add(imageLbl, c); c.gridx = 1; JTextField image = new JTextField(""); image.setColumns(20); leftPanel.add(image, c); c.gridx = 0; c.gridy = 3; JLabel healthLbl = new JLabel("Health Pts : "); leftPanel.add(healthLbl, c); c.gridx = 1; JTextField health = new JTextField(""); health.setColumns(20); leftPanel.add(health, c); c.gridx = 0; c.gridy = 4; JLabel attackPtsLbl = new JLabel("Attack Points : "); leftPanel.add(attackPtsLbl, c); c.gridx = 1; JTextField attackPts = new JTextField(""); attackPts.setColumns(20); leftPanel.add(attackPts, c); c.gridx = 0; c.gridy = 5; JLabel armoursPtsLbl = new JLabel("Armour Points : "); leftPanel.add(armoursPtsLbl, c); c.gridx = 1; JTextField armourPts = new JTextField(""); armourPts.setColumns(20); leftPanel.add(armourPts, c); c.gridx = 0; c.gridy = 6; JLabel attackRngeLbl = new JLabel("Attack Range : "); leftPanel.add(attackRngeLbl, c); c.gridx = 1; JTextField attackRnge = new JTextField(""); attackRnge.setColumns(20); leftPanel.add(attackRnge, c); c.gridx = 0; c.gridy = 7; JLabel movementLbl = new JLabel("Movement : "); leftPanel.add(movementLbl, c); c.gridx = 1; JTextField movement = new JTextField(""); movement.setColumns(20); leftPanel.add(movement, c); c.gridx = 0; c.gridy = 8; JLabel typeLbl = new JLabel("Type : "); leftPanel.add(typeLbl, c); c.gridx = 1; JTextField typeTxt = new JTextField(""); typeTxt.setColumns(20); leftPanel.add(typeTxt, c); c.gridx = 0; c.gridy = 9; JLabel weaponLbl = new JLabel("Equipped Weapon : "); leftPanel.add(weaponLbl, c); c.gridx = 1; DefaultComboBoxModel weapon = new DefaultComboBoxModel(); for (Item item : GameBean.weaponDetails) { if (item instanceof Weapon) { weapon.addElement(((Weapon) item).getName()); } } JComboBox weaponDrpDown = new JComboBox(weapon); weaponDrpDown.setSelectedIndex(-1); weaponDrpDown.setMaximumSize(new Dimension(100, 30)); leftPanel.add(weaponDrpDown, c); c.gridx = 0; c.gridy = 10; c.gridwidth = 2; JButton submit = new JButton("Save"); submit.addActionListener(this); submit.setActionCommand("button"); leftPanel.add(submit, c); wrapperPanel.add(leftPanel); lvlPanel = new LevelPanel(true, null); wrapperPanel.add(lvlPanel); c1.gridy = 2; c1.fill = GridBagConstraints.BOTH; add(wrapperPanel, c1); c1.fill = GridBagConstraints.NONE; validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down"); validationMess.setForeground(Color.red); validationMess.setVisible(false); c1.gridy = 3; add(validationMess, c1); c1.weightx = 1; c1.fill = GridBagConstraints.BOTH; c1.weighty = 1; c1.gridy = 4; add(new JPanel(), c1); }
From source file:org.apache.marmotta.splash.common.ui.MessageDialog.java
public static void show(String title, String message, String description) { final JDialog dialog = new JDialog((Frame) null, title); dialog.setModal(true);// w w w .j a v a 2s .c o m dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); final JPanel root = new JPanel(new GridBagLayout()); root.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); dialog.getRootPane().setContentPane(root); final JButton close = new JButton("OK"); close.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }); GridBagConstraints cClose = new GridBagConstraints(); cClose.gridx = 0; cClose.gridy = 2; cClose.gridwidth = 2; cClose.weightx = 1; cClose.weighty = 0; cClose.insets = new Insets(5, 5, 5, 5); root.add(close, cClose); dialog.getRootPane().setDefaultButton(close); Icon icon = loadIcon(MARMOTTA_ICON); if (icon != null) { JLabel lblIcn = new JLabel(icon); GridBagConstraints cIcon = new GridBagConstraints(); cIcon.gridx = 1; cIcon.gridy = 0; cIcon.gridheight = 2; cIcon.fill = GridBagConstraints.NONE; cIcon.weightx = 0; cIcon.weighty = 1; cIcon.anchor = GridBagConstraints.NORTH; cIcon.insets = new Insets(10, 5, 5, 0); root.add(lblIcn, cIcon); } JLabel lblMsg = new JLabel("<html>" + StringEscapeUtils.escapeHtml3(message).replaceAll("\\n", "<br>")); lblMsg.setFont(lblMsg.getFont().deriveFont(Font.BOLD, 16f)); GridBagConstraints cLabel = new GridBagConstraints(); cLabel.gridx = 0; cLabel.gridy = 0; cLabel.fill = GridBagConstraints.BOTH; cLabel.weightx = 1; cLabel.weighty = 0.5; cLabel.insets = new Insets(5, 5, 5, 5); root.add(lblMsg, cLabel); JLabel lblDescr = new JLabel( "<html>" + StringEscapeUtils.escapeHtml3(description).replaceAll("\\n", "<br>")); cLabel.gridy++; cLabel.insets = new Insets(0, 5, 5, 5); root.add(lblDescr, cLabel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.dispose(); }
From source file:EditorPaneExample10.java
public EditorPaneExample10() { super("JEditorPane Example 10"); 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 w w.java2 s. 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; 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: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;//from w w w. j a va 2s. c om // 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:TwoStopsGradient.java
/** Creates a new instance of TwoStopsGradient */ public TwoStopsGradient() { super("Two Stops Gradient"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridBagLayout()); JButton button;//from w w w . j av a 2s. c om panel.add(button = new DepthButton("New"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); button.setFocusPainted(false); panel.add(button = new DepthButton("Open"), new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); button.setFocusPainted(false); panel.add(button = new DepthButton("Save"), new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); button.setFocusPainted(false); add(panel); setSize(320, 240); }
From source file:events.FocusEventDemo.java
public void addComponentsToPane(final Container pane) { GridBagLayout gridbag = new GridBagLayout(); pane.setLayout(gridbag);/*from w w w . j a va 2 s.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: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++;// w ww .ja v a 2 s. co 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; } }; }
From source file:EditorPaneExample11.java
public EditorPaneExample11() { super("JEditorPane Example 11"); 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 w w. j a va 2 s . c o 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; 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"); // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // 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); // Display an empty tree while loading tree.setModel(emptyModel); tree.paintImmediately(0, 0, tree.getSize().width, tree.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)); TreeNode node = buildHeadingTree(doc); tree.setModel(new DefaultTreeModel(node)); 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)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); }
From source file:cz.alej.michalik.totp.client.OtpPanel.java
/** * Pid jeden panel se zznamem// www . j av a 2 s. c o 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(); } }); }
From source file:cool.pandora.modeller.ui.jpanel.base.NewBagFrame.java
/** * layoutBagVersionSelection.// w ww .j a va 2 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); }