List of usage examples for javax.swing JButton setIcon
@BeanProperty(visualUpdate = true, description = "The button's default icon") public void setIcon(Icon defaultIcon)
From source file:net.brtly.monkeyboard.plugin.ConsolePanel.java
public ConsolePanel(PluginDelegate service) { super(service); setLayout(new MigLayout("inset 5", "[grow][:100:100][24:n:24][24:n:24]", "[::24][grow]")); JComboBox comboBox = new JComboBox(); comboBox.setToolTipText("Log Level"); comboBox.setMaximumRowCount(6);// ww w . j a v a2s.co m comboBox.setModel( new DefaultComboBoxModel(new String[] { "Fatal", "Error", "Warn", "Info", "Debug", "Trace" })); comboBox.setSelectedIndex(5); add(comboBox, "cell 1 0,growx"); JButton btnC = new JButton(""); btnC.setToolTipText("Clear Buffer"); btnC.setIcon(new ImageIcon(ConsolePanel.class.getResource("/img/clear-document.png"))); btnC.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { logPangrams(); } }); add(btnC, "cell 2 0,wmax 24,hmax 26"); tglbtnV = new JToggleButton(""); tglbtnV.setToolTipText("Auto Scroll"); tglbtnV.setIcon(new ImageIcon(ConsolePanel.class.getResource("/img/auto-scroll.png"))); tglbtnV.setSelected(true); tglbtnV.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { if (ev.getStateChange() == ItemEvent.SELECTED) { _table.setAutoScroll(true); } else if (ev.getStateChange() == ItemEvent.DESELECTED) { _table.setAutoScroll(false); } } }); add(tglbtnV, "cell 3 0,wmax 24,hmax 26"); scrollPane = new JScrollPane(); scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { // TODO figure out what to do with this event? } }); add(scrollPane, "cell 0 1 4 1,grow"); _table = new JLogTable("Time", "Source", "Message"); _table.getColumnModel().getColumn(0).setMinWidth(50); _table.getColumnModel().getColumn(0).setPreferredWidth(50); _table.getColumnModel().getColumn(0).setMaxWidth(100); _table.getColumnModel().getColumn(1).setMinWidth(50); _table.getColumnModel().getColumn(1).setPreferredWidth(50); _table.getColumnModel().getColumn(1).setMaxWidth(100); _table.getColumnModel().getColumn(2).setMinWidth(50); _table.getColumnModel().getColumn(2).setWidth(255); _table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); scrollPane.setViewportView(_table); _appender = new JLogTableAppender(); _appender.setThreshold(Level.ALL); Logger.getRootLogger().addAppender(_appender); }
From source file:brainflow.core.ImageBrowser.java
private void initSourceView() { sourceView = new JList(); final DefaultListModel model = new DefaultListModel(); for (IImageSource source : sourceList.sourceList) { model.addElement(source);//from w ww .j a v a 2 s . com } sourceView.setModel(model); sourceView.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ButtonPanel panel = new ButtonPanel(SwingConstants.CENTER); JButton nextButton = new JButton("Next"); ImageIcon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/control_play_blue.png")); nextButton.setIcon(icon); JButton prevButton = new JButton("Previous"); icon = new ImageIcon(getClass().getClassLoader().getResource("icons/control_rev_blue.png")); prevButton.setIcon(icon); panel.addButton(prevButton); panel.addButton(nextButton); panel.setSizeConstraint(ButtonPanel.SAME_SIZE); JPanel container = new JPanel(new BorderLayout()); container.setBorder(new TitledBorder("Image List")); container.add(new JScrollPane(sourceView), BorderLayout.CENTER); container.add(panel, BorderLayout.SOUTH); add(container, BorderLayout.WEST); nextButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int index = sourceView.getSelectedIndex(); if (index == (sourceList.size() - 1)) { index = 0; } else { index++; } updateView(index); } }); sourceView.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int index = sourceView.getSelectedIndex(); if (currentModel.getSelectedLayer().getDataSource() != sourceView.getSelectedValue()) { System.out.println("updating view"); updateView(index); } else { System.out.println("not updating view "); } } }); }
From source file:components.ToolBarDemo.java
protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) {/*from w ww . j a v a2s .c o m*/ //Look for the image. String imgLocation = "images/" + imageName + ".gif"; URL imageURL = ToolBarDemo.class.getResource(imgLocation); //Create and initialize the button. JButton button = new JButton(); button.setActionCommand(actionCommand); button.setToolTipText(toolTipText); button.addActionListener(this); 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:SwingToolBarDemo.java
protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) {//from w w w . j a v a2s . co m //Look for the image. String imgLocation = "toolbarButtonGraphics/navigation/" + imageName + ".gif"; URL imageURL = SwingToolBarDemo.class.getResource(imgLocation); //Create and initialize the button. JButton button = new JButton(); button.setActionCommand(actionCommand); button.setToolTipText(toolTipText); button.addActionListener(this); 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:components.ToolBarDemo2.java
protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) {// www. j a v a 2 s. c om //Look for the image. String imgLocation = "images/" + imageName + ".gif"; URL imageURL = ToolBarDemo2.class.getResource(imgLocation); //Create and initialize the button. JButton button = new JButton(); button.setActionCommand(actionCommand); button.setToolTipText(toolTipText); button.addActionListener(this); 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.fhaes.fhrecorder.view.GraphPanel.java
/** * Constructor for the Graphics Panel. Sets up layout and settings of all components. *//*from w ww . j a v a2 s .c om*/ public GraphPanel() { data = FileController.getYearSummaryList(); setLayout(new MigLayout("", "[grow,right]", "[fill][300px,grow,fill][][]")); JButton customizeButton = new JButton("Customize"); customizeButton.setIcon(Builder.getImageIcon("configure.png")); customizeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { showCustomizeWindow(); } }); zoomOutButton = new JButton(""); zoomOutButton.setIcon(Builder.getImageIcon("zoom_out.png")); zoomOutButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { setZoomLevel(zoomLevel + 1); } }); add(zoomOutButton, "flowx,cell 0 0"); zoomInButton = new JButton(""); zoomInButton.setIcon(Builder.getImageIcon("zoom_in.png")); zoomInButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { setZoomLevel(zoomLevel - 1); } }); add(zoomInButton, "cell 0 0"); add(customizeButton, "cell 0 0,alignx right"); rigidArea = Box.createRigidArea(new Dimension(20, 20)); rigidArea.setMaximumSize(new Dimension(200, 20)); rigidArea.setMinimumSize(new Dimension(1, 20)); add(rigidArea, "cell 0 1"); colorPane = new ColorBarGraph(data); colorPane.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int notches = e.getWheelRotation(); setZoomLevel(zoomLevel + notches); } }); add(colorPane, "cell 0 1,growx"); scrollBar = new JScrollBar(); scrollBar.setMinimum(0); scrollBar.setMaximum(data.size()); scrollBar.addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent event) { setChartsFirstCategoryIndex(event.getValue()); } }); overlayPane = new GraphSummaryOverlay(data); overlayPane.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int notches = e.getWheelRotation(); setZoomLevel(zoomLevel + notches); } }); add(overlayPane, "cell 0 2,growx"); scrollBar.setOrientation(JScrollBar.HORIZONTAL); add(scrollBar, "cell 0 3,growx"); refreshCharts(false); }
From source file:ToolBarDemo2.java
protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) {//from w w w. j a va2 s . c o m //Look for the image. String imgLocation = "toolbarButtonGraphics/navigation/" + imageName + ".gif"; URL imageURL = ToolBarDemo2.class.getResource(imgLocation); //Create and initialize the button. JButton button = new JButton(); button.setActionCommand(actionCommand); button.setToolTipText(toolTipText); button.addActionListener(this); 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:TextSamplerDemo.java
protected void addStylesToDocument(StyledDocument doc) { //Initialize some styles. Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style regular = doc.addStyle("regular", def); StyleConstants.setFontFamily(def, "SansSerif"); Style s = doc.addStyle("italic", regular); StyleConstants.setItalic(s, true); s = doc.addStyle("bold", regular); StyleConstants.setBold(s, true); s = doc.addStyle("small", regular); StyleConstants.setFontSize(s, 10); s = doc.addStyle("large", regular); StyleConstants.setFontSize(s, 16); s = doc.addStyle("icon", regular); StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER); ImageIcon pigIcon = createImageIcon("images/Pig.gif", "a cute pig"); if (pigIcon != null) { StyleConstants.setIcon(s, pigIcon); }/*from w ww . j a v a 2 s . c o m*/ s = doc.addStyle("button", regular); StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER); ImageIcon soundIcon = createImageIcon("images/sound.gif", "sound icon"); JButton button = new JButton(); if (soundIcon != null) { button.setIcon(soundIcon); } else { button.setText("BEEP"); } button.setCursor(Cursor.getDefaultCursor()); button.setMargin(new Insets(0, 0, 0, 0)); button.setActionCommand(buttonString); button.addActionListener(this); StyleConstants.setComponent(s, button); }
From source file:org.tinymediamanager.ui.dialogs.FeedbackDialog.java
/** * Instantiates a new feedback dialog.//from www . j a v a 2 s.c o m */ 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:cz.alej.michalik.totp.client.OtpPanel.java
/** * Pid jeden panel se zznamem// w w w .j av a 2 s . co m * * @param raw_data * Data z Properties * @param p * Properties * @param index * Index zznamu - pro vymazn */ public OtpPanel(String raw_data, final Properties p, final int index) { // Data jsou oddlena stednkem final String[] data = raw_data.split(";"); // this.setBackground(App.COLOR); this.setLayout(new GridBagLayout()); // Mkov rozloen prvk GridBagConstraints c = new GridBagConstraints(); this.setMaximumSize(new Dimension(Integer.MAX_VALUE, 100)); // Tla?tko pro zkoprovn hesla final JButton passPanel = new JButton(""); passPanel.setFont(passPanel.getFont().deriveFont(App.FONT_SIZE)); passPanel.setBackground(App.COLOR); // Zabere celou ku c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 100; this.add(passPanel, c); passPanel.setText(data[0]); // Tla?tko pro smazn JButton delete = new JButton("X"); try { String path = "/material-design-icons/action/drawable-xhdpi/ic_delete_black_24dp.png"; Image img = ImageIO.read(App.class.getResource(path)); delete.setIcon(new ImageIcon(img)); delete.setText(""); } catch (Exception e) { System.out.println("Icon not found"); } delete.setFont(delete.getFont().deriveFont(App.FONT_SIZE)); delete.setBackground(App.COLOR); // Zabere kousek vpravo c.fill = GridBagConstraints.NONE; c.weightx = 0.5; c.anchor = GridBagConstraints.EAST; this.add(delete, c); // Akce pro vytvoen a zkoprovn hesla do schrnky passPanel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Generuji kod pro " + data[1]); System.out.println(new Base32().decode(data[1].getBytes()).length); clip.set(new TOTP(new Base32().decode(data[1].getBytes())).toString()); System.out.printf("Kd pro %s je ve schrnce\n", data[0]); passPanel.setText("Zkoprovno"); // Zobraz zprvu na 1 vteinu int time = 1000; // Animace zobrazen zprvy po zkoprovn final Timer t = new Timer(time, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { passPanel.setText(data[0]); } }); t.start(); t.setRepeats(false); } }); // Akce pro smazn panelu a uloen zmn delete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.printf("Odstrann %s s indexem %d\n", data[0], index); p.remove(String.valueOf(index)); App.saveProperties(); App.loadProperties(); } }); }