List of usage examples for java.awt GridBagConstraints GridBagConstraints
public GridBagConstraints()
From source file:biomine.bmvis2.pipeline.EdgeLabelOperation.java
public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { JPanel ret = new JPanel(); ret.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = c.HORIZONTAL;//from w ww . j a va 2s. co m c.weightx = 1; c.weighty = 0; c.gridy = 0; final Set<String> avail = graph.getAvailableEdgeLabels(); for (final String str : avail) { final JCheckBox box = new JCheckBox(); box.setSelected(enabledLabels.contains(str)); box.setAction(new AbstractAction(str) { public void actionPerformed(ActionEvent arg0) { if (box.isSelected() != enabledLabels.contains(str)) { if (box.isSelected()) enabledLabels.add(str); else enabledLabels.remove(str); v.settingsChanged(false); } } }); ret.add(box, c); c.gridy++; } return ret; }
From source file:eu.dety.burp.joseph.utilities.Converter.java
/** * Get RSA PublicKey by PublicKey HashMap input. Create a dialog popup with a combobox to choose the correct JWK to use. * /*from w ww .ja v a2 s . c o m*/ * @param publicKeys * HashMap containing a PublicKey and related describing string * @throws AttackPreparationFailedException * @return Selected {@link PublicKey} */ @SuppressWarnings("unchecked") public static PublicKey getRsaPublicKeyByJwkSelectionPanel(HashMap<String, PublicKey> publicKeys) throws AttackPreparationFailedException { // TODO: Move to other class? JPanel selectionPanel = new JPanel(); selectionPanel.setLayout(new java.awt.GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridy = 0; selectionPanel.add(new JLabel("Multiple JWKs found. Please choose one:"), constraints); JComboBox jwkSetKeySelection = new JComboBox<>(); DefaultComboBoxModel<String> jwkSetKeySelectionModel = new DefaultComboBoxModel<>(); for (Map.Entry<String, PublicKey> publicKey : publicKeys.entrySet()) { jwkSetKeySelectionModel.addElement(publicKey.getKey()); } jwkSetKeySelection.setModel(jwkSetKeySelectionModel); constraints.gridy = 1; selectionPanel.add(jwkSetKeySelection, constraints); int resultButton = JOptionPane.showConfirmDialog(null, selectionPanel, "Select JWK", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (resultButton == JOptionPane.CANCEL_OPTION) { throw new AttackPreparationFailedException("No JWK from JWK Set selected!"); } loggerInstance.log(Converter.class, "Key selected: " + jwkSetKeySelection.getSelectedIndex(), Logger.LogLevel.DEBUG); return publicKeys.get(jwkSetKeySelection.getSelectedItem()); }
From source file:DocumentEventDemo.java
public DocumentEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); JButton button = new JButton("Clear"); button.addActionListener(this); textField = new JTextField(20); textField.addActionListener(new MyTextActionListener()); textField.getDocument().addDocumentListener(new MyDocumentListener()); textField.getDocument().putProperty("name", "Text Field"); textArea = new JTextArea(); textArea.getDocument().addDocumentListener(new MyDocumentListener()); textArea.getDocument().putProperty("name", "Text Area"); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setPreferredSize(new Dimension(200, 75)); displayArea = new JTextArea(); displayArea.setEditable(false);/*from www . j a v a2 s. c o m*/ JScrollPane displayScrollPane = new JScrollPane(displayArea); displayScrollPane.setPreferredSize(new Dimension(200, 75)); c.gridx = 0; c.gridy = 0; c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(textField, c); add(textField); c.gridx = 0; c.gridy = 1; c.weightx = 0.0; c.gridheight = 2; c.fill = GridBagConstraints.BOTH; gridbag.setConstraints(scrollPane, c); add(scrollPane); c.gridx = 1; c.gridy = 0; c.weightx = 1.0; c.weighty = 1.0; gridbag.setConstraints(displayScrollPane, c); add(displayScrollPane); c.gridx = 1; c.gridy = 2; c.weightx = 0.0; c.gridheight = 1; c.weighty = 0.0; c.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(button, c); add(button); setPreferredSize(new Dimension(450, 250)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:jmap2gml.ScriptGui.java
/** * Formats the window, initializes the JMap2Script object, and sets up all * the necessary events./* w w w.j a v a 2 s . c om*/ */ public ScriptGui() { setTitle("jmap to gml script converter"); setDefaultCloseOperation(EXIT_ON_CLOSE); getContentPane().setLayout(new GridBagLayout()); this.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent we) { } @Override public void windowClosing(WindowEvent we) { saveConfig(); } @Override public void windowClosed(WindowEvent we) { } @Override public void windowIconified(WindowEvent we) { } @Override public void windowDeiconified(WindowEvent we) { } @Override public void windowActivated(WindowEvent we) { } @Override public void windowDeactivated(WindowEvent we) { } }); GridBagConstraints c = new GridBagConstraints(); setResizable(true); setIconImage((new ImageIcon("spikeup.png")).getImage()); jta = new JTextArea(38, 30); loadConfig(); JScrollPane jsp = new JScrollPane(jta); jsp.setRowHeaderView(new TextLineNumber(jta)); jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); jsp.setSize(jsp.getWidth(), 608); // menu bar JMenuBar menubar = new JMenuBar(); // file menu JMenu file = new JMenu("File"); // load button JMenuItem load = new JMenuItem("Load jmap"); load.addActionListener(ae -> { JFileChooser fileChooser = new JFileChooser(prevDirectory); fileChooser.setFileFilter(new FileNameExtensionFilter("jmap file", "jmap", "jmap")); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); prevDirectory = selectedFile.getAbsolutePath(); jm2s = new ScriptFromJmap(selectedFile.getPath(), false); jta.setText(""); jta.append(jm2s.toString()); jta.setCaretPosition(0); writeFile.setEnabled(true); drawPanel.setItems(jta.getText().split("\n")); } }); // add load to file menu file.add(load); // button to save script to file writeFile = new JMenuItem("Write file"); writeFile.addActionListener(ae -> { if (jm2s != null) { PrintWriter out; try { File f = new File( jm2s.getFileName().substring(0, jm2s.getFileName().lastIndexOf(".jmap")) + ".gml"); out = new PrintWriter(f); out.append(jm2s.toString()); out.close(); } catch (FileNotFoundException ex) { Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex); } } }); writeFile.setEnabled(false); JMenuItem gmx = new JMenuItem("Export as gmx"); gmx.addActionListener(ae -> { String fn = String.format("%s.room.gmx", prevDirectory); JFileChooser fc = new JFileChooser(prevDirectory); fc.setSelectedFile(new File(fn)); fc.setFileFilter(new FileNameExtensionFilter("Game Maker XML", "gmx", "gmx")); fc.showDialog(null, "Save"); File f = fc.getSelectedFile(); if (f != null) { try { GMX.itemsToGMX(drawPanel.items, new FileOutputStream(f)); } catch (FileNotFoundException ex) { Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex); } } }); // add to file menu file.add(writeFile); file.add(gmx); // add file menu to the menubar menubar.add(file); // Edit menu // display menu JMenu display = new JMenu("Display"); JMenuItem update = new JMenuItem("Update"); update.addActionListener(ae -> { drawPanel.setItems(jta.getText().split("\n")); }); display.add(update); JMenuItem gridToggle = new JMenuItem("Toggle Grid"); gridToggle.addActionListener(ae -> { drawPanel.toggleGrid(); }); display.add(gridToggle); JMenuItem gridOptions = new JMenuItem("Modify Grid"); gridOptions.addActionListener(ae -> { drawPanel.modifyGrid(); }); display.add(gridOptions); menubar.add(display); // sets the menubar setJMenuBar(menubar); // add the text area to the window c.gridx = 0; c.gridy = 0; add(jsp, c); // initialize the preview panel drawPanel = new Preview(this); JScrollPane scrollPane = new JScrollPane(drawPanel); // add preview panel to the window c.gridx = 1; c.gridwidth = 2; add(scrollPane, c); pack(); setMinimumSize(this.getSize()); setLocationRelativeTo(null); setVisible(true); drawPanel.setItems(jta.getText().split("\n")); }
From source file:be.ac.ua.comp.scarletnebula.gui.AllGraphsPanel.java
/** * Places all components (graphs) in the panel. *//*from w w w. j a va 2s. com*/ private void placeComponents() { final GridBagConstraints constraints = new GridBagConstraints(); int numberOfComponentsPlaced = 0; int currXPos = 0; final int graphHeight = 150; final int graphWidth = 100; final Collection<String> datastreams = statisticsManager.getAvailableDatastreams(); for (final String streamname : datastreams) { LOG.info("drawing stream"); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 0.5; constraints.gridx = currXPos; constraints.gridy = numberOfComponentsPlaced / 2; constraints.insets = new Insets(10, 0, 0, 0); final DecoratedGraph graph = new DecoratedGraph((long) 10 * 60 * 1000, statisticsManager.getDatastream(streamname)); graph.registerRelativeDatastream(server, streamname, Color.GREEN); graph.addServerToRefresh(server); final ChartPanel chartPanel = graph.getChartPanel(); chartPanel.setPreferredSize(new Dimension(graphWidth, graphHeight)); add(chartPanel, constraints); if (currXPos == 0) { currXPos = 1; } else { currXPos = 0; } numberOfComponentsPlaced++; } }
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);/* w w w . j av a 2 s. c o m*/ 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:events.ContainerEventDemo.java
public ContainerEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); //Initialize an empty list of buttons. buttonList = new Vector<JButton>(10, 10); //Create all the components. addButton = new JButton("Add a button"); addButton.setActionCommand(ADD);/*from w w w .ja v a2 s .co m*/ addButton.addActionListener(this); removeButton = new JButton("Remove a button"); removeButton.setActionCommand(REMOVE); removeButton.addActionListener(this); buttonPanel = new JPanel(new GridLayout(1, 1)); buttonPanel.setPreferredSize(new Dimension(200, 75)); buttonPanel.addContainerListener(this); display = new JTextArea(); display.setEditable(false); JScrollPane scrollPane = new JScrollPane(display); scrollPane.setPreferredSize(new Dimension(200, 75)); clearButton = new JButton("Clear text area"); clearButton.setActionCommand(CLEAR); clearButton.addActionListener(this); c.fill = GridBagConstraints.BOTH; //Fill entire cell. c.weighty = 1.0; //Button area and message area have equal height. c.gridwidth = GridBagConstraints.REMAINDER; //end of row gridbag.setConstraints(scrollPane, c); add(scrollPane); c.weighty = 0.0; gridbag.setConstraints(clearButton, c); add(clearButton); c.weightx = 1.0; //Add/remove buttons have equal width. c.gridwidth = 1; //NOT end of row gridbag.setConstraints(addButton, c); add(addButton); c.gridwidth = GridBagConstraints.REMAINDER; //end of row gridbag.setConstraints(removeButton, c); add(removeButton); c.weighty = 1.0; //Button area and message area have equal height. gridbag.setConstraints(buttonPanel, c); add(buttonPanel); setPreferredSize(new Dimension(400, 400)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:GetOpenProperties.java
public void init() { //Set up the layout. GridBagLayout gridbag = new GridBagLayout(); setLayout(gridbag);//w w w. j a v a2 s . c o 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:TreeExpandEventDemo2.java
public TreeExpandEventDemo2() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0;//from ww w. j a v a 2 s. c o m c.weighty = 1.0; c.insets = new Insets(1, 1, 1, 1); demoArea = new DemoArea(); gridbag.setConstraints(demoArea, c); add(demoArea); c.insets = new Insets(0, 0, 0, 0); textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(200, 75)); gridbag.setConstraints(scrollPane, c); add(scrollPane); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:com.igormaznitsa.sciareto.ui.tabs.TabTitle.java
public TabTitle(@Nonnull final Context context, @Nonnull final TabProvider parent, @Nullable final File associatedFile) { super(new GridBagLayout()); this.parent = parent; this.context = context; this.associatedFile = associatedFile; this.changed = this.associatedFile == null; this.setOpaque(false); final GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; constraints.weightx = 1000.0d;/*from ww w . j a v a 2 s . c om*/ final TabTitle theInstance = this; this.titleLabel = new JLabel() { private static final long serialVersionUID = 8689945842487138781L; @Override protected void processKeyEvent(@Nonnull final KeyEvent e) { theInstance.getParent().dispatchEvent(e); } @Override public String getToolTipText() { return theInstance.getToolTipText(); } @Override public boolean isFocusable() { return false; } }; this.add(this.titleLabel, constraints); final Icon uiCloseIcon = UIManager.getIcon("InternalFrameTitlePane.closeIcon"); this.closeButton = new JButton(uiCloseIcon == null ? NIMBUS_CLOSE_ICON : uiCloseIcon) { private static final long serialVersionUID = -8005282815756047979L; @Override public String getToolTipText() { return theInstance.getToolTipText(); } @Override public boolean isFocusable() { return false; } }; this.closeButton.setToolTipText("Close tab"); this.closeButton.setBorder(null); this.closeButton.setContentAreaFilled(false); this.closeButton.setMargin(new Insets(0, 0, 0, 0)); this.closeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); this.closeButton.setOpaque(false); this.closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(@Nonnull final ActionEvent e) { doSafeClose(); } }); constraints.fill = GridBagConstraints.BOTH; constraints.weightx = 0.0d; constraints.insets = new Insets(2, 8, 2, 0); this.add(this.closeButton, constraints); updateView(); ToolTipManager.sharedInstance().registerComponent(closeButton); ToolTipManager.sharedInstance().registerComponent(this.titleLabel); ToolTipManager.sharedInstance().registerComponent(this); }