List of usage examples for java.awt GridBagLayout GridBagLayout
public GridBagLayout()
From source file:com.std.StockPanel.java
public void setHistoricalData() { this.setLayout(new BorderLayout()); nameAndChangePanel.setLayout(new BoxLayout(nameAndChangePanel, BoxLayout.PAGE_AXIS)); nameAndChangePanel.add(nameLbl);/*from w w w. j a v a 2s . c o m*/ nameAndChangePanel.add(priceChangePercentLbl); data = new Object[30][2]; String[] colnames = { "1", "2" }; GridBagConstraints c = new GridBagConstraints(); dataAndGraph.setLayout(new GridBagLayout()); c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 0; c.gridheight = 1; c.insets = new Insets(0, 20, 0, 20); dataAndGraph.add(nameAndChangePanel, c); c.weightx = 0; c.weighty = 1; c.insets = new Insets(0, 20, 0, 0); //c.ipady = 20; c.gridx = 0; c.gridy = 1; remainingInfoTable = new StockTable(data, colnames); remainingInfoTable.setShowGrid(false); remainingInfoTable.setTableHeader(null); remainingInfoTable.setBackground(this.getBackground()); remainingInfoTable.setFocusable(false); remainingInfoTable.setColumnSelectionAllowed(false); remainingInfoTable.setRowSelectionAllowed(false); remainingInfoTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); dataAndGraph.add(remainingInfoTable, c); this.add(dataAndGraph, BorderLayout.CENTER); c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 0; c.gridheight = 2; //c.ipady = 20; c.gridx = 1; c.gridy = 0; dataAndGraph.add(chartPane, c); chartPane.setVisible(false); this.add(dataAndGraph, BorderLayout.CENTER); Test.show_hist_data(currentStock, b); currentStock.calculate_beta(sp500, 1200); nameLbl.setText(currentStock.get_name() + " (" + currentStock.get_symbol() + ")"); nameLbl.setFont(new Font(nameLbl.getName(), Font.BOLD, 24)); priceChangePercentLbl.setText(currentStock.get_price() + " "); String message = currentStock.get_change() + " " + currentStock.get_percent_change(); if (Double.parseDouble(currentStock.get_change()) < 0) priceChangePercentLbl.setText(String.format("<html>%s<font color='red'>%s</font></html>", priceChangePercentLbl.getText(), message)); else priceChangePercentLbl.setText(String.format("<html>%s<font color='green'>%s</font></html>", priceChangePercentLbl.getText(), message)); priceChangePercentLbl.setFont(new Font(priceChangePercentLbl.getName(), Font.PLAIN, 15)); data[0][0] = "Prev Close: " + currentStock.get_prev_close(); data[1][0] = "Open: " + currentStock.get_open_price(); data[2][0] = "Bid: " + currentStock.get_bid(); data[3][0] = "Ask: " + currentStock.get_ask(); data[4][0] = "One Year Target: " + currentStock.get_one_year_target(); data[5][0] = "Ebita: " + currentStock.get_ebitda(); data[0][1] = "Day Range: " + currentStock.get_days_range(); data[1][1] = "52 Week Range: " + currentStock.get_year_range(); data[2][1] = "Volume: " + currentStock.get_volume(); data[3][1] = "Average Daily Volume: " + currentStock.get_avg_daily_volume(); data[4][1] = "Market Cap: " + currentStock.get_market_cap(); data[5][1] = "P/E: " + currentStock.get_pe(); data[6][1] = "EPS: " + currentStock.get_earnings_per_share(); data[7][1] = "Dividend (Yield): " + currentStock.get_dividend_per_share() + "(" + currentStock.get_dividend_yield() + ")"; data[6][0] = "Reveune:" + currentStock.get_revenue(); data[7][0] = "Earnings Estimate: " + currentStock.get_earnings_estimate_current_year(); data[8][0] = "Beta: " + currentStock.get_beta(); data[8][1] = "PEG Ratio: " + currentStock.get_peg_ratio(); data[9][0] = "Short Ratio: " + currentStock.get_short_ratio(); data[11][0] = "50 Day MA: " + currentStock.get_fiftyday_moving_avg(); data[12][0] = "200 Day MA: " + currentStock.get_twohundredday_moving_avg(); if (currentStock.get_change_from_fiftyday_moving_avg() != null && currentStock.get_change_from_fiftyday_moving_avg().contains("-")) { data[13][0] = String.format("<html>%s<font color='red'>%s</font></html>", "Change 50 Day MA: ", currentStock.get_change_from_fiftyday_moving_avg()); data[14][0] = String.format("<html>%s<font color='red'>%s</font></html>", "Percent 50 Day MA: ", currentStock.get_percent_change_from_fiftyday_moving_avg()); } else { data[13][0] = String.format("<html>%s<font color='green'>%s</font></html>", "Change 50 Day MA: ", currentStock.get_change_from_fiftyday_moving_avg()); data[14][0] = String.format("<html>%s<font color='green'>%s</font></html>", "Percent 50 Day MA: ", currentStock.get_percent_change_from_fiftyday_moving_avg()); } if (currentStock.get_change_from_twohundredday_moving_avg() != null && currentStock.get_change_from_twohundredday_moving_avg().contains("-")) { data[15][0] = String.format("<html>%s<font color='red'>%s</font></html>", "Change 200 Day MA: ", currentStock.get_change_from_twohundredday_moving_avg()); data[16][0] = String.format("<html>%s<font color='red'>%s</font></html>", "Percent 200 Day MA: ", currentStock.get_percent_change_from_twohundredday_moving_avg()); } else { data[15][0] = String.format("<html>%s<font color='green'>%s</font></html>", "Change 200 Day MA: ", currentStock.get_change_from_twohundredday_moving_avg()); data[16][0] = String.format("<html>%s<font color='green'>%s</font></html>", "Percent 200 Day MA: ", currentStock.get_percent_change_from_twohundredday_moving_avg()); } data[17][0] = "Year High: " + currentStock.get_year_high(); data[18][0] = "Year Low: " + currentStock.get_year_low(); if (currentStock.get_change_from_year_high() != null && currentStock.get_change_from_year_high().contains("-")) { data[19][0] = String.format("<html>%s<font color='red'>%s</font></html>", "Year High Change: ", currentStock.get_change_from_year_high()); data[20][0] = String.format("<html>%s<font color='red'>%s</font></html>", "Year High Percent: ", currentStock.get_percent_change_from_year_high()); } else { data[19][0] = String.format("<html>%s<font color='green'>%s</font></html>", "Year High Change: ", currentStock.get_change_from_year_high()); data[20][0] = String.format("<html>%s<font color='green'>%s</font></html>", "Year High Percent: ", currentStock.get_percent_change_from_year_high()); } if (currentStock.get_change_from_year_low() != null && currentStock.get_change_from_year_low().contains("-")) { data[21][0] = String.format("<html>%s<font color='red'>%s</font></html>", "Year Low Change: ", currentStock.get_change_from_year_low()); data[22][0] = String.format("<html>%s<font color='red'>%s</font></html>", "Year Low Percent: ", currentStock.get_percent_change_from_year_low()); } else { data[21][0] = String.format("<html>%s<font color='green'>%s</font></html>", "Year Low Change: ", currentStock.get_change_from_year_low()); data[22][0] = String.format("<html>%s<font color='green'>%s</font></html>", "Year Low Percent: ", currentStock.get_percent_change_from_year_low()); } if (currentStock.get_five_day_change()[0] != null && currentStock.get_five_day_change()[0].contains("-")) data[11][1] = String.format("<html>%s<font color='red'>%s</font></html>", "5D Change: ", currentStock.get_five_day_change()[0] + " (" + currentStock.get_five_day_change()[1] + ")"); else data[11][1] = String.format("<html>%s<font color='green'>%s</font></html>", "5D Change: ", currentStock.get_five_day_change()[0] + " (" + currentStock.get_five_day_change()[1] + ")"); if (currentStock.get_one_month_change()[0] != null && currentStock.get_one_month_change()[0].contains("-")) data[12][1] = String.format("<html>%s<font color='red'>%s</font></html>", "1M Change: ", currentStock.get_one_month_change()[0] + " (" + currentStock.get_one_month_change()[1] + ")"); else data[12][1] = String.format("<html>%s<font color='green'>%s</font></html>", "1M Change: ", currentStock.get_one_month_change()[0] + " (" + currentStock.get_one_month_change()[1] + ")"); if (currentStock.get_three_month_change()[0] != null && currentStock.get_three_month_change()[0].contains("-")) data[13][1] = String.format("<html>%s<font color='red'>%s</font></html>", "3M Change: ", currentStock.get_three_month_change()[0] + " (" + currentStock.get_three_month_change()[1] + ")"); else data[13][1] = String.format("<html>%s<font color='green'>%s</font></html>", "3M Change: ", currentStock.get_three_month_change()[0] + " (" + currentStock.get_three_month_change()[1] + ")"); if (currentStock.get_six_month_change()[0] != null && currentStock.get_six_month_change()[0].contains("-")) data[14][1] = String.format("<html>%s<font color='red'>%s</font></html>", "6M Change: ", currentStock.get_six_month_change()[0] + " (" + currentStock.get_six_month_change()[1] + ")"); else data[14][1] = String.format("<html>%s<font color='green'>%s</font></html>", "6M Change: ", currentStock.get_six_month_change()[0] + " (" + currentStock.get_six_month_change()[1] + ")"); if (currentStock.get_ytd_change()[0] != null && currentStock.get_ytd_change()[0].contains("-")) data[15][1] = String.format("<html>%s<font color='red'>%s</font></html>", "YTD Change: ", currentStock.get_ytd_change()[0] + " (" + currentStock.get_ytd_change()[1] + ")"); else data[15][1] = String.format("<html>%s<font color='green'>%s</font></html>", "YTD Change: ", currentStock.get_ytd_change()[0] + " (" + currentStock.get_ytd_change()[1] + ")"); if (currentStock.get_one_year_change()[0] != null && currentStock.get_one_year_change()[0].contains("-")) data[16][1] = String.format("<html>%s<font color='red'>%s</font></html>", "1Y Change: ", currentStock.get_one_year_change()[0] + " (" + currentStock.get_one_year_change()[1] + ")"); else data[16][1] = String.format("<html>%s<font color='green'>%s</font></html>", "1Y Change: ", currentStock.get_one_year_change()[0] + " (" + currentStock.get_one_year_change()[1] + ")"); if (currentStock.get_five_year_change()[0] != null && currentStock.get_five_year_change()[0].contains("-")) data[17][1] = String.format("<html>%s<font color='red'>%s</font></html>", "5Y Change: ", currentStock.get_five_year_change()[0] + " (" + currentStock.get_five_year_change()[1] + ")"); else data[17][1] = String.format("<html>%s<font color='green'>%s</font></html>", "5Y Change: ", currentStock.get_five_year_change()[0] + " (" + currentStock.get_five_year_change()[1] + ")"); if (currentStock.get_ten_year_change()[0] != null && currentStock.get_ten_year_change()[0].contains("-")) data[18][1] = String.format("<html>%s<font color='red'>%s</font></html>", "10Y Change: ", currentStock.get_ten_year_change()[0] + " (" + currentStock.get_ten_year_change()[1] + ")"); else data[18][1] = String.format("<html>%s<font color='green'>%s</font></html>", "10Y Change: ", currentStock.get_ten_year_change()[0] + " (" + currentStock.get_ten_year_change()[1] + ")"); if (currentStock.get_max_year_change()[0] != null && currentStock.get_max_year_change()[0].contains("-")) data[19][1] = String.format("<html>%s<font color='red'>%s</font></html>", "Max Change: ", currentStock.get_max_year_change()[0] + " (" + currentStock.get_max_year_change()[1] + ")"); else data[19][1] = String.format("<html>%s<font color='green'>%s</font></html>", "Max Change: ", currentStock.get_max_year_change()[0] + " (" + currentStock.get_max_year_change()[1] + ")"); data[24][0] = "Earnings Est Next Quarter: " + currentStock.get_earnings_estimate_next_quarter(); data[25][0] = "Earnings Est Current Year: " + currentStock.get_earnings_estimate_current_year(); data[26][0] = "Earnings Est Next Year: " + currentStock.get_earnings_estimate_next_year(); data[24][1] = "P/E Est Current Year: " + currentStock.get_price_eps_estimate_current_year(); data[25][1] = "P/E Est Next Year: " + currentStock.get_price_eps_estimate_next_year(); remainingInfoTable.setFont(new Font(remainingInfoTable.getName(), Font.PLAIN, 15)); remainingInfoTable.packColumn(0, 4); remainingInfoTable.packColumn(1, 4); try { dataAndGraph.remove(chartPane); chartPane = new JTabbedPane(); chartPane.setVisible(true); ChartPanel intradayChart = new IntradayChart(currentStock).getChartPanel(); intradayChart.setPopupMenu(graphMenu); chartPane.addTab("1d", intradayChart); chartPane.setMnemonicAt(0, KeyEvent.VK_1); ChartPanel fivedayChart = new FiveDayChart(currentStock).getChartPanel(); fivedayChart.setPopupMenu(graphMenu); chartPane.addTab("5d", fivedayChart); chartPane.setMnemonicAt(0, KeyEvent.VK_2); ChartPanel onemonthChart = new OneMonthChart(currentStock).getChartPanel(); onemonthChart.setPopupMenu(graphMenu); chartPane.addTab("1m", onemonthChart); chartPane.setMnemonicAt(0, KeyEvent.VK_3); ChartPanel threemonthChart = new ThreeMonthChart(currentStock).getChartPanel(); threemonthChart.setPopupMenu(graphMenu); chartPane.addTab("3m", threemonthChart); chartPane.setMnemonicAt(0, KeyEvent.VK_4); ChartPanel sixmonthChart = new SixMonthChart(currentStock).getChartPanel(); sixmonthChart.setPopupMenu(graphMenu); chartPane.addTab("6m", sixmonthChart); chartPane.setMnemonicAt(0, KeyEvent.VK_5); ChartPanel ytdChart = new YTDChart(currentStock).getChartPanel(); ytdChart.setPopupMenu(graphMenu); chartPane.addTab("ytd", ytdChart); chartPane.setMnemonicAt(0, KeyEvent.VK_6); ChartPanel oneyearChart = new OneYearChart(currentStock).getChartPanel(); oneyearChart.setPopupMenu(graphMenu); chartPane.addTab("1y", oneyearChart); chartPane.setMnemonicAt(0, KeyEvent.VK_7); ChartPanel fiveyearChart = new FiveYearChart(currentStock).getChartPanel(); fiveyearChart.setPopupMenu(graphMenu); chartPane.addTab("5y", fiveyearChart); chartPane.setMnemonicAt(0, KeyEvent.VK_8); ChartPanel tenyearChart = new TenYearChart(currentStock).getChartPanel(); tenyearChart.setPopupMenu(graphMenu); chartPane.addTab("10y", tenyearChart); chartPane.setMnemonicAt(0, KeyEvent.VK_9); ChartPanel maxChart = new MaxChart(currentStock).getChartPanel(); maxChart.setPopupMenu(graphMenu); chartPane.addTab("max", maxChart); chartPane.setMnemonicAt(0, KeyEvent.VK_0); c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 0; c.gridheight = 2; //c.ipady = 20; c.gridx = 1; c.gridy = 0; dataAndGraph.add(chartPane, c); } catch (ParseException ex) { Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex); } chartPane.revalidate(); chartPane.repaint(); revalidate(); repaint(); finished = true; }
From source file:EditorPaneExample12.java
public EditorPaneExample12() { super("JEditorPane Example 12"); 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 . ja v 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.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(); loadNewPage(selection); } }); // 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(); 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:com.t3.macro.api.functions.input.ColumnPanel.java
public ColumnPanel() { tabVarSpec = null;//from w w w .j ava 2s . co m varSpecs = new ArrayList<VarSpec>(); labels = new ArrayList<JComponent>(); inputFields = new ArrayList<JComponent>(); lastFocus = null; onShowFocus = null; textInsets = new Insets(0, 2, 0, 2); // used by all TEXT controls setLayout(new GridBagLayout()); gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.NORTHWEST; gbc.insets = new Insets(2, 2, 2, 2); componentCount = 0; }
From source file:com.litt.core.security.license.gui.ConfigPanel.java
/** * Create the panel.//from w w w . jav a 2s . c o m */ public ConfigPanel(final Gui gui) { GridBagLayout gbl_configPanel = new GridBagLayout(); gbl_configPanel.columnWidths = new int[] { 0, 0, 0, 0 }; gbl_configPanel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; gbl_configPanel.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE }; gbl_configPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE }; this.setLayout(gbl_configPanel); JLabel label_18 = new JLabel("?"); GridBagConstraints gbc_label_18 = new GridBagConstraints(); gbc_label_18.insets = new Insets(0, 0, 5, 5); gbc_label_18.anchor = GridBagConstraints.EAST; gbc_label_18.gridx = 0; gbc_label_18.gridy = 0; this.add(label_18, gbc_label_18); comboBox_config = new JComboBox(); comboBox_config.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { try { LicenseConfig licenseConfig = (LicenseConfig) e.getItem(); File licenseFile = new File(licenseConfig.getLicenseFilePath()); currentLicenseConfig = licenseConfig; loadLicense(licenseFile); gui.setCurrentLicenseConfig(currentLicenseConfig); } catch (Exception e1) { JOptionPane.showMessageDialog(self, e1.getMessage()); } } } }); GridBagConstraints gbc_comboBox_config = new GridBagConstraints(); gbc_comboBox_config.insets = new Insets(0, 0, 5, 5); gbc_comboBox_config.fill = GridBagConstraints.HORIZONTAL; gbc_comboBox_config.gridx = 1; gbc_comboBox_config.gridy = 0; this.add(comboBox_config, gbc_comboBox_config); JButton button_3 = new JButton("?"); button_3.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { try { comboBox_config.removeAllItems(); File configFile = new File(Gui.HOME_PATH + File.separator + "config.xml"); Document document = XmlUtils.readXml(configFile); Element rootE = document.getRootElement(); List productList = rootE.elements(); for (int i = 0; i < productList.size(); i++) { Element productE = (Element) productList.get(i); String productCode = productE.attributeValue("code"); List customerList = productE.elements(); for (int j = 0; j < customerList.size(); j++) { Element customerE = (Element) customerList.get(j); String customerCode = customerE.attributeValue("code"); LicenseConfig licenseConfig = new LicenseConfig(); licenseConfig.setProductCode(productCode); licenseConfig.setCustomerCode(customerCode); licenseConfig.setLicenseId(customerE.elementText("licenseId")); licenseConfig.setEncryptedLicense(customerE.elementText("encryptedLicense")); licenseConfig.setRootFilePath(Gui.HOME_PATH); licenseConfig.setLicenseFilePath(Gui.HOME_PATH + File.separator + productCode + File.separator + customerCode + File.separator + "license.xml"); licenseConfig.setPriKeyFilePath( Gui.HOME_PATH + File.separator + productCode + File.separator + "private.key"); licenseConfig.setPubKeyFilePath( Gui.HOME_PATH + File.separator + productCode + File.separator + "license.key"); comboBox_config.addItem(licenseConfig); if (i == 0 && j == 0) { File licenseFile = new File(licenseConfig.getLicenseFilePath()); currentLicenseConfig = licenseConfig; loadLicense(licenseFile); gui.setCurrentLicenseConfig(currentLicenseConfig); btnDelete.setEnabled(true); } } } } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(self, e1.getMessage()); } } }); btnDelete = new JButton(); btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (currentLicenseConfig != null) { try { String productCode = currentLicenseConfig.getProductCode(); String customerCode = currentLicenseConfig.getCustomerCode(); //congfig.xml File configFile = new File(Gui.HOME_PATH + File.separator + "config.xml"); Document document = XmlUtils.readXml(configFile); Element customerNode = (Element) document.selectSingleNode( "//product[@code='" + productCode + "']/customer[@code='" + customerCode + "']"); if (customerNode != null) { customerNode.detach(); XmlUtils.writeXml(configFile, document); } // File licensePathFile = new File(currentLicenseConfig.getLicenseFilePath()); if (licensePathFile.exists()) { FileUtils.deleteDirectory(licensePathFile.getParentFile()); } //comboboxitem comboBox_config.removeItemAt(comboBox_config.getSelectedIndex()); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (comboBox_config.getItemCount() <= 0) { btnDelete.setEnabled(false); } } } }); btnDelete.setEnabled(false); btnDelete.setIcon(new ImageIcon(ConfigPanel.class.getResource("/images/icon_delete.png"))); GridBagConstraints gbc_btnDelete = new GridBagConstraints(); gbc_btnDelete.insets = new Insets(0, 0, 5, 0); gbc_btnDelete.gridx = 2; gbc_btnDelete.gridy = 0; add(btnDelete, gbc_btnDelete); GridBagConstraints gbc_button_3 = new GridBagConstraints(); gbc_button_3.insets = new Insets(0, 0, 5, 5); gbc_button_3.gridx = 1; gbc_button_3.gridy = 1; this.add(button_3, gbc_button_3); JLabel lblid = new JLabel("?ID"); GridBagConstraints gbc_lblid = new GridBagConstraints(); gbc_lblid.anchor = GridBagConstraints.EAST; gbc_lblid.insets = new Insets(0, 0, 5, 5); gbc_lblid.gridx = 0; gbc_lblid.gridy = 2; this.add(lblid, gbc_lblid); textField_licenseId = new JTextField(); GridBagConstraints gbc_textField_licenseId = new GridBagConstraints(); gbc_textField_licenseId.insets = new Insets(0, 0, 5, 5); gbc_textField_licenseId.fill = GridBagConstraints.HORIZONTAL; gbc_textField_licenseId.gridx = 1; gbc_textField_licenseId.gridy = 2; this.add(textField_licenseId, gbc_textField_licenseId); textField_licenseId.setColumns(10); JLabel label = new JLabel("?"); GridBagConstraints gbc_label = new GridBagConstraints(); gbc_label.anchor = GridBagConstraints.EAST; gbc_label.insets = new Insets(0, 0, 5, 5); gbc_label.gridx = 0; gbc_label.gridy = 3; add(label, gbc_label); comboBox_licenseType = new JComboBox(MapComboBoxModel.getLicenseTypeOptions().toArray()); GridBagConstraints gbc_comboBox_licenseType = new GridBagConstraints(); gbc_comboBox_licenseType.insets = new Insets(0, 0, 5, 5); gbc_comboBox_licenseType.fill = GridBagConstraints.HORIZONTAL; gbc_comboBox_licenseType.gridx = 1; gbc_comboBox_licenseType.gridy = 3; add(comboBox_licenseType, gbc_comboBox_licenseType); JLabel label_23 = new JLabel("???"); GridBagConstraints gbc_label_23 = new GridBagConstraints(); gbc_label_23.anchor = GridBagConstraints.EAST; gbc_label_23.insets = new Insets(0, 0, 5, 5); gbc_label_23.gridx = 0; gbc_label_23.gridy = 4; this.add(label_23, gbc_label_23); textField_productName = new JTextField(); GridBagConstraints gbc_textField_productName = new GridBagConstraints(); gbc_textField_productName.insets = new Insets(0, 0, 5, 5); gbc_textField_productName.fill = GridBagConstraints.HORIZONTAL; gbc_textField_productName.gridx = 1; gbc_textField_productName.gridy = 4; this.add(textField_productName, gbc_textField_productName); textField_productName.setColumns(10); JLabel label_24 = new JLabel("???"); GridBagConstraints gbc_label_24 = new GridBagConstraints(); gbc_label_24.anchor = GridBagConstraints.EAST; gbc_label_24.insets = new Insets(0, 0, 5, 5); gbc_label_24.gridx = 0; gbc_label_24.gridy = 5; this.add(label_24, gbc_label_24); textField_companyName = new JTextField(); GridBagConstraints gbc_textField_companyName = new GridBagConstraints(); gbc_textField_companyName.insets = new Insets(0, 0, 5, 5); gbc_textField_companyName.fill = GridBagConstraints.HORIZONTAL; gbc_textField_companyName.gridx = 1; gbc_textField_companyName.gridy = 5; this.add(textField_companyName, gbc_textField_companyName); textField_companyName.setColumns(10); JLabel label_25 = new JLabel("??"); GridBagConstraints gbc_label_25 = new GridBagConstraints(); gbc_label_25.anchor = GridBagConstraints.EAST; gbc_label_25.insets = new Insets(0, 0, 5, 5); gbc_label_25.gridx = 0; gbc_label_25.gridy = 6; this.add(label_25, gbc_label_25); textField_customerName = new JTextField(); GridBagConstraints gbc_textField_customerName = new GridBagConstraints(); gbc_textField_customerName.insets = new Insets(0, 0, 5, 5); gbc_textField_customerName.fill = GridBagConstraints.HORIZONTAL; gbc_textField_customerName.gridx = 1; gbc_textField_customerName.gridy = 6; this.add(textField_customerName, gbc_textField_customerName); textField_customerName.setColumns(10); JLabel label_26 = new JLabel(""); GridBagConstraints gbc_label_26 = new GridBagConstraints(); gbc_label_26.anchor = GridBagConstraints.EAST; gbc_label_26.insets = new Insets(0, 0, 5, 5); gbc_label_26.gridx = 0; gbc_label_26.gridy = 7; this.add(label_26, gbc_label_26); textField_version = new JTextField(); GridBagConstraints gbc_textField_version = new GridBagConstraints(); gbc_textField_version.insets = new Insets(0, 0, 5, 5); gbc_textField_version.fill = GridBagConstraints.HORIZONTAL; gbc_textField_version.gridx = 1; gbc_textField_version.gridy = 7; this.add(textField_version, gbc_textField_version); textField_version.setColumns(10); JLabel label_27 = new JLabel(""); GridBagConstraints gbc_label_27 = new GridBagConstraints(); gbc_label_27.insets = new Insets(0, 0, 5, 5); gbc_label_27.gridx = 0; gbc_label_27.gridy = 8; this.add(label_27, gbc_label_27); datePicker_expiredDate = new DatePicker(new Date(), "yyyy-MM-dd", null, null); //datePicker_expiredDate.setTimePanleVisible(false); GridBagConstraints gbc_datePicker_expiredDate = new GridBagConstraints(); gbc_datePicker_expiredDate.anchor = GridBagConstraints.WEST; gbc_datePicker_expiredDate.insets = new Insets(0, 0, 5, 5); gbc_datePicker_expiredDate.gridx = 1; gbc_datePicker_expiredDate.gridy = 8; this.add(datePicker_expiredDate, gbc_datePicker_expiredDate); JButton button_5 = new JButton(""); button_5.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (currentLicenseConfig != null) { try { File priKeyFile = new File(currentLicenseConfig.getPriKeyFilePath()); File licenseFile = new File(currentLicenseConfig.getLicenseFilePath()); //?? License license = new License(); license.setLicenseId(textField_licenseId.getText()); license.setLicenseType( ((MapComboBoxModel) comboBox_licenseType.getSelectedItem()).getValue().toString()); license.setProductName(textField_productName.getText()); license.setCompanyName(textField_companyName.getText()); license.setCustomerName(textField_customerName.getText()); license.setVersion(Version.parseVersion(textField_version.getText())); license.setCreateDate(new Date()); license.setExpiredDate(Utility.parseDate(datePicker_expiredDate.getText())); //???? DigitalSignatureTool utils = new DigitalSignatureTool("DSA"); utils.readPriKey(priKeyFile.getAbsolutePath()); //?? String signedData = utils.sign(license.toString()); //?????? license.setSignature(signedData); LicenseManager.writeLicense(license, licenseFile); //config.xml String licenseContent = XmlUtils.readXml(licenseFile).asXML(); //DES ISecurity security = new DESTool(currentLicenseConfig.getLicenseId(), Algorithm.BLOWFISH); licenseContent = security.encrypt(licenseContent); txt_encryptContent.setText(licenseContent); currentLicenseConfig.setEncryptedLicense(licenseContent); System.out.println(licenseContent); File configFile = new File(Gui.HOME_PATH + File.separator + "config.xml"); XMLConfiguration config = new XMLConfiguration(configFile); config.setAutoSave(true); config.setProperty("product.customer.encryptedLicense", licenseContent); //??zip? File customerPath = licenseFile.getParentFile(); //???license????? File licensePath = new File(customerPath.getParent(), "license"); if (!licensePath.exists() && !licensePath.isDirectory()) { licensePath.mkdir(); } else { FileUtils.cleanDirectory(licensePath); } //? FileUtils.copyDirectory(customerPath, licensePath); String currentTime = FormatDateTime.formatDateTimeNum(new Date()); ZipUtils.zip(licensePath, new File(licensePath.getParentFile(), currentLicenseConfig.getCustomerCode() + "-" + currentTime + ".zip")); //license FileUtils.deleteDirectory(licensePath); JOptionPane.showMessageDialog(self, "??"); } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(self, e1.getMessage()); } } else { JOptionPane.showMessageDialog(self, "???"); } } }); GridBagConstraints gbc_button_5 = new GridBagConstraints(); gbc_button_5.insets = new Insets(0, 0, 5, 5); gbc_button_5.gridx = 1; gbc_button_5.gridy = 9; this.add(button_5, gbc_button_5); JScrollPane scrollPane = new JScrollPane(); GridBagConstraints gbc_scrollPane = new GridBagConstraints(); gbc_scrollPane.insets = new Insets(0, 0, 0, 5); gbc_scrollPane.fill = GridBagConstraints.BOTH; gbc_scrollPane.gridx = 1; gbc_scrollPane.gridy = 10; this.add(scrollPane, gbc_scrollPane); txt_encryptContent = new JTextArea(); txt_encryptContent.setLineWrap(true); scrollPane.setViewportView(txt_encryptContent); // txt_encryptContent = new JTextArea(20, 20); // GridBagConstraints gbc_6 = new GridBagConstraints(); // gbc_6.gridx = 1; // gbc_6.gridy = 10; // this.add(txt_encryptContent, gbc_6); }
From source file:com.github.cmisbox.ui.BaseFrame.java
public BaseFrame() { super(AWTUtilitiesWrapper.isTranslucencyCapable(BaseFrame.gc) ? BaseFrame.gc : null); this.log = LogFactory.getLog(this.getClass()); this.gradient = false; this.setUndecorated(true); this.mainPanel = new JPanel(new GridBagLayout()) { private static final long serialVersionUID = 1035974033526970010L; protected void paintComponent(Graphics g) { if ((g instanceof Graphics2D) && BaseFrame.this.gradient) { final int R = 0; final int G = 0; final int B = 0; Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 192), this.getWidth(), this.getHeight(), new Color(R, G, B, 255), true); Graphics2D g2d = (Graphics2D) g; g2d.setPaint(p);/* w ww . j a v a 2 s. com*/ g2d.fillRect(0, 0, this.getWidth(), this.getHeight()); } else { super.paintComponent(g); } } }; this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); GridBagConstraints gbc = new GridBagConstraints(); this.mainPanel.setDoubleBuffered(false); this.mainPanel.setOpaque(false); this.mainPanel.setBorder(BorderFactory.createLineBorder(Color.white)); JLabel title = new JLabel(this.getWindowTitle(), SwingConstants.CENTER); title.setForeground(Color.white); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 1; gbc.gridy = 0; gbc.weightx = 100; this.mainPanel.add(title, gbc); Image closeImg = this.getImage("images/application-exit.png", 32, 32); JLabel close = new JLabel(new ImageIcon(closeImg), SwingConstants.RIGHT); gbc.fill = GridBagConstraints.NONE; gbc.gridx = 2; gbc.weightx = 0; this.mainPanel.add(close, gbc); close.addMouseListener(this.closeAdapter); this.getContentPane().add(this.mainPanel, BorderLayout.CENTER); this.initComponents(); this.pack(); this.mainPanel.setOpaque(!this.gradient); if (!this.gradient) { this.mainPanel.setBackground(new Color(0, 0, 0, 208)); } this.setLocationRelativeTo(null); AWTUtilitiesWrapper.setWindowOpaque(this, false); this.setVisible(true); this.setAlwaysOnTop(true); }
From source file:de.costache.calendar.JCalendar.java
/** * Initializes the GUI// www.j a va2 s .co m */ private void initGui() { this.setBackground(Color.white); headerPane = new HeaderPanel(this); contentPane = new ContentPanel(this); headerPane.getIntervalLabel().setText(contentPane.getStrategy().getDisplayInterval()); this.setLayout(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = GridBagConstraints.BOTH; add(headerPane, c); c.gridx = 0; c.gridy = 1; c.weighty = 0.9; c.insets = new Insets(10, 10, 10, 10); add(contentPane, c); }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
public NumberToBoxPlot() { setName("Number to BoxPlot"); setDescription("Use bar height to represent numeric values"); //initialize UI configUI.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0;/*from w w w. ja v a 2 s . co m*/ c.gridy = 0; c.ipadx = 5; c.ipady = 5; c.insets = new Insets(5, 5, 5, 5); c.gridwidth = 1; c.gridx = 0; c.gridy++; c.gridwidth = 1; // JButton button = new JButton("Apply"); // configUI.add(button, c); // button.setToolTipText("Apply preset data ranges"); // button.addActionListener(new ActionListener() { // // @Override // public void actionPerformed(ActionEvent e) { // try { // MinMaxItem item = (MinMaxItem) (presetRangeComboBox.getSelectedItem()); // minValueField.setText(item.getMinMax().lowerEndpoint().toString()); // maxValueField.setText(item.getMinMax().upperEndpoint().toString()); // } catch (Exception ex) { // minValueField.setText("-1"); // maxValueField.setText("1"); // } // // updateRenderer(); // } // }); configUI.add(new JLabel("Preset range:"), c); c.gridx = 1; c.gridwidth = 1; presetRangeComboBox = new JComboBox(); configUI.add(presetRangeComboBox, c); presetRangeComboBox.addItem(new DataMinMaxItem()); presetRangeComboBox.addItem(new DefinedMinMaxItem(-1, 1)); presetRangeComboBox.addItem(new DefinedMinMaxItem(0, 1)); presetRangeComboBox.addItem(new DefinedMinMaxItem(-1, 0)); presetRangeComboBox.addItem(new DefinedMinMaxItem(0, 100)); presetRangeComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { try { MinMaxItem item = (MinMaxItem) (presetRangeComboBox.getSelectedItem()); minValueField.setText(item.getMinMax().lowerEndpoint().toString()); maxValueField.setText(item.getMinMax().upperEndpoint().toString()); } catch (Exception ex) { minValueField.setText("-1"); maxValueField.setText("1"); } } }); //////////////////////////////////////////////////////////////////////////////// // c.weightx = 0.2; c.gridx = 0; c.gridy++; c.gridwidth = 1; configUI.add(new JLabel("Min value: "), c); c.gridx = 1; // c.weightx = 0.3; configUI.add(minValueField, c); c.gridx = 0; c.gridy++; c.gridwidth = 1; configUI.add(new JLabel("Max value: "), c); c.gridx = 1; configUI.add(maxValueField, c); c.gridx = 0; c.gridy++; c.gridwidth = 1; configUI.add(new JLabel("Disect boundary: "), c); c.gridx = 1; configUI.add(disectField, c); disectField.setText("0"); c.gridx = 0; c.gridy++; c.gridwidth = 3; JButton button = new JButton("Update", UI.getImageIcon("refresh")); configUI.add(button, c); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //hit button, redraw! updateRenderer(); } }); }
From source file:geneon.intellij.plugin.jenkins.ui.EditServerDialog.java
@Nullable @Override//from w w w. jav a 2 s .co m protected JComponent createCenterPanel() { nameTextField.setMinimumSize(new Dimension(300, 10)); urlTextField.setMinimumSize(new Dimension(300, 10)); JButton testButton = new JButton("Test"); testButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { testSettings(); } }); JPanel panel = new JPanel(new GridBagLayout()); JLabel nameLabel = new JLabel("Server name:"); panel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 10), 0, 0)); panel.add(nameTextField, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0)); JLabel urlLabel = new JLabel("URL:"); panel.add(urlLabel, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 10), 0, 0)); panel.add(urlTextField, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0)); panel.add(testButton, new GridBagConstraints(0, 2, 2, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 0), 0, 0)); return panel; }
From source file:EditorPaneExample16.java
public EditorPaneExample16() { super("JEditorPane Example 16"); pane = new JEditorPane(); pane.setEditable(true); // Editable 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 va 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.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.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(); 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)); 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:ContainerEventDemo.java
public ContainerEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); //Initialize an empty list of buttons. buttonList = new Vector(10, 10); //Create all the components. addButton = new JButton("Add a button"); addButton.setActionCommand(ADD);/*from w w w. j ava 2s . c o 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)); }