List of usage examples for javax.swing JPanel setLayout
public void setLayout(LayoutManager mgr)
From source file:captureplugin.drivers.DeviceCreatorDialog.java
/** * Create the GUI//from w ww . j a va 2s .c o m */ private void createGUI() { UiUtilities.registerForClosing(this); DriverIf[] drivers = DriverFactory.getInstance().getDrivers(); mDriverCombo = new JComboBox(drivers); mDriverCombo.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof DriverIf) { value = ((DriverIf) value).getDriverName(); } return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); JPanel panel = (JPanel) getContentPane(); panel.setLayout(new GridBagLayout()); GridBagConstraints label = new GridBagConstraints(); label.insets = new Insets(5, 5, 5, 5); label.anchor = GridBagConstraints.NORTHWEST; GridBagConstraints input = new GridBagConstraints(); input.fill = GridBagConstraints.HORIZONTAL; input.weightx = 1.0; input.gridwidth = GridBagConstraints.REMAINDER; input.insets = new Insets(5, 5, 5, 5); panel.add(new JLabel(mLocalizer.msg("Name", "Name")), label); mName = new JTextField(); panel.add(mName, input); panel.add(new JLabel(mLocalizer.msg("Driver", "Driver")), label); panel.add(mDriverCombo, input); mDesc = UiUtilities.createHtmlHelpTextArea(""); mDesc.setEditable(false); panel.add(new JLabel(mLocalizer.msg("Description", "Description")), input); GridBagConstraints descC = new GridBagConstraints(); descC.weightx = 1.0; descC.weighty = 1.0; descC.fill = GridBagConstraints.BOTH; descC.gridwidth = GridBagConstraints.REMAINDER; descC.insets = new Insets(5, 5, 5, 5); panel.add(new JScrollPane(mDesc, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), descC); final Font font = new JLabel().getFont(); String desc = ((DriverIf) mDriverCombo.getSelectedItem()).getDriverDesc(); desc = "<html><div style=\"color:#000000;font-family:" + font.getName() + "; font-size:" + font.getSize() + ";\">" + desc + "</div></html>"; mDesc.setText(desc); mDesc.setFont(font); mDriverCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { String description = ((DriverIf) mDriverCombo.getSelectedItem()).getDriverDesc(); description = "<html><div style=\"color:#000000;font-family:" + font.getName() + "; font-size:" + font.getSize() + ";\">" + description + "</div></html>"; mDesc.setText(description); mDesc.setFont(font); } }); final JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); ok.setEnabled(false); final JButton cancel = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okPressed(); } }); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); mName.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { updateButtons(); } @Override public void insertUpdate(DocumentEvent e) { updateButtons(); } @Override public void changedUpdate(DocumentEvent e) { updateButtons(); } private void updateButtons() { ok.setEnabled(!mName.getText().trim().isEmpty()); } }); ButtonBarBuilder2 builder = new ButtonBarBuilder2(); builder.addGlue(); builder.addButton(new JButton[] { ok, cancel }); getRootPane().setDefaultButton(ok); input.insets = new Insets(5, 5, 5, 5); panel.add(builder.getPanel(), input); setSize(400, 300); }
From source file:com.titan.storagepanel.DownloadImageDialog.java
public DownloadImageDialog(final Frame frame) { super(frame, true); setTitle("Openstack vm os image"); setBounds(100, 100, 947, 706);//w w w .ja va 2 s . co m getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new BorderLayout(0, 0)); { JPanel panel = new JPanel(); contentPanel.add(panel, BorderLayout.NORTH); panel.setLayout(new MigLayout("", "[41px][107.00px][27px][95.00px][24px][95.00px][]", "[27px]")); { JLabel lblSearch = new JLabel("Search"); panel.add(lblSearch, "cell 0 0,alignx left,aligny center"); } { searchTextField = new JSearchTextField(); searchTextField.setPreferredSize(new Dimension(150, 40)); panel.add(searchTextField, "cell 1 0,growx,aligny center"); } { JLabel lblType = new JLabel("Type"); panel.add(lblType, "cell 2 0,alignx left,aligny center"); } { typeComboBox = new JComboBox( new String[] { "All", "Ubuntu", "Fedora", "Redhat", "CentOS", "Gentoo", "Windows" }); panel.add(typeComboBox, "cell 3 0,growx,aligny top"); } { JLabel lblSize = new JLabel("Size"); panel.add(lblSize, "cell 4 0,alignx left,aligny center"); } { sizeComboBox = new JComboBox(new String[] { "0-700MB", ">700MB" }); panel.add(sizeComboBox, "cell 5 0,growx,aligny top"); } { JButton btnSearch = new JButton("Search"); btnSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { d.setVisible(true); } }); panel.add(btnSearch, "cell 6 0"); } } { JScrollPane scrollPane = new JScrollPane(); contentPanel.add(scrollPane, BorderLayout.CENTER); { table = new JTable(); table.setModel(tableModel); table.addMouseListener(new JTableButtonMouseListener(table)); table.addMouseMotionListener(new JTableButtonMouseListener(table)); scrollPane.setViewportView(table); } } { JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.SOUTH); { JButton downloadButton = new JButton("Download"); downloadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (table.getSelectedRowCount() == 1) { JFileChooser jf = new JFileChooser(); int x = jf.showSaveDialog(frame); if (x == JFileChooser.APPROVE_OPTION) { DownloadImage p = (DownloadImage) table.getValueAt(table.getSelectedRow(), 0); DownloadFileDialog d = new DownloadFileDialog(frame, "Downloading image", true, p.file, jf.getSelectedFile()); CommonLib.centerDialog(d); d.setVisible(true); } } } }); panel.add(downloadButton); } } d = new JProgressBarDialog(frame, true); d.progressBar.setIndeterminate(true); d.progressBar.setStringPainted(true); d.thread = new Thread() { public void run() { InputStream in = null; tableModel.columnNames.clear(); tableModel.columnNames.add("image"); tableModel.editables.clear(); tableModel.editables.put(0, true); Vector<Object> col1 = new Vector<Object>(); try { d.progressBar.setString("connecting to titan image site"); in = new URL("http://titan-image.kingofcoders.com/titan-image.xml").openStream(); String xml = IOUtils.toString(in); NodeList list = TitanCommonLib.getXPathNodeList(xml, "/images/image"); for (int x = 0; x < list.getLength(); x++) { DownloadImage downloadImage = new DownloadImage(); downloadImage.author = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/author/text()"); downloadImage.authorEmail = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/authorEmail/text()"); downloadImage.License = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/License/text()"); downloadImage.description = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/description/text()"); downloadImage.file = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/file/text()"); downloadImage.os = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/os/text()"); downloadImage.osType = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/osType/text()"); downloadImage.uploadDate = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse( TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/uploadDate/text()")); downloadImage.size = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/size/text()"); downloadImage.architecture = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/architecture/text()"); col1.add(downloadImage); } } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(frame, "Unable to connect titan image site !", "Error", JOptionPane.ERROR_MESSAGE); } finally { IOUtils.closeQuietly(in); } tableModel.values.clear(); tableModel.values.add(col1); tableModel.fireTableStructureChanged(); table.getColumnModel().getColumn(0).setCellRenderer(new DownloadImageTableCellRenderer()); // table.getColumnModel().getColumn(0).setCellEditor(new DownloadImageTableCellEditor()); for (int x = 0; x < table.getRowCount(); x++) { table.setRowHeight(x, 150); } } }; d.setVisible(true); }
From source file:org.tinymediamanager.ui.dialogs.FeedbackDialog.java
/** * Instantiates a new feedback dialog.//w w w. ja v a 2s . c om */ public FeedbackDialog() { super(BUNDLE.getString("Feedback"), "feedback"); //$NON-NLS-1$ setBounds(100, 100, 450, 320); getContentPane().setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(400px;min):grow"), FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("fill:max(250px;min):grow"), FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, })); JPanel panelContent = new JPanel(); getContentPane().add(panelContent, "2, 2, fill, fill"); panelContent.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.PARAGRAPH_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.NARROW_LINE_GAP_ROWSPEC, RowSpec.decode("default:grow"), })); JLabel lblName = new JLabel(BUNDLE.getString("Feedback.name")); //$NON-NLS-1$ panelContent.add(lblName, "2, 2, right, default"); tfName = new JTextField(); panelContent.add(tfName, "4, 2, fill, default"); tfName.setColumns(10); JLabel lblEmailoptional = new JLabel(BUNDLE.getString("Feedback.email")); //$NON-NLS-1$ panelContent.add(lblEmailoptional, "2, 4, right, default"); tfEmail = new JTextField(); panelContent.add(tfEmail, "4, 4, fill, default"); tfEmail.setColumns(10); // pre-fill dialog if (Globals.isDonator()) { Properties p = License.decrypt(); tfEmail.setText(p.getProperty("email")); tfName.setText(p.getProperty("user")); } JLabel lblFeedback = new JLabel(BUNDLE.getString("Feedback.message")); //$NON-NLS-1$ panelContent.add(lblFeedback, "2, 6, 3, 1"); JScrollPane scrollPane = new JScrollPane(); panelContent.add(scrollPane, "2, 8, 3, 1, fill, fill"); textArea = new JTextArea(); scrollPane.setViewportView(textArea); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); JPanel panelButtons = new JPanel(); panelButtons.setLayout(new EqualsLayout(5)); getContentPane().add(panelButtons, "2, 4, fill, fill"); JButton btnSend = new JButton(BUNDLE.getString("Feedback")); //$NON-NLS-1$ btnSend.setIcon(IconManager.APPLY); btnSend.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // check if feedback is provided if (StringUtils.isEmpty(textArea.getText())) { JOptionPane.showMessageDialog(null, BUNDLE.getString("Feedback.message.empty")); //$NON-NLS-1$ return; } // send feedback HttpClient client = TmmHttpClient.getHttpClient(); HttpPost post = new HttpPost( "https://script.google.com/macros/s/AKfycbxTIhI58gwy0UJ0Z1CdmZDdHlwBDU_vugBmQxcKN9aug4nfgrgZ/exec"); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); StringBuilder message = new StringBuilder("Feedback from "); message.append(tfName.getText()); message.append("\nEmail:"); message.append(tfEmail.getText()); message.append("\n"); message.append("\nis Donator?: "); message.append(Globals.isDonator()); message.append("\nVersion: "); message.append(ReleaseInfo.getRealVersion()); message.append("\nBuild: "); message.append(ReleaseInfo.getRealBuildDate()); message.append("\nOS: "); message.append(System.getProperty("os.name")); message.append(" "); message.append(System.getProperty("os.version")); message.append("\nJDK: "); message.append(System.getProperty("java.version")); message.append(" "); message.append(System.getProperty("java.vendor")); message.append("\nUUID: "); message.append(System.getProperty("tmm.uuid")); message.append("\n\n"); message.append(textArea.getText()); nameValuePairs.add(new BasicNameValuePair("message", message.toString())); nameValuePairs.add(new BasicNameValuePair("sender", tfEmail.getText())); post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); HttpResponse response = client.execute(post); HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); } catch (IOException e) { LOGGER.error("failed sending feedback: " + e.getMessage()); JOptionPane.showMessageDialog(null, BUNDLE.getString("Feedback.send.error") + "\n" + e.getMessage()); //$NON-NLS-1$ return; } JOptionPane.showMessageDialog(null, BUNDLE.getString("Feedback.send.ok")); //$NON-NLS-1$ setVisible(false); } }); panelButtons.add(btnSend); JButton btnCacnel = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$ btnCacnel.setIcon(IconManager.CANCEL); btnCacnel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); panelButtons.add(btnCacnel); }
From source file:de.codesourcery.eve.skills.ui.components.impl.planning.CalendarEntryEditorComponent.java
@Override protected JPanel createPanelHook() { startDateField.setText(format(startDate)); startDateField.setEditable(false);//from w w w . ja v a 2 s . c om startDateField.setColumns(13); durationTextField.setColumns(13); notes.setLineWrap(true); notes.setWrapStyleWord(true); durationTextField.setColumns(6); summaryTextField.addActionListener(closeOnEnterListener); durationTextField.addActionListener(closeOnEnterListener); reminderOffsetTextField.addActionListener(closeOnEnterListener); final DefaultListCellRenderer durationTypeRenderer = new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); setText(((Duration.Type) value).getDisplayName()); return this; } }; durationType.setRenderer(durationTypeRenderer); reminderOffsetType.setRenderer(durationTypeRenderer); durationType.setSelectedItem(Duration.Type.DAYS); reminderOffsetType.setSelectedItem(Duration.Type.DAYS); reminderEnabled.setEnabled(true); reminderOffsetTextField.setEnabled(false); reminderOffsetType.setEnabled(false); linkComponentEnabledStates(reminderEnabled, reminderOffsetTextField, reminderOffsetType); // do layout final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); new GridLayoutBuilder().add(new VerticalGroup( new HorizontalGroup(new Cell(new JLabel("Start date")), new Cell(startDateField)), new HorizontalGroup(new Cell(new JLabel("Summary")), new Cell(summaryTextField)), new HorizontalGroup( new Cell(new JLabel("Duration")), new Cell(durationTextField), new Cell(durationType)), new HorizontalGroup(new Cell(reminderEnabled)), new HorizontalGroup(new Cell(new JLabel("Reminder offset")), new Cell(reminderOffsetTextField), new Cell(reminderOffsetType)), new HorizontalGroup(new Cell(new JScrollPane(notes))))).addTo(result); return result; }
From source file:com.smart.aqimonitor.client.AqiSettingDialog.java
/** * Create the dialog./*from w ww. java 2 s . co m*/ */ public AqiSettingDialog(Frame owner, final AbstractAqiParser aqiParser) { super(owner); this.aqiParser = aqiParser; setTitle("\u8BBE\u7F6E"); setResizable(false); setBounds(100, 100, 450, 135); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); GridBagLayout gbl_contentPanel = new GridBagLayout(); gbl_contentPanel.columnWidths = new int[] { 33, 48, 66, 41, 48, 66, 0, 0 }; gbl_contentPanel.rowHeights = new int[] { 21, 0, 0 }; gbl_contentPanel.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; gbl_contentPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; contentPanel.setLayout(gbl_contentPanel); { JLabel lblRetryTimes = new JLabel("\u91CD\u8BD5\u6B21\u6570\uFF1A"); GridBagConstraints gbc_lblRetryTimes = new GridBagConstraints(); gbc_lblRetryTimes.anchor = GridBagConstraints.WEST; gbc_lblRetryTimes.insets = new Insets(0, 0, 5, 5); gbc_lblRetryTimes.gridx = 1; gbc_lblRetryTimes.gridy = 0; contentPanel.add(lblRetryTimes, gbc_lblRetryTimes); } { tfRetryTimes = new JTextField(); tfRetryTimes.setPreferredSize(new Dimension(6, 29)); tfRetryTimes.setMinimumSize(new Dimension(60, 29)); GridBagConstraints gbc_tfRetryTimes = new GridBagConstraints(); gbc_tfRetryTimes.anchor = GridBagConstraints.NORTHWEST; gbc_tfRetryTimes.insets = new Insets(0, 0, 5, 5); gbc_tfRetryTimes.gridx = 2; gbc_tfRetryTimes.gridy = 0; contentPanel.add(tfRetryTimes, gbc_tfRetryTimes); tfRetryTimes.setColumns(10); } { JLabel lblRetryGap = new JLabel("\u91CD\u8BD5\u95F4\u9694\uFF1A"); GridBagConstraints gbc_lblRetryGap = new GridBagConstraints(); gbc_lblRetryGap.anchor = GridBagConstraints.WEST; gbc_lblRetryGap.insets = new Insets(0, 0, 5, 5); gbc_lblRetryGap.gridx = 4; gbc_lblRetryGap.gridy = 0; contentPanel.add(lblRetryGap, gbc_lblRetryGap); } { tfRetryGap = new JTextField(); tfRetryGap.setMinimumSize(new Dimension(60, 29)); tfRetryGap.setPreferredSize(new Dimension(60, 29)); GridBagConstraints gbc_tfRetryGap = new GridBagConstraints(); gbc_tfRetryGap.insets = new Insets(0, 0, 5, 5); gbc_tfRetryGap.anchor = GridBagConstraints.NORTHWEST; gbc_tfRetryGap.gridx = 5; gbc_tfRetryGap.gridy = 0; contentPanel.add(tfRetryGap, gbc_tfRetryGap); tfRetryGap.setColumns(10); } { JLabel label = new JLabel("\u5206\u949F"); GridBagConstraints gbc_label = new GridBagConstraints(); gbc_label.insets = new Insets(0, 0, 5, 0); gbc_label.gridx = 6; gbc_label.gridy = 0; contentPanel.add(label, gbc_label); } { JLabel lblExportPath = new JLabel("\u8F93\u51FA\u8DEF\u5F84\uFF1A"); GridBagConstraints gbc_lblExportPath = new GridBagConstraints(); gbc_lblExportPath.anchor = GridBagConstraints.EAST; gbc_lblExportPath.insets = new Insets(0, 0, 0, 5); gbc_lblExportPath.gridx = 1; gbc_lblExportPath.gridy = 1; contentPanel.add(lblExportPath, gbc_lblExportPath); } { tfExportPath = new JTextField(); tfExportPath.setEditable(false); tfExportPath.setPreferredSize(new Dimension(180, 29)); tfExportPath.setMinimumSize(new Dimension(180, 29)); GridBagConstraints gbc_tfExportPath = new GridBagConstraints(); gbc_tfExportPath.gridwidth = 4; gbc_tfExportPath.insets = new Insets(0, 0, 0, 5); gbc_tfExportPath.fill = GridBagConstraints.HORIZONTAL; gbc_tfExportPath.gridx = 2; gbc_tfExportPath.gridy = 1; contentPanel.add(tfExportPath, gbc_tfExportPath); tfExportPath.setColumns(10); } { JButton button = new JButton("..."); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fDialog = new JFileChooser(); // fDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fDialog.showOpenDialog(contentPanel); if (result == JFileChooser.APPROVE_OPTION) { tfExportPath.setText(fDialog.getSelectedFile().getAbsolutePath()); } } }); GridBagConstraints gbc_button = new GridBagConstraints(); gbc_button.gridx = 6; gbc_button.gridy = 1; contentPanel.add(button, gbc_button); } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton okButton = new JButton("\u786E\u5B9A"); okButton.setName("settingOk"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String retryTimes = tfRetryTimes.getText(); if (StringUtils.isEmpty(retryTimes) || !isNumeric(retryTimes)) { JOptionPane.showMessageDialog(contentPanel, "", "", JOptionPane.ERROR_MESSAGE); return; } String retryGap = tfRetryGap.getText(); if (StringUtils.isEmpty(retryGap) || !isNumeric(retryGap)) { JOptionPane.showMessageDialog(contentPanel, "", "", JOptionPane.ERROR_MESSAGE); return; } String exportPath = tfExportPath.getText(); if (StringUtils.isEmpty(exportPath)) { JOptionPane.showMessageDialog(contentPanel, "", "", JOptionPane.ERROR_MESSAGE); return; } File testFile = new File(exportPath); if (!testFile.exists()) { JOptionPane.showMessageDialog(contentPanel, "", "", JOptionPane.ERROR_MESSAGE); return; } props.put("query.retryTimes", retryTimes); props.put("query.retryGap", retryGap); props.put("result.path", exportPath); try { props.store(new FileOutputStream(propertiesResource.getFile()), ""); aqiParser.setRetryTimes(Integer.parseInt(retryTimes)); aqiParser.setRetryGap(Integer.parseInt(retryGap)); aqiParser.setFilePath(exportPath); } catch (IOException e1) { e1.printStackTrace(); } finally { dispose(); } } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton("\u53D6\u6D88"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } }
From source file:ParallelPrint.java
/** Build the GUI. You can ignore this for now if you have not * yet worked through the GUI chapter. Your mileage may vary. *//*from w w w .ja v a 2 s . c om*/ protected void makeGUI() { Container cp = getContentPane(); JPanel centerPanel = new JPanel(); cp.add(BorderLayout.CENTER, centerPanel); centerPanel.setLayout(new GridLayout(0, 2, PAD, PAD)); centerPanel.add(new JLabel("Serial Ports", JLabel.RIGHT)); serialPortsChoice = new JComboBox(); centerPanel.add(serialPortsChoice); serialPortsChoice.setEnabled(false); centerPanel.add(new JLabel("Parallel Ports", JLabel.RIGHT)); parallelPortsChoice = new JComboBox(); centerPanel.add(parallelPortsChoice); parallelPortsChoice.setEnabled(false); centerPanel.add(new JLabel("Unknown Ports", JLabel.RIGHT)); other = new JComboBox(); centerPanel.add(other); other.setEnabled(false); centerPanel.add(new JLabel("Your choice:", JLabel.RIGHT)); centerPanel.add(choice = new JLabel()); JButton okButton; cp.add(BorderLayout.SOUTH, okButton = new JButton("OK")); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PortChooser.this.dispose(); } }); }
From source file:es.emergya.ui.gis.popups.GenericDialog.java
public GenericDialog(T i, final String titulo, final String icon) { super();/*from w w w . java2s.co m*/ log.trace("GenericDialog(" + i + ")"); setAlwaysOnTop(true); setResizable(false); setBackground(Color.WHITE); setPreferredSize(new Dimension(500, 500)); setTitle(titulo); try { setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getIconImage()); } catch (Throwable e) { LOG.error("There is no icon image", e); } JPanel base = new JPanel(); base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS)); base.setBackground(Color.WHITE); JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING)); final JLabel labelTitle = new JLabel(titulo, LogicConstants.getIcon(icon), JLabel.LEFT); labelTitle.setFont(LogicConstants.deriveBoldFont(12f)); title.setBackground(Color.WHITE); title.add(labelTitle); base.add(title); mid = new JPanel(new SpringLayout()); mid.setBackground(Color.WHITE); loadDialog(i); SpringUtilities.makeCompactGrid(mid, rows, cols, initialX, initialY, xPad, yPad); base.add(mid); JPanel buttons = new JPanel(); buttons.setBackground(Color.WHITE); JButton accept = new JButton(i18n.getString("Buttons.ok"), LogicConstants.getIcon("button_accept")); accept.addActionListener(closeListener); accept.addActionListener(saveListener); buttons.add(accept); JButton cancel = new JButton(i18n.getString("Buttons.cancel"), LogicConstants.getIcon("button_cancel")); cancel.addActionListener(closeListener); buttons.add(cancel); base.add(buttons); getContentPane().add(base); pack(); int x; int y; Container myParent; try { myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getContentPane(); java.awt.Point topLeft = myParent.getLocationOnScreen(); Dimension parentSize = myParent.getSize(); Dimension mySize = getSize(); if (parentSize.width > mySize.width) x = ((parentSize.width - mySize.width) / 2) + topLeft.x; else x = topLeft.x; if (parentSize.height > mySize.height) y = ((parentSize.height - mySize.height) / 2) + topLeft.y; else y = topLeft.y; setLocation(x, y); } catch (Throwable e1) { LOG.error("There is no basic window!", e1); } }
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;// ww w . j a va 2 s . c o m c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; 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:gui.images.CodebookVectorProfilePanel.java
/** * Sets the data to be shown./*from ww w .ja v a2 s . c om*/ * * @param occurrenceProfile Double array that is the neighbor occurrence * profile of this visual word. * @param codebookIndex Integer that is the index of this visual word. * @param classColors Color[] of class colors. * @param classNames String[] of class names. */ public void setResults(double[] occurrenceProfile, int codebookIndex, Color[] classColors, String[] classNames) { int numClasses = Math.min(classNames.length, occurrenceProfile.length); this.codebookIndex = codebookIndex; this.occurrenceProfile = occurrenceProfile; DefaultPieDataset pieData = new DefaultPieDataset(); for (int cIndex = 0; cIndex < numClasses; cIndex++) { pieData.setValue(classNames[cIndex], occurrenceProfile[cIndex]); } JFreeChart chart = ChartFactory.createPieChart3D("codebook vect " + codebookIndex, pieData, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); PieRenderer prend = new PieRenderer(classColors); prend.setColor(plot, pieData); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(140, 140)); chartPanel.setVisible(true); chartPanel.revalidate(); chartPanel.repaint(); JPanel jp = new JPanel(); jp.setPreferredSize(new Dimension(140, 140)); jp.setMinimumSize(new Dimension(140, 140)); jp.setMaximumSize(new Dimension(140, 140)); jp.setSize(new Dimension(140, 140)); jp.setLayout(new FlowLayout()); jp.add(chartPanel); jp.setVisible(true); jp.validate(); jp.repaint(); JFrame frame = new JFrame(); frame.setBackground(Color.WHITE); frame.setUndecorated(true); frame.getContentPane().add(jp); frame.pack(); BufferedImage bi = new BufferedImage(jp.getWidth(), jp.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = bi.createGraphics(); jp.print(graphics); graphics.dispose(); frame.dispose(); imPanel.removeAll(); imPanel.setImage(bi); imPanel.setVisible(true); imPanel.revalidate(); imPanel.repaint(); }
From source file:brainflow.app.presentation.controls.FileObjectGroupSelector.java
private JideSplitPane createSplitPane() { JPanel treePanel = new JPanel(); treePanel.setLayout(new BorderLayout()); treePanel.setMinimumSize(new Dimension(300, 100)); treePanel.add(new JScrollPane(explorer.getComponent()), BorderLayout.CENTER); splitPane = new JideSplitPane(JideSplitPane.HORIZONTAL_SPLIT); splitPane.setProportionalLayout(true); treePanel.setBorder(BorderFactory.createTitledBorder("File System")); splitPane.add(treePanel, JideBoxLayout.FLEXIBLE); JScrollPane jsp = new JScrollPane(fileList); jsp.setBorder(BorderFactory.createTitledBorder("Filter Selection")); splitPane.add(jsp, JideBoxLayout.VARY); splitPane.setProportions(new double[] { .55 }); return splitPane; }