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:org.quackedcube.impl.Gui.java
public JComponent generateContent() { //Inital creation JPanel clockPanel = new JPanel(new BorderLayout()); JPanel virtualCubePanel = new JPanel(new BorderLayout()); JPanel logPanel = new JPanel(new BorderLayout()); virtualCubePanel//from w w w .j av a 2s. c o m .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Cube Position")); logPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Log")); //Clock setup clock = new Clock(); clock.setPreferredSize(new Dimension((int) clock.getPreferredSize().getWidth(), 100)); clock.setFont(new Font("Arial", Font.PLAIN, 180)); clock.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Timer")); clock.setAlignmentX(JComponent.CENTER_ALIGNMENT); clockPanel.add(clock, BorderLayout.CENTER); //Logging panel setup logScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); logScroll.setAlignmentX(Component.RIGHT_ALIGNMENT); logPane.setEditable(false); logPane.setAlignmentX(Component.CENTER_ALIGNMENT); logPanel.add(logScroll, BorderLayout.CENTER); //Virtual Cube panel log.trace("Creating virtual cube"); virtualCubePanel.add(virtualCube = new VirtualBuilder(), BorderLayout.CENTER); log.trace("Done creating virtual cube."); JPanel virtualCubeControl = new JPanel(new FlowLayout()); virtualCubeControl.add(new JButton("Rotate") { { final JButton self = this; addActionListener(new ActionListener() { final String start = "Rotate"; final String end = "Stop Rotating"; @Override public void actionPerformed(ActionEvent e) { if (self.getText().equals(start)) { Gui.this.virtualCube.rotate(); self.setText(end); } else if (self.getText().equals(end)) { Gui.this.virtualCube.stopRotating(); self.setText(start); } } }); } }); virtualCubeControl.add(new JButton("Reset Position") { { addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Gui.this.virtualCube.resetPosition(); } }); setEnabled(false); } }); virtualCubePanel.add(virtualCubeControl, BorderLayout.SOUTH); log.trace("Creating content pane"); JPanel contentPane = new JPanel(new MigLayout("fill", "fill", "fill")); contentPane.add(clock, "dock north"); //span 2, hmax 25%, wrap contentPane.add(virtualCubePanel, "growprio 20"); contentPane.add(logPanel, "span 1 2"); return contentPane; }
From source file:org.rdv.ui.channel.LocalChannelDialog.java
private JPanel buildFooterPanel() { JPanel footerPanel = new JPanel(); if (isChannelAddOperation()) { channelActionButton.setName("addChannelButton"); channelActionButton.setText(PROPERTY_REPO.getValue(ADD_CHANNEL_BUTTON_KEY)); } else { // channel exists channelActionButton.setName("saveChannelButton"); channelActionButton.setText(PROPERTY_REPO.getValue(SAVE_CHANNEL_BUTTON_KEY)); }//from www.ja v a2 s . c o m channelActionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (isChannelAddOperation()) { addChannel(); } else { updateChannel(); } } }); footerPanel.add(channelActionButton); JButton cancelButton = new JButton(); cancelButton.setName("cancelButton"); cancelButton.setText(PROPERTY_REPO.getValue(CANCEL_BUTTON_KEY)); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cancel(); } }); footerPanel.add(cancelButton); helpButton.setText(PROPERTY_REPO.getValue(HELP_BUTTON_KEY)); helpButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Browser.open(getOwner(), new URI(PROPERTY_REPO.getValue(ADD_CHANNEL_DOC_KEY))); } catch (URISyntaxException e1) { LOGGER.error("", e1); e1.printStackTrace(); } } }); footerPanel.add(helpButton); return footerPanel; }
From source file:org.rdv.ui.channel.LocalChannelDialog.java
private JPanel buildVariablesPanel() { JPanel variablesPanel = new JPanel(); variablesPanel.setLayout(new BorderLayout()); JScrollPane variablesScrollPane = new JScrollPane(variablesTable.getComponent()); variablesPanel.add(variablesScrollPane, BorderLayout.CENTER); Box variablesButtonsPanel = Box.createVerticalBox(); variablesButtonsPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); JButton addVariableButton = new JButton(); addVariableButton.setName("addVariableButton"); addVariableButton.setText(PROPERTY_REPO.getValue(ADD_VARIABLE_BUTTON_KEY)); addVariableButton.addActionListener(new ActionListener() { @Override//from w w w . j a va 2s. c o m public void actionPerformed(ActionEvent e) { addVariable(); } }); variablesButtonsPanel.add(addVariableButton); variablesButtonsPanel.add(Box.createVerticalStrut(5)); removeVariableButton.setName("removeVariableButton"); removeVariableButton.setText(PROPERTY_REPO.getValue(REMOVE_VARIABLE_BUTTON_KEY)); removeVariableButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeVariable(); } }); variablesButtonsPanel.add(removeVariableButton); variablesPanel.add(variablesButtonsPanel, BorderLayout.EAST); return variablesPanel; }
From source file:org.revager.tools.GUITools.java
/** * Creates a new image button./*www. ja va 2s . c o m*/ * * @param icon * the normal icon * @param rolloverIcon * the rollover icon * @param action * the action * * @return the newly created image button */ public static JButton newImageButton(ImageIcon icon, ImageIcon rolloverIcon, Action action) { JButton button = new JButton(action); button.setToolTipText(button.getText()); button.setText(null); button.setContentAreaFilled(false); button.setBorder(new EmptyBorder(0, 0, 0, 0)); button.setMargin(new Insets(0, 0, 0, 0)); button.setBorderPainted(false); button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); button.setFocusPainted(false); button.setFocusable(false); button.setIcon(icon); button.setRolloverIcon(rolloverIcon); button.setRolloverSelectedIcon(rolloverIcon); button.setSelectedIcon(rolloverIcon); return button; }
From source file:org.rivalry.swingui.RivalryUI.java
/** * @param imageName Image name.//w w w . j a v a2s . co m * @param toolTipText Tool tip text. * @param altText Alternate text. * @param actionListener Action listener. * * @return a new button. */ private JButton createButton(final String imageName, final String toolTipText, final String altText, final ActionListener actionListener) { // Look for the image. final String imgLocation = "images/" + imageName; final URL imageURL = getClass().getClassLoader().getResource(imgLocation); // Create and initialize the button. final JButton button = new JButton(); button.setToolTipText(toolTipText); button.addActionListener(actionListener); if (imageURL != null) { // image found button.setIcon(new ImageIcon(imageURL, altText)); } else { // no image found button.setText(altText); System.err.println("Resource not found: " + imgLocation); } return button; }
From source file:org.swiftexplorer.gui.AboutDlg.java
public static void show(Component parent, HasLocalizedStrings stringsBundle) { URI uri = null;//from w w w . jav a 2s .c o m try { uri = new URI("http://www.swiftexplorer.org"); } catch (URISyntaxException e) { logger.error("URL seems to be ill-formed", e); } final String buttontext = "www.swiftexplorer.org"; Box mainBox = Box.createVerticalBox(); mainBox.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0)); StringBuilder sb = loadResource("/about.html"); JLabel label = new JLabel(sb.toString()); label.getAccessibleContext().setAccessibleDescription(getTitle(stringsBundle)); mainBox.add(label); if (uri != null) { JButton button = new JButton(); button.setText(buttontext); button.setToolTipText(uri.toString()); button.addActionListener(new OpenUrlAction(uri)); FontMetrics metrics = button.getFontMetrics(button.getFont()); if (metrics != null) button.setSize(metrics.stringWidth(buttontext), button.getHeight()); button.getAccessibleContext().setAccessibleDescription(buttontext); mainBox.add(button); } mainBox.add(Box.createVerticalStrut(10)); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); panel.add(mainBox); JOptionPane.showMessageDialog(parent, panel, getTitle(stringsBundle), JOptionPane.INFORMATION_MESSAGE, getIcon()); }
From source file:org.ut.biolab.medsavant.client.cohort.CohortDetailedView.java
public synchronized void setPatientList(List<SimplePatient> patients) { members.removeAll();//ww w .j av a2 s.c o m final Object[][] data = new Object[patients.size()][1]; for (int i = 0; i < patients.size(); i++) { data[i][0] = patients.get(i); } list = new StripyTable(data, new String[] { "Member Hospital IDs" }); list.setFont(FontFactory.getGeneralFont().deriveFont(16)); list.setBorder(null); list.setShowGrid(false); list.setRowHeight(21); list.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { int[] selection = list.getSelectedRows(); String[] hosIds = new String[selection.length]; for (int i = 0; i < selection.length; i++) { int j = list.convertRowIndexToModel(selection[i]); hosIds[i] = ((SimplePatient) data[j][0]).getHospitalId(); } createHospitalPopup(hosIds).show(e.getComponent(), e.getX(), e.getY()); } } }); final JButton removeButton = removeIndividualsButton(); removeButton.setEnabled(false); list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int count = list.getSelectedRowCount(); removeButton.setEnabled(count > 0); if (count == 0) { removeButton.setText("Remove selected member"); } else { if (count == 1) { removeButton.setText("Remove selected member"); } else { removeButton.setText(String.format("Remove %d selected members", count)); } } } }); members.setLayout(new MigLayout("fillx, insets 0, wrap")); members.add(new JLabel(ViewUtil.numToString(list.getRowCount()) + " " + MiscUtils.pluralize(list.getRowCount(), "member", "members")), "split, growx 1.0"); members.add(removeButton, "right,wrap"); members.add(list, "width 100%"); members.updateUI(); }
From source file:org.ut.biolab.medsavant.client.variant.VariantWorker.java
/** * Initialise functionality shared by all UpdateWorkers and PublicationWorkers. * * @param activity "Importing", "Publishing", or "Removing" * @param wizard the wizard which is providing the user interface * @param progressLabel label which indicates progress activity * @param progressBar provides quantitative display of progress * @param workButton starts the process and cancels it *///from www .j ava 2 s .c o m VariantWorker(String activity, WizardDialog wizard, JLabel progressLabel, JProgressBar progressBar, JButton workButton) { super(activity + "Variants"); this.activity = activity; this.wizard = wizard; this.progressLabel = progressLabel; this.progressBar = progressBar; this.workButton = workButton; progressLabel.setText(String.format("%s ...", activity)); // Convert our start button into a cancel button. workButton.setText("Cancel"); if (workButton.getActionListeners().length > 0) { workButton.removeActionListener(workButton.getActionListeners()[0]); } workButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { VariantWorker.this.progressBar.setIndeterminate(true); VariantWorker.this.workButton.setText("Cancelling..."); VariantWorker.this.workButton.setEnabled(false); cancel(true); } }); workButton.setEnabled(true); wizard.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); }
From source file:org.ut.biolab.medsavant.client.view.dialog.FamilySelector.java
private void initUI() { JPanel p = new JPanel(); ViewUtil.applyVerticalBoxLayout(p);//from w w w. j ava2 s.c o m this.add(p); topPanel = ViewUtil.getClearPanel(); middlePanel = ViewUtil.getClearPanel(); bottomPanel = ViewUtil.getClearPanel(); p.add(topPanel); p.add(middlePanel); p.add(bottomPanel); // middle middlePanel.setLayout(new BorderLayout()); retriever = new FamilyReceiver(); stp = new SearchableTablePanel("Individuals", COLUMN_NAMES, COLUMN_CLASSES, HIDDEN_COLUMNS, true, true, Integer.MAX_VALUE, false, SearchableTablePanel.TableSelectionType.ROW, Integer.MAX_VALUE, retriever); stp.setExportButtonVisible(false); middlePanel.add(stp, BorderLayout.CENTER); // bottom ViewUtil.applyVerticalBoxLayout(bottomPanel); numselections = ViewUtil.getTitleLabel("0 families selected"); JPanel text = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(text); JButton clearIndividuals = ViewUtil .getIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.CLOSE)); clearIndividuals.setToolTipText("Clear selections"); clearIndividuals.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { clearSelections(); } }); text.add(numselections); text.add(Box.createHorizontalStrut(5)); text.add(clearIndividuals); bottomPanel.add(ViewUtil.centerHorizontally(text)); final JButton addAllIndividuals = ViewUtil.getSoftButton("Add All"); bottomPanel.add(addAllIndividuals); final JButton addIndividuals = ViewUtil.getSoftButton("Add Selected"); bottomPanel.add(addIndividuals); final JButton removeIndividuals = ViewUtil.getSoftButton("Remove Selected"); bottomPanel.add(removeIndividuals); final JButton removeAllIndividuals = ViewUtil.getSoftButton("Remove All"); bottomPanel.add(removeAllIndividuals); JPanel buttons = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(buttons); buttons.add(addAllIndividuals); buttons.add(addIndividuals); buttons.add(removeIndividuals); buttons.add(removeAllIndividuals); JPanel windowControlPanel = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(windowControlPanel); windowControlPanel.add(Box.createHorizontalGlue()); JButton cancel = new JButton("Cancel"); bottomPanel.add(ViewUtil.centerHorizontally(buttons)); ok = new JButton("OK"); bottomPanel.add(ViewUtil.alignRight(ok)); ok.setEnabled(false); windowControlPanel.add(cancel); windowControlPanel.add(ok); bottomPanel.add(windowControlPanel); final JDialog instance = this; ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { instance.setVisible(false); setIndividualsChosen(true); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { instance.setVisible(false); setIndividualsChosen(false || hasMadeSelections); } }); addIndividuals.setEnabled(false); removeIndividuals.setEnabled(false); stp.getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent lse) { if (!lse.getValueIsAdjusting()) { int rows[] = stp.getTable().getSelectedRows(); boolean someSelection = rows.length > 0; addIndividuals.setEnabled(someSelection); removeIndividuals.setEnabled(someSelection); if (someSelection) { addIndividuals.setText("Add Selected (" + rows.length + ")"); removeIndividuals.setText("Remove Selected (" + rows.length + ")"); } else { addIndividuals.setText("Add Selected"); removeIndividuals.setText("Remove Selected"); } } } }); stp.getTable().getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent tme) { //addAllIndividuals.setText("Add All (" + stp.getTable().getModel().getRowCount() + ")"); //removeAllIndividuals.setText("Remove All (" + stp.getTable().getModel().getRowCount() + ")"); } }); ActionListener addAction = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { addSelections(false); } }; ActionListener addAllAction = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { addSelections(true); } }; ActionListener removeAction = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { removeSelections(false); } }; ActionListener removeAllAction = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { removeSelections(true); } }; addIndividuals.addActionListener(addAction); addAllIndividuals.addActionListener(addAllAction); removeIndividuals.addActionListener(removeAction); removeAllIndividuals.addActionListener(removeAllAction); this.pack(); this.setLocationRelativeTo(MedSavantFrame.getInstance()); }
From source file:org.ut.biolab.medsavant.client.view.dialog.IndividualSelector.java
private void initUI() { JPanel p = new JPanel(); ViewUtil.applyVerticalBoxLayout(p);//w ww .j av a 2s.com this.add(p); topPanel = ViewUtil.getClearPanel(); middlePanel = ViewUtil.getClearPanel(); bottomPanel = ViewUtil.getClearPanel(); p.add(topPanel); p.add(middlePanel); p.add(bottomPanel); // Only display the bottom panel for multiple patient selection if (onlyOnePatient) { bottomPanel.setVisible(false); } // middle middlePanel.setLayout(new BorderLayout()); individualsRetriever = new IndividualsReceiver(); individualsSTP = new SearchableTablePanel("Individuals", COLUMN_NAMES, COLUMN_CLASSES, HIDDEN_COLUMNS, true, true, Integer.MAX_VALUE, false, SearchableTablePanel.TableSelectionType.ROW, Integer.MAX_VALUE, individualsRetriever); individualsSTP.setExportButtonVisible(false); //If patients or cohorts are edited, update the searchabletable. CacheController.getInstance().addListener(new Listener<ModificationType>() { @Override public void handleEvent(ModificationType event) { if (event == ModificationType.PATIENT || event == ModificationType.COHORT) { if (!individualsSTP.isUpdating()) { forceRefresh = true; individualsSTP.forceRefreshData(); } } } }); middlePanel.add(individualsSTP, BorderLayout.CENTER); // bottom ViewUtil.applyVerticalBoxLayout(bottomPanel); numselections = ViewUtil.getTitleLabel("0 individual(s) selected"); JPanel text = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(text); JButton clearIndividuals = ViewUtil .getIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.CLOSE)); clearIndividuals.setToolTipText("Clear selections"); clearIndividuals.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { clearSelections(); } }); text.add(numselections); text.add(Box.createHorizontalStrut(5)); text.add(clearIndividuals); bottomPanel.add(ViewUtil.centerHorizontally(text)); final JButton addAllIndividuals = ViewUtil.getSoftButton("Add All"); bottomPanel.add(addAllIndividuals); final JButton addIndividuals = ViewUtil.getSoftButton("Add Selected"); bottomPanel.add(addIndividuals); final JButton removeIndividuals = ViewUtil.getSoftButton("Remove Selected"); bottomPanel.add(removeIndividuals); final JButton removeAllIndividuals = ViewUtil.getSoftButton("Remove All"); bottomPanel.add(removeAllIndividuals); JPanel buttons = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(buttons); buttons.add(addAllIndividuals); buttons.add(addIndividuals); buttons.add(removeIndividuals); buttons.add(removeAllIndividuals); JPanel windowControlPanel = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(windowControlPanel); windowControlPanel.add(Box.createHorizontalGlue()); JButton cancel = new JButton("Cancel"); bottomPanel.add(ViewUtil.centerHorizontally(buttons)); ok = new JButton("OK"); bottomPanel.add(ViewUtil.alignRight(ok)); ok.setEnabled(false); windowControlPanel.add(cancel); windowControlPanel.add(ok); bottomPanel.add(windowControlPanel); final JDialog instance = this; ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { instance.setVisible(false); setIndividualsChosen(true); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { instance.setVisible(false); setIndividualsChosen(false || hasMadeSelections); } }); addIndividuals.setEnabled(false); removeIndividuals.setEnabled(false); individualsSTP.getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent lse) { if (!lse.getValueIsAdjusting()) { int rows[] = individualsSTP.getTable().getSelectedRows(); boolean someSelection = rows.length > 0; addIndividuals.setEnabled(someSelection); removeIndividuals.setEnabled(someSelection); if (someSelection) { addIndividuals.setText("Add Selected (" + rows.length + ")"); removeIndividuals.setText("Remove Selected (" + rows.length + ")"); } else { addIndividuals.setText("Add Selected"); removeIndividuals.setText("Remove Selected"); } /* Close the dialog if only a single individual is requested. */ if (onlyOnePatient && rows.length == 1) { selectedRows.clear(); selectedHospitalIDs.clear(); int realRow = individualsSTP.getActualRowAt(rows[0]); selectedRows.add(realRow); Object[] o = individualsRetriever.getIndividuals().get(realRow); selectedHospitalIDs.add(o[INDEX_OF_HOSPITAL_ID].toString()); instance.setVisible(false); setIndividualsChosen(true); individualsSTP.getTable().clearSelection(); // if errors crop up, this line may be causing ListSelectionEvents - can be removed } } } }); individualsSTP.getTable().getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent tme) { //addAllIndividuals.setText("Add All (" + stp.getTable().getModel().getRowCount() + ")"); //removeAllIndividuals.setText("Remove All (" + stp.getTable().getModel().getRowCount() + ")"); } }); ActionListener addAction = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { addSelections(false); } }; ActionListener addAllAction = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { addSelections(true); } }; ActionListener removeAction = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { removeSelections(false); } }; ActionListener removeAllAction = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { removeSelections(true); } }; addIndividuals.addActionListener(addAction); addAllIndividuals.addActionListener(addAllAction); removeIndividuals.addActionListener(removeAction); removeAllIndividuals.addActionListener(removeAllAction); this.pack(); this.setLocationRelativeTo(MedSavantFrame.getInstance()); }