List of usage examples for java.awt GridBagLayout GridBagLayout
public GridBagLayout()
From source file:FocusEventDemo.java
public void addComponentsToPane(final Container pane) { GridBagLayout gridbag = new GridBagLayout(); pane.setLayout(gridbag);//from w ww . j a v a2 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:com.digitalgeneralists.assurance.ui.components.FilePickerTextField.java
protected void initializeComponent() { if (!this.initialized) { this.filePicker.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); GridBagLayout gridbag = new GridBagLayout(); this.setLayout(gridbag); final JPanel filePathPanel = new JPanel(); filePathPanel.setLayout(new GridBagLayout()); GridBagConstraints filePathPanelConstraints = new GridBagConstraints(); filePathPanelConstraints.anchor = GridBagConstraints.NORTH; filePathPanelConstraints.fill = GridBagConstraints.HORIZONTAL; filePathPanelConstraints.gridx = 0; filePathPanelConstraints.gridy = 0; filePathPanelConstraints.weightx = 1.0; filePathPanelConstraints.weighty = 1.0; filePathPanelConstraints.gridheight = 1; filePathPanelConstraints.gridwidth = 2; filePathPanelConstraints.insets = new Insets(0, 0, 0, 0); GridBagConstraints pathTextFieldConstraints = new GridBagConstraints(); pathTextFieldConstraints.anchor = GridBagConstraints.NORTH; pathTextFieldConstraints.fill = GridBagConstraints.HORIZONTAL; pathTextFieldConstraints.gridx = 0; pathTextFieldConstraints.gridy = 0; pathTextFieldConstraints.weightx = 0.9; pathTextFieldConstraints.weighty = 1.0; pathTextFieldConstraints.gridheight = 1; pathTextFieldConstraints.gridwidth = 1; pathTextFieldConstraints.insets = new Insets(0, 0, 0, 0); GridBagConstraints pathFileChooserButtonConstraints = new GridBagConstraints(); pathFileChooserButtonConstraints.anchor = GridBagConstraints.NORTH; pathFileChooserButtonConstraints.fill = GridBagConstraints.HORIZONTAL; pathFileChooserButtonConstraints.gridx = 1; pathFileChooserButtonConstraints.gridy = 0; pathFileChooserButtonConstraints.weightx = 0.1; pathFileChooserButtonConstraints.weighty = 1.0; pathFileChooserButtonConstraints.gridheight = 1; pathFileChooserButtonConstraints.gridwidth = 1; pathFileChooserButtonConstraints.insets = new Insets(0, 0, 0, 0); filePathPanel.add(this.pathTextField, pathTextFieldConstraints); filePathPanel.add(this.pathFileChooserButton, pathFileChooserButtonConstraints); this.add(filePathPanel, filePathPanelConstraints); this.pathFileChooserButton.setActionCommand(AssuranceActions.chooseFilePathAction); this.pathTextField.getDocument().addDocumentListener(this.textPropertyValidationListener); this.pathFileChooserButton.addActionListener(this); this.initialized = true; }// w ww . j av a 2s. c om }
From source file:com.codedx.burp.security.InvalidCertificateDialogStrategy.java
@Override public CertificateAcceptance checkAcceptance(Certificate genericCert, CertificateException certError) { if (genericCert instanceof X509Certificate && defaultHostVerifier instanceof DefaultHostnameVerifier) { X509Certificate cert = (X509Certificate) genericCert; DefaultHostnameVerifier verifier = (DefaultHostnameVerifier) defaultHostVerifier; JPanel message = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = 2;//from w w w. ja v a 2s . c om gbc.insets = new Insets(0, 0, 10, 0); gbc.anchor = GridBagConstraints.WEST; message.add( new JLabel("Unable to establish a secure connection because the certificate is not trusted"), gbc); gbc = new GridBagConstraints(); gbc.gridy = 2; gbc.insets = new Insets(2, 0, 2, 0); gbc.anchor = GridBagConstraints.WEST; JLabel issuer = new JLabel("Issuer: "); Font defaultFont = issuer.getFont(); Font bold = new Font(defaultFont.getName(), Font.BOLD, defaultFont.getSize()); issuer.setFont(bold); message.add(issuer, gbc); gbc.gridx = 1; message.add(new JLabel(cert.getIssuerDN().toString()), gbc); try { JLabel fingerprint = new JLabel("Thumbprint: "); fingerprint.setFont(bold); gbc.gridx = 0; gbc.gridy += 1; message.add(fingerprint, gbc); gbc.gridx = 1; message.add(new JLabel(toHexString(getSHA1(cert.getEncoded()), " ")), gbc); } catch (CertificateEncodingException e) { // this shouldn't actually ever happen } try { verifier.verify(host, cert); } catch (SSLException e) { String cn = getCN(cert); JLabel mismatch = new JLabel("Host Mismatch: "); mismatch.setFont(bold); gbc.gridx = 0; gbc.gridy += 1; message.add(mismatch, gbc); String msg; if (cn != null) { msg = String.format("Expected '%s', but the certificate is for '%s'.", host, cn); } else { msg = e.getMessage(); } gbc.gridx = 1; message.add(new JLabel(msg), gbc); } // Open the dialog, and return its result int choice = JOptionPane.showOptionDialog(burpExtender.getUiComponent(), message, dialogTitle, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, dialogButtons, null); switch (choice) { case (0): return CertificateAcceptance.REJECT; case (1): return CertificateAcceptance.ACCEPT_TEMPORARILY; case (2): return CertificateAcceptance.ACCEPT_PERMANENTLY; } } return CertificateAcceptance.REJECT; }
From source file:misc.GradientTranslucentWindowDemo.java
public GradientTranslucentWindowDemo() { super("GradientTranslucentWindow"); setBackground(new Color(0, 0, 0, 0)); setSize(new Dimension(300, 200)); setLocationRelativeTo(null);/*from w w w . j a va2 s . c o m*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { @Override protected void paintComponent(Graphics g) { if (g instanceof Graphics2D) { final int R = 240; final int G = 240; final int B = 240; Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0), 0.0f, getHeight(), new Color(R, G, B, 255), true); Graphics2D g2d = (Graphics2D) g; g2d.setPaint(p); g2d.fillRect(0, 0, getWidth(), getHeight()); } } }; setContentPane(panel); setLayout(new GridBagLayout()); add(new JButton("I am a Button")); }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraphGUI.java
/** * Load the GUI.//from ww w . ja v a 2 s. c om */ 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:gate.gui.docview.AnnotationStack.java
void init() { setLayout(new GridBagLayout()); setOpaque(true);/*from w w w. j ava 2s . c om*/ setBackground(Color.WHITE); stackRows = new ArrayList<StackRow>(); textMouseListener = new StackMouseListener(); headerMouseListener = new StackMouseListener(); annotationMouseListener = new StackMouseListener(); }
From source file:edu.scripps.fl.pubchem.xmltool.gui.PubChemXMLCreatorGUI.java
public PubChemXMLCreatorGUI(Boolean isInternal) { DOMConfigurator.configure(PubChemXMLCreatorGUI.class.getClassLoader().getResource("log4j.config.xml")); // isInternal is initially set in SwingGUI this.isInternal = isInternal; setBorder(BorderFactory.createTitledBorder("PubChem XML Creator")); setLayout(new GridBagLayout()); setUpGUIComponents();//from w ww. j av a 2s . c om add(jlbFileTemplate, gbc01); add(jtfFileTemplate, gbc02); add(jbnFileTemplate, gbc03); add(jlbFileExcel, gbc04); add(jtfFileExcel, gbc05); add(jbnFileExcel, gbc06); add(jbnRunCreator, gbc07); add(jbnReportCreator, gbc08); add(jtpExcelTemplate, gbc09); add(jtpExample, gbc10); addMouseListener(this); }
From source file:Demo.HistGraph.java
public HistGraph(List<String> paraType_list) { this.paraType_list = paraType_list; // widgets: charts(JFreeChart), parameter selector (JList) chartPane = new ChartPanel(null); charts = new JFreeChart[paraType_list.size()]; DefaultListModel modelOfList = new DefaultListModel(); paraSelector = new JList(modelOfList); for (int i = 0; i < paraType_list.size(); i++) { modelOfList.addElement(paraType_list.get(i)); charts[i] = null;/* w ww .jav a 2 s . c o m*/ } paraSelector.setSelectedIndex(0); charts[0] = CreateChart(paraType_list.get(0)); chartPane.setChart(charts[0]); JScrollPane selectorPanel = new JScrollPane(); selectorPanel.setViewportView(paraSelector); paraSelector.addMouseListener(this); // layout GridBagLayout layout = new GridBagLayout(); setLayout(layout); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.weighty = 1; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 20, 5, 5); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 20; add(new JLabel("Distribution:"), gbc); gbc.insets = new Insets(5, 5, 5, 20); gbc.gridx = 1; gbc.gridy = 0; gbc.weightx = 1; add(new JLabel("Parameters:"), gbc); gbc.weighty = 14; gbc.insets = new Insets(5, 20, 5, 5); gbc.gridx = 0; gbc.gridy = 1; gbc.weightx = 20; add(chartPane, gbc); gbc.insets = new Insets(5, 5, 15, 20); gbc.gridx = 1; gbc.gridy = 1; gbc.weightx = 1; add(selectorPanel, gbc); }
From source file:com.game.ui.views.MapEditor.java
public void generateGUI() throws IOException { setDefaultCloseOperation(DISPOSE_ON_CLOSE); // setResizable(false); JMenuBar menubar = new JMenuBar(); ImageIcon icon = null;//from w w w . j a v a 2 s. c o m try { icon = GameUtils.shrinkImage("save.png", 20, 20); } catch (IOException e) { System.out.println("Dialog : showDialogForMap(): Exception occured :" + e); e.printStackTrace(); } JMenu file = new JMenu("File"); JMenuItem save = new JMenuItem("Save", icon); save.setToolTipText("Save Map Information"); save.setActionCommand("Save Map"); save.addActionListener(this); file.add(save); menubar.add(file); setJMenuBar(menubar); JPanel topPanel = new JPanel(); topPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); topPanel.setLayout(new GridBagLayout()); JLabel headerLbl = new JLabel("Legend : "); headerLbl.setFont(new Font("Times New Roman", Font.BOLD, 15)); JLabel lbl1 = new JLabel(); lbl1.setPreferredSize(new Dimension(50, 20)); lbl1.setBackground(Configuration.pathColor); lbl1.setOpaque(true); JLabel lbl2 = new JLabel("- Represents the path."); JLabel lbl3 = new JLabel(); lbl3.setPreferredSize(new Dimension(50, 20)); lbl3.setBackground(Configuration.enemyColor); lbl3.setOpaque(true); JLabel lbl4 = new JLabel("- Represents the path with monsters"); JLabel lbl5 = new JLabel(); lbl5.setPreferredSize(new Dimension(50, 20)); lbl5.setBackground(Configuration.startPointColor); lbl5.setOpaque(true); JLabel lbl6 = new JLabel("- Represents the starting point in the path"); JLabel lbl7 = new JLabel(); lbl7.setBackground(Configuration.endPointColor); lbl7.setOpaque(true); lbl7.setPreferredSize(new Dimension(50, 20)); JLabel lbl8 = new JLabel("- Ending point in the path"); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.weightx = 1; c.weighty = 0; c.insets = new Insets(5, 5, 5, 5); c.gridwidth = 2; topPanel.add(headerLbl, c); c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 1; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.ipadx = 5; c.ipady = 5; topPanel.add(lbl1, c); c.gridx = 1; c.anchor = GridBagConstraints.FIRST_LINE_START; topPanel.add(lbl2, c); c.gridx = 0; c.gridy = 2; topPanel.add(lbl3, c); c.gridx = 1; topPanel.add(lbl4, c); c.gridx = 0; c.gridy = 3; topPanel.add(lbl5, c); c.gridx = 1; topPanel.add(lbl6, c); c.gridx = 0; c.gridy = 4; topPanel.add(lbl7, c); c.gridx = 1; topPanel.add(lbl8, c); add(topPanel, BorderLayout.NORTH); bottomPanel = new JPanel(); add(bottomPanel, BorderLayout.CENTER); bottomPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); // bottomPanel.add(new JButton("kaushik")); pack(); setExtendedState(JFrame.MAXIMIZED_BOTH); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); setMaximizedBounds(env.getMaximumWindowBounds()); setVisible(true); callDialogForUsersInput(); }
From source file:ClipboardTest.java
public ClipboardTest() { super("Clipboard Test"); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag);//from w w w . j a v a2 s . c om srcText = new TextArea(8, 32); c.gridwidth = 2; c.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(srcText, c); add(srcText); copyButton = new Button("Copy Above"); copyButton.setActionCommand("copy"); copyButton.addActionListener(this); c.gridy = 1; c.gridwidth = 1; gridbag.setConstraints(copyButton, c); add(copyButton); pasteButton = new Button("Paste Below"); pasteButton.setActionCommand("paste"); pasteButton.addActionListener(this); pasteButton.setEnabled(false); c.gridx = 1; gridbag.setConstraints(pasteButton, c); add(pasteButton); dstText = new TextArea(8, 32); c.gridx = 0; c.gridy = 2; c.gridwidth = 2; gridbag.setConstraints(dstText, c); add(dstText); pack(); }