List of usage examples for java.awt GridBagConstraints WEST
int WEST
To view the source code for java.awt GridBagConstraints WEST.
Click Source Link
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;/*from w w w . ja va 2 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:net.sourceforge.pmd.util.designer.CreateXMLRulePanel.java
public CreateXMLRulePanel(JTextArea xpathQueryArea, CodeEditorTextPane codeEditorPane) { super();/*from w ww . j a va 2s . co m*/ this.xpathQueryArea = xpathQueryArea; this.codeEditorPane = codeEditorPane; GridBagConstraints gbc = new GridBagConstraints(); // We use a gridbaglayout for a nice and sturdy look and feel GridBagLayout gbl = new GridBagLayout(); setLayout(gbl); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.EAST; gbc.weightx = 0.5; JLabel rulenameLabel = new JLabel("Rule name : "); gbl.setConstraints(rulenameLabel, gbc); add(rulenameLabel); gbc.weightx = 0.5; gbc.anchor = GridBagConstraints.WEST; gbc.gridx = 1; gbl.setConstraints(rulenameField, gbc); add(rulenameField); gbc.gridx = 0; gbc.gridy = 1; gbc.anchor = GridBagConstraints.EAST; gbc.weightx = 0.5; JLabel rulemsgLabel = new JLabel("Rule msg : "); gbl.setConstraints(rulemsgLabel, gbc); add(rulemsgLabel); gbc.gridx = 1; gbc.anchor = GridBagConstraints.WEST; gbc.weightx = 0.5; gbl.setConstraints(rulemsgField, gbc); add(rulemsgField); gbc.gridx = 0; gbc.gridy = 2; gbc.anchor = GridBagConstraints.EAST; gbc.weightx = 0.5; JLabel ruledescLabel = new JLabel("Rule desc : "); gbl.setConstraints(ruledescLabel, gbc); add(ruledescLabel); gbc.gridx = 1; gbc.anchor = GridBagConstraints.WEST; gbc.weightx = 0.5; ruledescField.setLineWrap(true); gbl.setConstraints(ruledescField, gbc); add(ruledescField); gbc.gridx = 0; gbc.gridy = 3; gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.NORTH; JButton createRuleBtn = new JButton("Create rule XML"); createRuleBtn.addActionListener(this); gbl.setConstraints(createRuleBtn, gbc); add(createRuleBtn); gbc.gridx = 0; gbc.gridy = 4; gbc.anchor = GridBagConstraints.NORTH; gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 1.0; gbc.weighty = 1.0; JScrollPane ruleXMLPane = new JScrollPane(ruleXMLArea); gbl.setConstraints(ruleXMLPane, gbc); add(ruleXMLPane); repaint(); }
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 w w w .j a v a 2 s.c om*/ 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.openconcerto.erp.core.finance.accounting.ui.ClotureMensuellePayePanel.java
public ClotureMensuellePayePanel() { super();// ww w .j a v a 2 s .c om this.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(2, 2, 1, 2); c.weightx = 0; c.weighty = 0; c.gridheight = 1; c.gridwidth = 1; c.gridx = 0; c.gridy = 0; JLabel labelMois = new JLabel("Cloture du mois de "); this.add(labelMois, c); final ElementComboBox selMois = new ElementComboBox(true, 25); selMois.init(((ComptaPropsConfiguration) Configuration.getInstance()).getDirectory() .getElement(MoisSQLElement.class)); selMois.setButtonsVisible(false); c.gridx++; this.add(selMois, c); JLabel labelAnnee = new JLabel("Anne"); c.gridx++; this.add(labelAnnee, c); final JTextField textAnnee = new JTextField(5); c.gridx++; this.add(textAnnee, c); DateFormat format = new SimpleDateFormat("yyyy"); textAnnee.setText(format.format(new Date())); c.gridy++; c.gridx = 0; final JCheckBox boxValid = new JCheckBox("Valider toutes les payes du mois"); final JCheckBox boxCompta = new JCheckBox("Gnrer les critures comptables associes"); c.gridwidth = GridBagConstraints.REMAINDER; this.add(boxValid, c); boxValid.setSelected(true); c.gridy++; this.add(boxCompta, c); JButton buttonClot = new JButton("Clturer"); JButton buttonFermer = new JButton("Fermer"); JPanel panelButton = new JPanel(); panelButton.add(buttonClot); panelButton.add(buttonFermer); c.anchor = GridBagConstraints.SOUTHEAST; c.fill = GridBagConstraints.NONE; c.weighty = 1; c.gridy++; this.add(panelButton, c); buttonFermer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ((JFrame) SwingUtilities.getRoot(ClotureMensuellePayePanel.this)).dispose(); } }); buttonClot.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { // Valider les fiches non valids des salaris actifs if (boxValid.isSelected()) { SQLSelect selFiche = new SQLSelect(); SQLTable tableFiche = ClotureMensuellePayePanel.this.base.getTable("FICHE_PAYE"); SQLTable tableSalarie = ClotureMensuellePayePanel.this.base.getTable("SALARIE"); SQLTable tableInfosSal = ClotureMensuellePayePanel.this.base.getTable("INFOS_SALARIE_PAYE"); selFiche.addSelect(tableFiche.getField("ID")); selFiche.setWhere(new Where(tableFiche.getField("VALIDE"), "=", Boolean.FALSE)); selFiche.andWhere(new Where(tableFiche.getField("ID_MOIS"), "=", selMois.getSelectedId())); selFiche.andWhere( new Where(tableFiche.getField("ANNEE"), "=", new Integer(textAnnee.getText()))); selFiche.andWhere( new Where(tableSalarie.getField("ID"), "=", tableFiche.getField("ID_SALARIE"))); selFiche.andWhere(new Where(tableInfosSal.getField("ID"), "=", tableSalarie.getField("ID_INFOS_SALARIE_PAYE"))); // FIXME ne pas valider les fiches d'un employ renvoy // Where w2 = new Where(tableInfosSal.getField("DATE_SORTIE"), "IS", // "NULL"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, selMois.getSelectedId() - 2); cal.set(Calendar.YEAR, Integer.parseInt(textAnnee.getText())); cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE)); Where w = new Where(tableInfosSal.getField("DATE_SORTIE"), "<=", cal.getTime()); w = w.or(new Where(tableInfosSal.getField("DATE_SORTIE"), "=", (Object) null)); selFiche.andWhere(w); String req = selFiche.asString(); System.err.println(req); List l = (List) ClotureMensuellePayePanel.this.base.getDataSource().execute(req, new ArrayListHandler()); for (int i = 0; i < l.size(); i++) { Object[] tmp = (Object[]) l.get(i); SQLRow rowFicheTmp = tableFiche.getRow(Integer.parseInt(tmp[0].toString())); System.err.println(rowFicheTmp); FichePayeSQLElement.validationFiche(rowFicheTmp.getID()); } } // cloture du mois et generation compta SQLSelect selFiche = new SQLSelect(ClotureMensuellePayePanel.this.base); SQLTable tableFiche = ClotureMensuellePayePanel.this.base.getTable("FICHE_PAYE"); SQLTable tableMois = ClotureMensuellePayePanel.this.base.getTable("MOIS"); selFiche.addSelect(tableFiche.getField("ID")); selFiche.setWhere(new Where(tableFiche.getField("VALIDE"), "=", Boolean.TRUE)); selFiche.andWhere(new Where(tableFiche.getField("ID_MOIS"), "=", selMois.getSelectedId())); selFiche.andWhere( new Where(tableFiche.getField("ANNEE"), "=", new Integer(textAnnee.getText()))); String req = selFiche.asString(); List l = (List) ClotureMensuellePayePanel.this.base.getDataSource().execute(req, new ArrayListHandler()); if (l != null && l.size() > 0) { int[] idS = new int[l.size()]; SQLRow rowMois = tableMois.getRow(selMois.getSelectedId()); for (int i = 0; i < l.size(); i++) { Object[] tmp = (Object[]) l.get(i); idS[i] = Integer.parseInt(tmp[0].toString()); SQLRow rowFiche = tableFiche.getRow(idS[i]); FichePayeSQLElement.clotureMensuelle(selMois.getSelectedId(), Integer.parseInt(textAnnee.getText()), rowFiche.getInt("ID_SALARIE")); } if (boxCompta.isSelected()) { new GenerationMvtFichePaye(idS, rowMois.getString("NOM"), textAnnee.getText()); } } System.err.println( "ClotureMensuellePayePanel.ClotureMensuellePayePanel().new ActionListener() {...}.actionPerformed()"); JOptionPane.showMessageDialog(null, "Clture termine"); } catch (Exception ex) { ExceptionHandler.handle("Unable to complete operation", ex); } } }); }
From source file:EditorPaneExample19.java
public EditorPaneExample19() { super("JEditorPane Example 19"); pane = new JEditorPane(); pane.setEditable(true); // Editable getContentPane().add(new JScrollPane(pane), "Center"); // Add a menu bar menuBar = new JMenuBar(); setJMenuBar(menuBar);/*from w w w . ja va 2 s.c o m*/ // Populate it createMenuBar(); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1; 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.gridy = 5; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; editableBox = new JCheckBox("Editable JEditorPane"); panel.add(editableBox, c); editableBox.setSelected(true); editableBox.setForeground(typeLabel.getForeground()); c.gridy = 6; c.weightx = 0.0; JButton saveButton = new JButton("Save"); panel.add(saveButton, c); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { EditorKit kit = pane.getEditorKit(); try { if (kit instanceof RTFEditorKit) { kit.write(System.out, pane.getDocument(), 0, pane.getDocument().getLength()); System.out.flush(); } else { if (writer == null) { writer = new OutputStreamWriter(System.out); pane.write(writer); writer.flush(); } kit.write(writer, pane.getDocument(), 0, pane.getDocument().getLength()); writer.flush(); } } catch (Exception e) { System.out.println("Write failed"); } } }); c.gridx = 1; c.gridy = 0; c.weightx = 1.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"); // Register a custom EditorKit for HTML ClassLoader loader = getClass().getClassLoader(); if (loader != null) { // Java 2 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.EnhancedHTMLEditorKit", loader); } else { // JDK 1.1 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.EnhancedHTMLEditorKit"); } // 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(); loadNewPage(selection); } }); // Change editability based on the checkbox editableBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editableBox.isSelected()); pane.revalidate(); pane.repaint(); } }); // 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)); createMenuBar(); enableMenuBar(true); getRootPane().revalidate(); enableInput(); loadingPage = false; } } }); // 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) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
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;//from ww w . j a v a2 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; 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:org.zaproxy.zap.extension.openapi.ImportFromUrlDialog.java
public ImportFromUrlDialog(JFrame parent, ExtensionOpenApi caller) { super(parent, true); this.setTitle(Constant.messages.getString(MESSAGE_PREFIX + "title")); this.caller = caller; if (parent != null) { Dimension parentSize = parent.getSize(); Point p = parent.getLocation(); setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4); }/*from ww w . j a va2s . c o m*/ // set up layout setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(5, 5, 5, 5); buttonImport.addActionListener(this); buttonCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ImportFromUrlDialog.this.setVisible(false); ImportFromUrlDialog.this.dispose(); } }); // add components to the frame constraints.gridx = 0; constraints.gridy = 0; add(new JLabel(Constant.messages.getString(MESSAGE_PREFIX + "labelurl")), constraints); constraints.gridx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1.0; constraints.gridwidth = 2; fieldURL = addContextMenu(fieldURL); add(fieldURL, constraints); constraints.gridx = 0; constraints.gridy = 1; add(new JLabel(Constant.messages.getString(MESSAGE_PREFIX + "labeloverride")), constraints); constraints.gridx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1.0; constraints.gridwidth = 2; add(siteOverride, constraints); constraints.gridwidth = 1; constraints.gridy = 2; constraints.anchor = GridBagConstraints.CENTER; add(buttonCancel, constraints); constraints.gridx = 2; constraints.gridy = 2; constraints.anchor = GridBagConstraints.CENTER; add(buttonImport, constraints); setDefaultCloseOperation(DISPOSE_ON_CLOSE); pack(); setVisible(true); }
From source file:GetOpenProperties.java
public void init() { //Set up the layout. GridBagLayout gridbag = new GridBagLayout(); setLayout(gridbag);/*from w w w. ja va 2s.co m*/ 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:flow.visibility.tapping.OpenDayLightUtils.java
/** Creating the Pane for Flow Entry */ public OpenDayLightUtils() { super("Installed Flow"); FlowtextArea = new JTextArea(50, 10); FlowtextArea.setEditable(false);// ww w .j a va2 s .c om FlowtextArea.setFont(new Font("Courier New", Font.BOLD, 12)); PrintStream FlowprintStream = new PrintStream(new CustomOutputStream(FlowtextArea)); // re-assigns standard output stream and error output stream System.setOut(FlowprintStream); System.setErr(FlowprintStream); // creates the GUI setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0; constraints.gridy = 0; constraints.insets = new Insets(10, 10, 10, 10); constraints.anchor = GridBagConstraints.WEST; constraints.gridx = 0; constraints.gridy = 1; constraints.gridwidth = 2; constraints.fill = GridBagConstraints.BOTH; constraints.weightx = 1.0; constraints.weighty = 1.0; /** Adding the Pane into Frame */ scrollPane = new JScrollPane(FlowtextArea); this.add(scrollPane, constraints); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setSize(400, 600); setLocationRelativeTo(null); // centers on screen }
From source file:cool.pandora.modeller.ui.jpanel.base.NewBagFrame.java
/** * layoutBagVersionSelection./*from w ww .j av a 2s.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); }