List of usage examples for javax.swing JToggleButton setSelectedIcon
@BeanProperty(visualUpdate = true, description = "The selected icon for the button.") public void setSelectedIcon(Icon selectedIcon)
From source file:com.maxl.java.amikodesk.AMiKoDesk.java
private static void setupButton(JToggleButton button, String toolTipText, String rolloverImg, String selectedImg) {//from w ww .ja va 2 s.c om button.setFont(new Font("Dialog", Font.PLAIN, 12)); button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setHorizontalTextPosition(SwingConstants.CENTER); button.setText(toolTipText); button.setRolloverIcon(new ImageIcon(Constants.IMG_FOLDER + rolloverImg)); button.setSelectedIcon(new ImageIcon(Constants.IMG_FOLDER + selectedImg)); button.setBackground(m_selected_but_color); button.setToolTipText(toolTipText); // Remove border Border emptyBorder = BorderFactory.createEmptyBorder(); button.setBorder(emptyBorder); // Set adequate size button.setPreferredSize(new Dimension(32, 32)); }
From source file:op.controlling.PnlControlling.java
private JPanel createContentPanel4Drugs() { JPanel pnlContent = new JPanel(new VerticalLayout()); /***//from w w w. j av a 2 s . co m * ____ ____ _ _ _ _ _ * | _ \ _ __ _ _ __ _ / ___|___ _ __ | |_ _ __ ___ | | | | (_)___| |_ * | | | | '__| | | |/ _` | | | / _ \| '_ \| __| '__/ _ \| | | | | / __| __| * | |_| | | | |_| | (_| | | |__| (_) | | | | |_| | | (_) | | | |___| \__ \ |_ * |____/|_| \__,_|\__, | \____\___/|_| |_|\__|_| \___/|_| |_____|_|___/\__| * |___/ */ JPanel pnlDrugControl = new JPanel(new BorderLayout()); final JButton btnDrugControl = GUITools.createHyperlinkButton("opde.controlling.drugs.controllist", null, null); final JComboBox cmbStation = new JComboBox(StationTools.getAll4Combobox(false)); btnDrugControl.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { return MedStockTools.getListForMedControl((Station) cmbStation.getSelectedItem(), progressClosure); } @Override protected void done() { try { SYSFilesTools.print(get().toString(), true); } catch (ExecutionException ee) { OPDE.fatal(ee); } catch (InterruptedException ie) { // nop } OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); pnlDrugControl.add(btnDrugControl, BorderLayout.WEST); pnlDrugControl.add(cmbStation, BorderLayout.EAST); pnlContent.add(pnlDrugControl); /*** * __ __ _ _ _ ____ _ _ _ _ _ _ * \ \ / /__(_) __ _| |__ | |_ / ___|___ _ __ | |_ _ __ ___ | | | \ | | __ _ _ __ ___ ___ | |_(_) ___ ___ * \ \ /\ / / _ \ |/ _` | '_ \| __| | / _ \| '_ \| __| '__/ _ \| | | \| |/ _` | '__/ __/ _ \| __| |/ __/ __| * \ V V / __/ | (_| | | | | |_| |__| (_) | | | | |_| | | (_) | | | |\ | (_| | | | (_| (_) | |_| | (__\__ \ * \_/\_/ \___|_|\__, |_| |_|\__|\____\___/|_| |_|\__|_| \___/|_| |_| \_|\__,_|_| \___\___/ \__|_|\___|___/ * |___/ */ JPanel pnlWeightControllNarcotics = new JPanel(new BorderLayout()); final JButton btnWeightControl = GUITools .createHyperlinkButton("opde.controlling.prescription.narcotics.weightcontrol", null, null); // final JComboBox cmbStation = new JComboBox(StationTools.getAll4Combobox(false)); btnWeightControl.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { return MedStockTools.getNarcoticsWeightList(new LocalDate().minusMonths(1), new LocalDate()); } @Override protected void done() { try { SYSFilesTools.print(get().toString(), true); } catch (ExecutionException ee) { OPDE.fatal(ee); } catch (InterruptedException ie) { // nop } OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); final JToggleButton btnNotify = new JToggleButton(SYSConst.icon22mailOFF); btnNotify.setSelectedIcon(SYSConst.icon22mailON); btnNotify.setSelected(NotificationTools.find(OPDE.getLogin().getUser(), NotificationTools.NKEY_DRUG_WEIGHT_CONTROL) != null); btnNotify.setToolTipText(SYSTools.xx("opde.notification.enable.for.this.topic")); btnNotify.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Users user = em.merge(OPDE.getLogin().getUser()); em.lock(user, LockModeType.OPTIMISTIC_FORCE_INCREMENT); if (e.getStateChange() == ItemEvent.SELECTED) { Notification myNotification = em .merge(new Notification(NotificationTools.NKEY_DRUG_WEIGHT_CONTROL, user)); user.getNotifications().add(myNotification); } else { Notification myNotification = em.merge(NotificationTools.find(OPDE.getLogin().getUser(), NotificationTools.NKEY_DRUG_WEIGHT_CONTROL)); user.getNotifications().remove(myNotification); em.remove(myNotification); } em.getTransaction().commit(); OPDE.getLogin().setUser(user); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception ex) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(ex); } finally { em.close(); } } }); pnlWeightControllNarcotics.add(btnWeightControl, BorderLayout.WEST); pnlWeightControllNarcotics.add(btnNotify, BorderLayout.EAST); pnlContent.add(pnlWeightControllNarcotics); return pnlContent; }
From source file:org.revager.tools.GUITools.java
/** * Creates a new image toggle button./*from w w w . j a va 2 s . co m*/ * * @param icon * the normal icon * @param rolloverIcon * the rollover icon * @param action * the action * * @return the newly created image button */ public static JToggleButton newImageToggleButton(ImageIcon icon, ImageIcon rolloverIcon, Action action) { JToggleButton button = new JToggleButton(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; }