List of usage examples for javax.swing JButton setText
@BeanProperty(preferred = true, visualUpdate = true, description = "The button's text.") public void setText(String text)
From source file:fxts.stations.util.preferences.EditAction.java
public void actionPerformed(ActionEvent aEvent) { JButton okButton = UIManager.getInst().createButton(); JButton cancelButton = UIManager.getInst().createButton(); final JDialog dialog = new JDialog(mEditorPanel.getParentDialog()); dialog.setTitle(mEditorPanel.getTitle()); JPanel editPanel = new JPanel(); JPanel buttonPanel = new JPanel(); JPanel mainPanel = new JPanel(); mainPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); //mainPanel.setLayout(new SideLayout()); //sets button panel buttonPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); okButton.setText(mResMan.getString("IDS_OK_BUTTON")); //okButton.setPreferredSize(new Dimension(80, 27)); GridBagConstraints sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 0;// w w w.j a v a2 s. c o m sideConstraints.gridy = 0; ResizeParameterWrapper resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.5, 0.0, 0.5, 0.0); resizeParameter.setToConstraints(sideConstraints); buttonPanel.add(okButton, sideConstraints); cancelButton.setText(mResMan.getString("IDS_CANCEL_BUTTON")); //cancelButton.setPreferredSize(new Dimension(80, 27)); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 1; sideConstraints.gridy = 0; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.5, 0.0, 0.5, 0.0); resizeParameter.setToConstraints(sideConstraints); buttonPanel.add(cancelButton, sideConstraints); //adds button panel sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 0; sideConstraints.gridy = 1; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 1.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); mainPanel.add(buttonPanel, sideConstraints); //sets edit panel final IEditor editor = mType.getEditor(); editor.setValue(mValue); editPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); Component editComp = editor.getComponent(); //Mar 25 2004 - kav: added for right tab order at Font Chooser at java 1.4. if (editComp instanceof FontChooser) { FontChooser fc = (FontChooser) editComp; fc.setNextFocusedComp(okButton); } editPanel.add(editComp, sideConstraints); //adds editor panel sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.gridx = 0; sideConstraints.gridy = 0; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); mainPanel.add(editPanel, sideConstraints); //adds main panel dialog.getContentPane().setLayout(UIFrontEnd.getInstance().getSideLayout()); //dialog.getContentPane().setLayout(new SideLayout()); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.fill = GridBagConstraints.BOTH; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); dialog.getContentPane().add(mainPanel, sideConstraints); //adds listeners to buttons okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { if (editor.getValue().equals(mValue)) { // } else { mValue = editor.getValue(); mEditorPanel.setValue(mValue); mEditorPanel.refreshControls(); mEditorPanel.setValueChanged(true); } dialog.setVisible(false); dialog.dispose(); } }); okButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ExitAction"); okButton.getActionMap().put("ExitAction", new AbstractAction() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent aEvent) { editor.setValue(mValue); dialog.setVisible(false); dialog.dispose(); } }); okButton.requestFocus(); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { editor.setValue(mValue); dialog.setVisible(false); dialog.dispose(); } }); //dialog.setResizable(false); dialog.setModal(true); dialog.pack(); //sets minimal sizes for components Dimension dim = mainPanel.getSize(); mainPanel.setMinimumSize(dim); mainPanel.setPreferredSize(dim); //sets size of buttons Dimension dimOkButton = okButton.getSize(); Dimension dimCancelButton = cancelButton.getSize(); int nMaxWidth = dimOkButton.getWidth() > dimCancelButton.getWidth() ? (int) dimOkButton.getWidth() : (int) dimCancelButton.getWidth(); okButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight())); okButton.setSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight())); cancelButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight())); cancelButton.setSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight())); dialog.setLocationRelativeTo(dialog.getOwner()); dialog.setVisible(true); }
From source file:SortableTable.java
/** * Returns the renderer component./*from www .j a v a 2s . c o m*/ * * @param table the table. * @param value the value. * @param isSelected selected? * @param hasFocus focussed? * @param row the row. * @param column the column. * @return the renderer. */ public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { if (table == null) { throw new NullPointerException("Table must not be null."); } final JComponent component; final SortableTableModel model = (SortableTableModel) table.getModel(); final int cc = table.convertColumnIndexToModel(column); final boolean isSorting = (model.getSortingColumn() == cc); final boolean isAscending = model.isAscending(); final JTableHeader header = table.getTableHeader(); final boolean isPressed = (cc == this.pressedColumn); if (this.useLabels) { final JLabel label = getRendererLabel(isSorting, isAscending); label.setText((value == null) ? "" : value.toString()); component = label; } else { final JButton button = getRendererButton(isSorting, isAscending); button.setText((value == null) ? "" : value.toString()); button.getModel().setPressed(isPressed); button.getModel().setArmed(isPressed); component = button; } if (header != null) { component.setForeground(header.getForeground()); component.setBackground(header.getBackground()); component.setFont(header.getFont()); } return component; }
From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java
private JButton getGuardarBtn(SaveOrUpdateAction guardar) { JButton guardarBtn = new JButton(guardar); if (isNew) {//from ww w.j a va2s.c om guardarBtn.setText("Crear"); guardarBtn.setIcon(getIcon("button_crear")); } else { guardarBtn.setText("Guardar"); guardarBtn.setIcon(getIcon("button_save")); } return guardarBtn; }
From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java
@Override public synchronized void actionPerformed(ActionEvent event) { for (int i = 0; i < transactionRenameButtons.size(); ++i) { if (event.getSource() == transactionRenameButtons.get(i)) { String newName = (String) JOptionPane.showInputDialog(this, "Enter the new name for this transaction type", "New Dataset", JOptionPane.PLAIN_MESSAGE, null, null, transactionNames.get(i)); if (newName == null || newName.trim().isEmpty()) { return; } else { newName = newName.trim(); transactionNames.set(i, newName); transactionLabels.get(i).setText(newName); DefaultTableModel model = (DefaultTableModel) monitorTable.getModel(); model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(i)), 2 + (i * ROW_PER_TX_TYPE), 0); model.setValueAt(/*from w w w. j a va 2s .com*/ String.format("Current average latency of '%s' transactions", transactionNames.get(i)), 2 + (i * ROW_PER_TX_TYPE) + 1, 0); // TimeSeriesCollection collection = (TimeSeriesCollection) throughputChartPanel.getChart().getXYPlot().getDataset(); throughputCollection.getSeries(i).setKey(newName); latencyCollection.getSeries(i).setKey(newName); // if (DBSeerGUI.currentDataset != null) // { // DBSeerGUI.currentDataset.setTransactionTypeName(i, newName); // } for (DBSeerDataSet dataset : DBSeerGUI.liveDatasets) { dataset.setTransactionTypeName(i, newName); } return; } } } for (int i = 0; i < transactionViewSampleButtons.size(); ++i) { if (event.getSource() == transactionViewSampleButtons.get(i)) { final int type = i; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { DBSeerShowTransactionExampleFrame sampleFrame = new DBSeerShowTransactionExampleFrame(type); sampleFrame.pack(); sampleFrame.setLocationRelativeTo(DBSeerGUI.mainFrame); sampleFrame.setVisible(true); } }); } } for (int i = 0; i < transactionEnableDisableButtons.size(); ++i) { if (event.getSource() == transactionEnableDisableButtons.get(i)) { final XYItemRenderer throughputRenderer = throughputChartPanel.getChart().getXYPlot().getRenderer(); final XYItemRenderer latencyRenderer = latencyChartPanel.getChart().getXYPlot().getRenderer(); final int type = i; final JButton button = transactionEnableDisableButtons.get(i); final DBSeerDataSet dataset = DBSeerGUI.liveDataset; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (button.getText() == "Disable") { dataset.disableTransaction(type); throughputRenderer.setSeriesVisible(type, false); latencyRenderer.setSeriesVisible(type, false); button.setText("Enable"); } else if (button.getText() == "Enable") { dataset.enableTransaction(type); throughputRenderer.setSeriesVisible(type, true); latencyRenderer.setSeriesVisible(type, true); button.setText("Disable"); } } }); } } for (int i = 0; i < transactionDeleteButtons.size(); ++i) { if (event.getSource() == transactionDeleteButtons.get(i)) { synchronized (LiveMonitorInfo.LOCK) { try { DBSeerGUI.middlewareSocket.removeTransactionType(i); } catch (IOException e) { DBSeerExceptionHandler.handleException(e); } throughputCollection.removeSeries(i); latencyCollection.removeSeries(i); DefaultTableModel model = (DefaultTableModel) monitorTable.getModel(); int newTxSize = transactionNames.size() - 1; for (int j = 0; j < transactionNames.size(); ++j) { model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(j)), 2 + (j * ROW_PER_TX_TYPE), 0); model.setValueAt(String.format("Current average latency of '%s' transactions", transactionNames.get(j)), 2 + (j * ROW_PER_TX_TYPE) + 1, 0); model.setValueAt("", 2 + (j * ROW_PER_TX_TYPE), 1); model.setValueAt("", 2 + (j * ROW_PER_TX_TYPE) + 1, 1); } model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE), 0); model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE), 1); model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE) + 1, 0); model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE) + 1, 1); final JPanel panel = transactionTypesPanel; final JLabel label = transactionLabels.remove(i); final JButton renameButton = transactionRenameButtons.remove(i); final JButton exampleButton = transactionViewSampleButtons.remove(i); final JButton deleteButton = transactionDeleteButtons.remove(i); transactionNames.remove(i); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { panel.remove(label); panel.remove(renameButton); panel.remove(exampleButton); panel.remove(deleteButton); panel.revalidate(); panel.repaint(); } }); } break; } } }
From source file:dotaSoundEditor.Controls.EditorPanel.java
void advancedButtonActionPerformed(java.awt.event.ActionEvent evt, JButton advancedButton) { if (!getAdvancedMode()) { setAdvancedMode(true);// w ww .j a v a 2 s . com String scriptPath = getCurrentScriptString(); ScriptParser parser = new ScriptParser(new File(Paths.get(scriptPath).toString())); TreeModel model = parser.getTreeModel(); currentTree.setModel(model); currentTree.setEditable(true); for (int i = 0; i < currentTree.getRowCount(); i++) { currentTree.expandRow(i); } //Change button and action to Basic-revert: advancedButton.setText("Basic <<"); advancedButton.setMnemonic('a'); } else if (getAdvancedMode()) { setAdvancedMode(false); this.populateSoundList(); advancedButton.setText("Advanced >>"); advancedButton.setMnemonic('a'); currentTree.setEditable(false); } }
From source file:com.hammurapi.jcapture.CaptureFrame.java
public CaptureFrame(final AbstractCaptureApplet applet) throws Exception { super("Screen capture"); setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("camera.png"))); setUndecorated(true);//from w ww.j a va 2 s . c om Translucener.makeFrameTranslucent(this); setAlwaysOnTop(true); this.applet = applet; captureConfig = new CaptureConfig(); captureConfig.load(applet.loadConfig()); captureConfig.setBackgroundProcessor(applet.getBackgroundProcessor()); //--- GUI construction --- capturePanel = new JPanel(); final JLabel dimensionsLabel = new JLabel(""); capturePanel.add(dimensionsLabel, BorderLayout.CENTER); capturePanel.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { super.componentResized(e); dimensionsLabel.setText(e.getComponent().getWidth() + " x " + e.getComponent().getHeight()); } }); JButton captureButton = new JButton(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { Rectangle bounds = capturePanel.getBounds(); Point loc = bounds.getLocation(); SwingUtilities.convertPointToScreen(loc, capturePanel); bounds.setLocation(loc); Properties props = captureConfig.setRecordingRectangle(bounds); if (props != null) { getApplet().storeConfig(props); } capturing.set(true); setVisible(false); } }); captureButton.setText("Capture"); captureButton.setToolTipText("Create a snapshot of the screen"); capturePanel.add(captureButton, BorderLayout.CENTER); recordButton = new JButton(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { Rectangle bounds = capturePanel.getBounds(); Point loc = bounds.getLocation(); SwingUtilities.convertPointToScreen(loc, capturePanel); bounds.setLocation(loc); Properties props = captureConfig.setRecordingRectangle(bounds); if (props != null) { getApplet().storeConfig(props); } recording.set(true); setVisible(false); } }); recordButton.setText("Record"); setRecordButtonState(); capturePanel.add(recordButton, BorderLayout.CENTER); JButton optionsButton = new JButton(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { new CaptureOptionsDialog(CaptureFrame.this).setVisible(true); } }); optionsButton.setText("Options"); capturePanel.add(optionsButton, BorderLayout.CENTER); JButton cancelButton = new JButton(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { CaptureFrame.this.setVisible(false); } }); cancelButton.setText("Cancel"); capturePanel.add(cancelButton, BorderLayout.CENTER); getContentPane().add(capturePanel, BorderLayout.CENTER); capturePanel.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); if (captureConfig.getRecordingRectangle() == null) { setSize(400, 300); setLocationRelativeTo(null); } else { setBounds(captureConfig.getRecordingRectangle()); } Insets dragInsets = new Insets(5, 5, 5, 5); new ComponentResizer(dragInsets, this); ComponentMover cm = new ComponentMover(); cm.registerComponent(this); cm.setDragInsets(dragInsets); addComponentListener(new ComponentListener() { @Override public void componentShown(ComponentEvent e) { // TODO Auto-generated method stub } @Override public void componentResized(ComponentEvent e) { // TODO Auto-generated method stub } @Override public void componentMoved(ComponentEvent e) { // TODO Auto-generated method stub } @Override public void componentHidden(ComponentEvent e) { if (capturing.get()) { capturing.set(false); try { capture(); } catch (Exception ex) { ex.printStackTrace(); } } else if (recording.get()) { recording.set(false); record(); } } }); }
From source file:es.emergya.ui.gis.popups.ConsultaHistoricos.java
private JButton getCancelar() { JButton jButton = new JButton(LogicConstants.getIcon("button_cancel")); jButton.addActionListener(closing);/* ww w . j av a2s. c om*/ jButton.setText("Cancelar"); return jButton; }
From source file:es.emergya.ui.gis.popups.ConsultaHistoricos.java
private JButton getLimpiar() { JButton jButton = new JButton(LogicConstants.getIcon("button_limpiar")); jButton.setText("Limpiar"); jButton.addActionListener(new ActionListener() { @Override/* w w w. ja va 2s .c o m*/ public void actionPerformed(ActionEvent e) { SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { clearRecursos(); clearIncidencias(); cleanLayers(); if (visorHistorico != null) { visorHistorico.updateControls(); } return null; } @Override protected void done() { HistoryMapViewer.enableSaveGpx(false); HistoryMapViewer.getResultadoHistoricos().setSelected(false); recursos.setSelectedIndex(-1); incidencias.setSelectedIndex(-1); // zona.setSelectedIndex(-1); final Calendar instance = Calendar.getInstance(); calendarini.setDate(instance.getTime()); calendarfin.setDate(instance.getTime()); horafin.setValue(instance.getTime()); instance.set(Calendar.HOUR_OF_DAY, 0); instance.set(Calendar.MINUTE, 0); instance.set(Calendar.SECOND, 0); horaini.setValue(instance.getTime()); soloUltimas.setSelected(false); calendarini.setEnabled(true); calendarfin.setEnabled(true); horaini.setEnabled(true); horafin.setEnabled(true); consultar.setEnabled(false); limpiar.setEnabled(false); setError(""); } }; sw.execute(); } }); return jButton; }
From source file:net.sf.jabref.EntryEditor.java
/** * Create toolbar for entry editor./*from w w w .j a v a 2 s. c o m*/ */ private void setupToolBar() { JToolBar tlb = new JToolBar(JToolBar.VERTICAL); CloseAction closeAction = new CloseAction(); ; StoreFieldAction storeFieldAction = new StoreFieldAction(); DeleteAction deleteAction = new DeleteAction(); UndoAction undoAction = new UndoAction(); RedoAction redoAction = new RedoAction(); tlb.setBorder(null); tlb.setRollover(true); tlb.setMargin(new Insets(0, 0, 0, 2)); tlb.setFloatable(false); tlb.addSeparator(); tlb.add(deleteAction); tlb.addSeparator(); tlb.add(prevEntryAction); tlb.add(nextEntryAction); tlb.addSeparator(); tlb.add(helpAction); for (Component comp : tlb.getComponents()) { ((JComponent) comp).setOpaque(false); } // The toolbar carries all the key bindings that are valid for the whole window. ActionMap am = tlb.getActionMap(); InputMap im = tlb.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(prefs.getKey("Close entry editor"), "close"); am.put("close", closeAction); im.put(prefs.getKey("Entry editor, store field"), "store"); am.put("store", storeFieldAction); im.put(prefs.getKey("Entry editor, previous entry"), "prev"); am.put("prev", prevEntryAction); im.put(prefs.getKey("Entry editor, next entry"), "next"); am.put("next", nextEntryAction); im.put(prefs.getKey("Undo"), "undo"); am.put("undo", undoAction); im.put(prefs.getKey("Redo"), "redo"); am.put("redo", redoAction); im.put(prefs.getKey("Help"), "help"); am.put("help", helpAction); // Add actions (and thus buttons) JButton closeBut = new JButton(closeAction); closeBut.setText(null); closeBut.setBorder(null); // Create type-label TypeLabel typeLabel = new TypeLabel(entry.getType().getName()); JPanel leftPan = new JPanel(); leftPan.setLayout(new BorderLayout()); leftPan.add(closeBut, BorderLayout.NORTH); leftPan.add(typeLabel, BorderLayout.CENTER); leftPan.add(tlb, BorderLayout.SOUTH); add(leftPan, BorderLayout.WEST); }
From source file:edu.ucla.stat.SOCR.chart.demo.PowerTransformHistogramChart.java
protected void createActionComponents(JToolBar toolBar) { super.createActionComponents(toolBar); JButton button; /**************** wiki Tab ****************/ Action linkAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { try { parentApplet.getAppletContext().showDocument(new java.net.URL( "http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_Activities_PowerTransformFamily_Graphs"), "SOCR: Power Transform Graphing Activity"); } catch (MalformedURLException Exc) { JOptionPane.showMessageDialog(null, Exc, "MalformedURL Error", JOptionPane.ERROR_MESSAGE); Exc.printStackTrace();//from w w w .ja v a2s . c om } } }; button = toolBar.add(linkAction); button.setText(" WIKI_Activity "); button.setToolTipText("Press this Button to go to SOCR_POWER_Activity wiki page"); }