List of usage examples for javax.swing JButton setEnabled
public void setEnabled(boolean b)
From source file:Main.java
public static void disableNewFolderButton(Container c) { int len = c.getComponentCount(); for (int i = 0; i < len; i++) { Component comp = c.getComponent(i); if (comp instanceof JButton) { JButton b = (JButton) comp; Icon icon = b.getIcon(); if (icon != null && icon == UIManager.getIcon("FileChooser.newFolderIcon")) b.setEnabled(false); } else if (comp instanceof Container) { disableNewFolderButton((Container) comp); }//from www . ja v a 2 s .co m } }
From source file:MainClass.java
public static JScrollPane createPagingScrollPaneForTable(JTable jt) { JScrollPane jsp = new JScrollPane(jt); TableModel tmodel = jt.getModel(); if (!(tmodel instanceof PagingModel)) { return jsp; }//from w ww.j av a2s . c o m final PagingModel model = (PagingModel) tmodel; final JButton upButton = new JButton("UP"); upButton.setEnabled(false); final JButton downButton = new JButton("DOWN"); if (model.getPageCount() <= 1) { downButton.setEnabled(false); } upButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageUp(); if (model.getPageOffset() == 0) { upButton.setEnabled(false); } downButton.setEnabled(true); } }); downButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageDown(); if (model.getPageOffset() == (model.getPageCount() - 1)) { downButton.setEnabled(false); } upButton.setEnabled(true); } }); jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton); jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton); return jsp; }
From source file:PagingTester.java
public static JScrollPane createPagingScrollPaneForTable(JTable jt) { JScrollPane jsp = new JScrollPane(jt); TableModel tmodel = jt.getModel(); // Don't choke if this is called on a regular table . . . if (!(tmodel instanceof PagingModel)) { return jsp; }/*from w ww .j a v a 2s. c o m*/ // Okay, go ahead and build the real scrollpane final PagingModel model = (PagingModel) tmodel; final JButton upButton = new JButton(new ArrowIcon(ArrowIcon.UP)); upButton.setEnabled(false); // starts off at 0, so can't go up final JButton downButton = new JButton(new ArrowIcon(ArrowIcon.DOWN)); if (model.getPageCount() <= 1) { downButton.setEnabled(false); // One page...can't scroll down } upButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageUp(); // If we hit the top of the data, disable the up button. if (model.getPageOffset() == 0) { upButton.setEnabled(false); } downButton.setEnabled(true); } }); downButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageDown(); // If we hit the bottom of the data, disable the down button. if (model.getPageOffset() == (model.getPageCount() - 1)) { downButton.setEnabled(false); } upButton.setEnabled(true); } }); // Turn on the scrollbars; otherwise we won't get our corners. jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); // Add in the corners (page up/down). jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton); jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton); return jsp; }
From source file:MainClass.java
public static JPanel demo1() { JPanel pan = new JPanel(new BorderLayout()); pan.setBorder(new TitledBorder("change format midstream")); MaskFormatter lowercase = null; try {//w w w. ja v a 2s. c om lowercase = new MaskFormatter("LLLL"); } catch (ParseException pe) { } final JFormattedTextField field = new JFormattedTextField(lowercase); field.setValue("lower case"); pan.add(field, BorderLayout.CENTER); final JButton change = new JButton("change format"); JPanel changePanel = new JPanel(); changePanel.add(change); pan.add(changePanel, BorderLayout.SOUTH); change.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { field.commitEdit(); MaskFormatter uppercase = new MaskFormatter("UUUU"); DefaultFormatterFactory factory = new DefaultFormatterFactory(uppercase); field.setFormatterFactory(factory); change.setEnabled(false); } catch (ParseException pe) { } } }); return pan; }
From source file:eu.europa.ec.markt.dss.applet.util.ComponentFactory.java
/** * /*from ww w. ja v a 2s. c om*/ * @param label * @param actionListener * @param enabled * @return */ public static JButton createButton(final String label, final boolean enabled, final ActionListener actionListener) { final JButton button = new JButton(label); button.setEnabled(enabled); button.addActionListener(actionListener); return button; }
From source file:FactoryDemo.java
public static JPanel demo2() { // Demo 2: Change the format of a field when the user presses a button. // We can't call field.setFormatter() because that's a protected method. // (Plus it wouldn't work anyway. The old factory would replace our new // formatter with an "old" one next time the field gains or loses // focus.)/*from ww w .j a v a 2 s. c o m*/ // The thing to do is send a new factory to field.setFormatterFactory(). JPanel pan = new JPanel(new BorderLayout()); pan.setBorder(new TitledBorder("Demo 2: change format midstream")); MaskFormatter lowercase = null; try { lowercase = new MaskFormatter("LLLL"); } catch (ParseException pe) { } final JFormattedTextField field = new JFormattedTextField(lowercase); field.setValue("Fore"); pan.add(field, BorderLayout.CENTER); final JButton change = new JButton("change format"); JPanel changePanel = new JPanel(); changePanel.add(change); pan.add(changePanel, BorderLayout.SOUTH); change.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { field.commitEdit(); // commit current edit (if any) MaskFormatter uppercase = new MaskFormatter("UUUU"); DefaultFormatterFactory factory = new DefaultFormatterFactory(uppercase); field.setFormatterFactory(factory); change.setEnabled(false); } catch (ParseException pe) { } } }); return pan; }
From source file:edu.ku.brc.specify.config.init.RegisterSpecify.java
/** * Registers the ISA number./*from w ww . j ava2 s. c o m*/ */ public static void registerISA() { SpecifyUser spUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class); if (!spUser.getUserType().equals(SpecifyUserTypes.UserType.Manager.toString())) { UIRegistry.showLocalizedMsg("", "SpReg.MUSTBECM"); return; } Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class); String isaNumber = collection.getIsaNumber(); String isaTitle = getResourceString("SpReg.ISA_TITLE"); if (StringUtils.isNotEmpty(isaNumber)) { String msg = UIRegistry.getLocalizedMessage("SpReg.ISA_NUM", isaNumber); JOptionPane.showMessageDialog(UIRegistry.getTopWindow(), msg, isaTitle, JOptionPane.INFORMATION_MESSAGE); } else { final JTextField textField = UIHelper.createTextField(30); isaNumber = textField.getText(); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,10px,p")); pb.add(UIHelper.createI18NFormLabel("SpReg.ISA_ENT"), cc.xy(1, 1)); pb.add(textField, cc.xy(3, 1)); pb.add(UIHelper.createI18NLabel("SpReg.ISA_EXPL"), cc.xyw(1, 3, 3)); pb.setDefaultDialogBorder(); CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(), isaTitle, true, pb.getPanel()); dlg.createUI(); final JButton okBtn = dlg.getOkBtn(); okBtn.setEnabled(false); textField.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { if (StringUtils.isNotEmpty(textField.getText()) != okBtn.isEnabled()) { okBtn.setEnabled(!okBtn.isEnabled()); } } }); dlg.setVisible(true); isaNumber = textField.getText(); if (!dlg.isCancelled() && StringUtils.isNotEmpty(isaNumber)) { setIsAnonymous(false); collection.setIsaNumber(isaNumber); getInstance().doStartRegister(RegisterType.Collection, false, true); AppPreferences.getLocalPrefs().putBoolean(EXTRA_CHECK, true); } } }
From source file:com.diversityarrays.kdxplore.vistool.VisToolbarFactory.java
static public VisToolToolBar create(final String title, final JComponent comp, final Closure<File> snapshotter, final VisToolDataProvider visToolDataProvider, boolean floatable, final String[] imageSuffixes) { Window window = GuiUtil.getOwnerWindow(comp); boolean anyButtons = false; final JCheckBox keepOnTop; if (window == null) { keepOnTop = null;/* ww w .j av a 2s .c o m*/ } else { anyButtons = true; keepOnTop = new JCheckBox(Msg.OPTION_KEEP_ON_TOP(), true); keepOnTop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { window.setAlwaysOnTop(keepOnTop.isSelected()); } }); window.setAlwaysOnTop(keepOnTop.isSelected()); // buttons.add(keepOnTop); final PropertyChangeListener alwaysOnTopListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { keepOnTop.setSelected(window.isAlwaysOnTop()); } }; window.addPropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener); window.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { window.removeWindowListener(this); window.removePropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener); } }); } final JButton cameraButton; if (snapshotter == null) { cameraButton = null; } else { Action cameraAction = new AbstractAction(Msg.ACTION_SNAPSHOT()) { @Override public void actionPerformed(ActionEvent e) { if (chooser == null) { chooser = new JFileChooser(); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (!f.isFile()) { return true; } String loname = f.getName().toLowerCase(); for (String sfx : imageSuffixes) { if (loname.endsWith(sfx)) { return true; } } return false; } @Override public String getDescription() { return Msg.DESC_IMAGE_FILE(); } }); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); } if (JFileChooser.APPROVE_OPTION == chooser.showSaveDialog(comp)) { File file = chooser.getSelectedFile(); snapshotter.execute(file); } } }; ImageIcon icon = loadIcon("camera-24.png"); //$NON-NLS-1$ if (icon != null) { cameraAction.putValue(Action.SMALL_ICON, icon); cameraAction.putValue(Action.NAME, null); } anyButtons = true; cameraButton = new JButton(cameraAction); } final JButton refreshButton; if (visToolDataProvider == null) { refreshButton = null; } else { anyButtons = true; refreshButton = new JButton(Msg.ACTION_REFRESH()); ImageIcon icon = loadIcon("refresh-24.png"); //$NON-NLS-1$ if (icon != null) { refreshButton.setIcon(icon); // don't remove the name } refreshButton.setForeground(Color.RED); refreshButton.setEnabled(false); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (visToolDataProvider.refreshData()) { refreshButton.setEnabled(false); } } }); visToolDataProvider.addVisToolDataChangedListener(new VisToolDataChangedListener() { @Override public void visToolDataChanged(Object source) { refreshButton.setEnabled(true); } }); } VisToolToolBar toolBar = null; if (anyButtons) { toolBar = new VisToolToolBar(keepOnTop, cameraButton, refreshButton); toolBar.setFloatable(floatable); } return toolBar; }
From source file:com.willwinder.universalgcodesender.uielements.macros.MacroActionPanel.java
private void updateCustomGcodeControls(boolean enabled) { for (JButton button : customGcodeButtons) { button.setEnabled(enabled); }// w w w . ja v a 2 s.com }
From source file:com.unicauca.braim.http.HttpBraimClient.java
public Song[] GET_Songs(int page, String access_token, JButton bt_next_list, JButton bt_previous_list) throws IOException { if (page == 1) { bt_previous_list.setEnabled(false); } else {//from w ww . j a v a 2 s . c o m bt_previous_list.setEnabled(true); } String token = "braim_token=" + access_token; String data = "page=" + page + "&per_page=10"; GetMethod method = new GetMethod(api_url + "/api/v1/songs?" + token + "&" + data); Song[] songList = null; Gson gson = new Gson(); try { method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } byte[] responseBody = method.getResponseBody(); Integer total_pages = Integer.parseInt(method.getResponseHeader("total_pages").getValue()); System.out.println("TOTAL SONG PAGES= " + method.getResponseHeader("total_pages")); String response = new String(responseBody, "UTF-8"); songList = gson.fromJson(response, Song[].class); if (page == total_pages) { bt_next_list.setEnabled(false); } else { bt_next_list.setEnabled(true); } } catch (UnsupportedEncodingException ex) { Logger.getLogger(HttpBraimClient.class.getName()).log(Level.SEVERE, null, ex); } return songList; }