List of usage examples for javax.swing ButtonGroup add
public void add(AbstractButton b)
From source file:com.floreantpos.bo.ui.explorer.QuickMaintenanceExplorer.java
public QuickMaintenanceExplorer() { super(new MigLayout("inset 0")); int btnSize = PosUIManager.getSize(60); btnCursor = new POSToggleButton(); btnCursor.setIcon(IconFactory.getIcon("/ui_icons/", "cursor_hand.png")); btnEdit = new POSToggleButton("EDIT"); btnCopy = new POSToggleButton("COPY"); btnDelete = new POSToggleButton("DEL"); btni18 = new POSToggleButton("i18n"); ButtonGroup group = new ButtonGroup(); group.add(btnCursor); group.add(btnCopy);//from w ww .j a va2 s . com group.add(btnEdit); group.add(btnDelete); group.add(btni18); btnEdit.setSelected(true); add(btnCursor, "w " + btnSize + "!, h " + btnSize + "!"); add(btnEdit, "w " + btnSize + "!, h " + btnSize + "!"); add(btnCopy, "w " + btnSize + "!, h " + btnSize + "!"); add(btnDelete, "w " + btnSize + "!, h " + btnSize + "!"); //add(btni18, "w " + btnSize + "!, h " + btnSize + "!"); }
From source file:com.floreantpos.ui.OrderFilterPanel.java
private void createPaymentStatusFilterPanel() { btnFilterByOpenStatus = new POSToggleButton(PaymentStatusFilter.OPEN.toString()); btnFilterByPaidStatus = new POSToggleButton(PaymentStatusFilter.PAID.toString()); btnFilterByUnPaidStatus = new POSToggleButton(PaymentStatusFilter.CLOSED.toString()); final ButtonGroup paymentGroup = new ButtonGroup(); paymentGroup.add(btnFilterByOpenStatus); paymentGroup.add(btnFilterByPaidStatus); paymentGroup.add(btnFilterByUnPaidStatus); PaymentStatusFilter paymentStatusFilter = TerminalConfig.getPaymentStatusFilter(); switch (paymentStatusFilter) { case OPEN:/*from w w w . j a va2 s. c o m*/ btnFilterByOpenStatus.setSelected(true); break; case PAID: btnFilterByPaidStatus.setSelected(true); break; case CLOSED: btnFilterByUnPaidStatus.setSelected(true); break; } ActionListener psFilterHandler = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); if (actionCommand.equals("CLOSED") && !Application.getCurrentUser().hasPermission(UserPermission.VIEW_ALL_CLOSE_TICKETS)) { String password = PasswordEntryDialog.show(Application.getPosWindow(), "Please enter privileged password"); if (StringUtils.isEmpty(password)) { updateButton(); return; } User user2 = UserDAO.getInstance().findUserBySecretKey(password); if (user2 == null) { POSMessageDialog.showError(Application.getPosWindow(), "No user found with that secret key"); updateButton(); return; } else { if (!user2.hasPermission(UserPermission.VIEW_ALL_CLOSE_TICKETS)) { POSMessageDialog.showError(Application.getPosWindow(), "No permission"); updateButton(); return; } } } String filter = actionCommand.replaceAll("\\s", "_"); //$NON-NLS-1$ //$NON-NLS-2$ TerminalConfig.setPaymentStatusFilter(filter); ticketList.updateTicketList(); ticketLists.updateButtonStatus(); } }; btnFilterByOpenStatus.addActionListener(psFilterHandler); btnFilterByPaidStatus.addActionListener(psFilterHandler); btnFilterByUnPaidStatus.addActionListener(psFilterHandler); JPanel filterByPaymentStatusPanel = new JPanel(new MigLayout("", "fill, grow", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ filterByPaymentStatusPanel.setBorder(new TitledBorder(Messages.getString("SwitchboardView.3"))); //$NON-NLS-1$ filterByPaymentStatusPanel.add(btnFilterByOpenStatus); filterByPaymentStatusPanel.add(btnFilterByPaidStatus); filterByPaymentStatusPanel.add(btnFilterByUnPaidStatus); getContentPane().add(filterByPaymentStatusPanel); }
From source file:LightBug.java
JPanel lightPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(0, 1)); panel.add(new JLabel("Light type")); // create the buttons JRadioButton lightNoneButton = new JRadioButton(lightNoneString); JRadioButton lightDirectionalButton = new JRadioButton(lightDirectionalString); JRadioButton lightPointButton = new JRadioButton(lightPointString); JRadioButton lightSpotButton = new JRadioButton(lightSpotString); // set up the action commands lightNoneButton.setActionCommand(lightNoneString); lightDirectionalButton.setActionCommand(lightDirectionalString); lightPointButton.setActionCommand(lightPointString); lightSpotButton.setActionCommand(lightSpotString); // add the buttons to a group so that only one can be selected ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(lightNoneButton); buttonGroup.add(lightDirectionalButton); buttonGroup.add(lightPointButton);//from ww w. ja va 2s .c o m buttonGroup.add(lightSpotButton); // register the applet as the listener for the buttons lightNoneButton.addActionListener(this); lightDirectionalButton.addActionListener(this); lightPointButton.addActionListener(this); lightSpotButton.addActionListener(this); // add the buttons to the panel panel.add(lightNoneButton); panel.add(lightDirectionalButton); panel.add(lightPointButton); panel.add(lightSpotButton); // set the default lightDirectionalButton.setSelected(true); return panel; }
From source file:SoundBug.java
JPanel soundPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(4, 1)); // create the buttons soundNoneButton = new JRadioButton(soundNoneString); soundBackgroundButton = new JRadioButton(soundBackgroundString); soundPointButton = new JRadioButton(soundPointString); //soundConeButton = new JRadioButton(soundConeString); // set up the action commands soundNoneButton.setActionCommand(soundNoneString); soundBackgroundButton.setActionCommand(soundBackgroundActionString); soundPointButton.setActionCommand(soundPointActionString); //soundConeButton.setActionCommand(soundConeString); // add the buttons to a group so that only one can be selected ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(soundNoneButton); buttonGroup.add(soundBackgroundButton); buttonGroup.add(soundPointButton);//from w ww. j a v a 2s.com //buttonGroup.add(soundConeButton); // register the applet as the listener for the buttons soundNoneButton.addActionListener(this); soundBackgroundButton.addActionListener(this); soundPointButton.addActionListener(this); // soundConeButton.addActionListener(this); // add the buttons to the panel panel.add(soundNoneButton); panel.add(soundBackgroundButton); panel.add(soundPointButton); //panel.add(soundConeButton); // set the default soundNoneButton.setSelected(true); return panel; }
From source file:com.floreantpos.ui.views.LoginPasswordEntryView.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor.//from w ww . ja va2s.co m */ // <editor-fold defaultstate="collapsed" // desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { buttonPanel = new javax.swing.JPanel(); bottomPanel = new javax.swing.JPanel(); btnShutdown = new com.floreantpos.swing.PosButton(); setPreferredSize(new Dimension(320, 593)); setLayout(new BorderLayout()); buttonPanel.setOpaque(false); buttonPanel.setPreferredSize(new java.awt.Dimension(200, 180)); buttonPanel.setLayout(new MigLayout("", "[111px][111px][111px,grow]", "[60px][60px][60px][60px]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ lblTerminalId = new JLabel("TERMINAL ID:"); //$NON-NLS-1$ lblTerminalId.setForeground(Color.BLACK); lblTerminalId.setFont(new Font("Dialog", Font.BOLD, 18)); //$NON-NLS-1$ lblTerminalId.setHorizontalAlignment(SwingConstants.CENTER); add(lblTerminalId, BorderLayout.NORTH); bottomPanel.setLayout(new MigLayout("hidemode 3, fill")); //$NON-NLS-1$ bottomPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(btnRegularMode); //buttonGroup.add(btnCashierMode); buttonGroup.add(btnKitchenMode); btnRegularMode.setFocusable(false); // btnCashierMode.setFocusable(false); btnKitchenMode.setFocusable(false); ModeSelectionListener l = new ModeSelectionListener(); btnRegularMode.addActionListener(l); // btnCashierMode.addActionListener(l); btnKitchenMode.addActionListener(l); btnRegularMode.setSelected(TerminalConfig.isRegularMode()); // btnCashierMode.setSelected(TerminalConfig.isCashierMode()); btnKitchenMode.setSelected(TerminalConfig.isKitchenMode()); if (!btnRegularMode.isSelected() && !btnKitchenMode.isSelected()) { btnRegularMode.setSelected(true); } JPanel modePanel = new JPanel(new GridLayout(1, 0, 2, 2)); modePanel.add(btnRegularMode); // modePanel.add(btnCashierMode); modePanel.add(btnKitchenMode); bottomPanel.add(modePanel, "h 60!, grow, wrap"); //$NON-NLS-1$ psbtnLogin = new PosButton(); psbtnLogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doLogin(); } }); psbtnLogin.setText("LOGIN"); //$NON-NLS-1$ bottomPanel.add(psbtnLogin, "grow, wrap, gapbottom 20px"); //$NON-NLS-1$ PosButton btnClockOUt = new PosButton(new ClockInOutAction(false, true)); bottomPanel.add(btnClockOUt, "grow, wrap, h 60!"); //$NON-NLS-1$ if (TerminalConfig.isShowDbConfigureButton()) { btnConfigureDatabase = new com.floreantpos.swing.PosButton(); btnConfigureDatabase.setAction(goAction); btnConfigureDatabase.setText(com.floreantpos.POSConstants.CONFIGURE_DATABASE); btnConfigureDatabase.setFocusable(false); btnConfigureDatabase.setActionCommand("DBCONFIG"); //$NON-NLS-1$ bottomPanel.add(btnConfigureDatabase, "grow, wrap, h 60!"); //$NON-NLS-1$ } btnShutdown.setAction(goAction); btnShutdown.setText(com.floreantpos.POSConstants.SHUTDOWN); btnShutdown.setFocusable(false); if (TerminalConfig.isFullscreenMode()) { if (btnConfigureDatabase != null) { btnConfigureDatabase.setVisible(false); } if (btnShutdown != null) { btnShutdown.setVisible(false); } } bottomPanel.add(btnShutdown, "grow, wrap, h 60!"); //$NON-NLS-1$ add(bottomPanel, BorderLayout.SOUTH); lblTerminalId.setText(""); //$NON-NLS-1$ }
From source file:EditorPaneExample7.java
public EditorPaneExample7() { super("JEditorPane Example 7"); pane = new JEditorPane(); pane.setEditable(false); // Start read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;//from w w w . ja va 2s. c o m c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("File name: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; textField = new JTextField(32); panel.add(textField, c); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; c.gridwidth = 2; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); getContentPane().add(panel, "South"); panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); saveButton = new JButton("Save"); plain = new JCheckBox("Plain Text"); html = new JCheckBox("HTML"); rtf = new JCheckBox("RTF"); panel.add(plain); panel.add(html); panel.add(rtf); ButtonGroup group = new ButtonGroup(); group.add(plain); group.add(html); group.add(rtf); plain.setSelected(true); panel.add(Box.createVerticalStrut(10)); panel.add(saveButton); panel.add(Box.createVerticalGlue()); panel.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4)); getContentPane().add(panel, "East"); // Change page based on text field textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String fileName = textField.getText().trim(); file = new File(fileName); absolutePath = file.getAbsolutePath(); String url = "file:///" + absolutePath; try { // Check if the new page and the old // page are the same. URL newURL = new URL(url); URL loadedURL = pane.getPage(); if (loadedURL != null && loadedURL.sameFile(newURL)) { return; } // Try to display the page textField.setEnabled(false); // Disable input textField.paintImmediately(0, 0, textField.getSize().width, textField.getSize().height); saveButton.setEnabled(false); saveButton.paintImmediately(0, 0, saveButton.getSize().width, saveButton.getSize().height); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Busy cursor loadingState.setText("Loading..."); loadingState.paintImmediately(0, 0, loadingState.getSize().width, loadingState.getSize().height); loadedType.setText(""); loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height); pane.setEditable(false); pane.setPage(url); loadedType.setText(pane.getContentType()); } catch (Exception e) { JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); textField.setEnabled(true); setCursor(Cursor.getDefaultCursor()); } } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadingState.setText("Page loaded."); textField.setEnabled(true); // Allow entry of new file name textField.requestFocus(); setCursor(Cursor.getDefaultCursor()); // Allow editing and saving if appropriate pane.setEditable(file.canWrite()); saveButton.setEnabled(file.canWrite()); } } }); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Writer w = null; OutputStream os = System.out; String contentType; if (plain.isSelected()) { contentType = "text/plain"; w = new OutputStreamWriter(os); } else if (html.isSelected()) { contentType = "text/html"; w = new OutputStreamWriter(os); } else { contentType = "text/rtf"; } EditorKit kit = pane.getEditorKitForContentType(contentType); try { if (w != null) { kit.write(w, pane.getDocument(), 0, pane.getDocument().getLength()); w.flush(); } else { kit.write(os, pane.getDocument(), 0, pane.getDocument().getLength()); os.flush(); } } catch (Exception e) { System.out.println("Write failed"); } } }); }
From source file:it.cnr.icar.eric.client.ui.swing.FindParamsPanel.java
private JPanel createSearchTypePanel() { //It just has two radio buttons that Selects from Business and Adhoc Query JPanel searchTypePanel = new JPanel(); businessButton = new JRadioButton(resourceBundle.getString("button.businessQuery")); businessButton.setMnemonic(KeyEvent.VK_B); businessButton.setSelected(true);/* w w w .j a va 2 s.co m*/ businessButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cardLayout.show(paramEntryParentPanel, "businessPanel"); businessQuery = true; } }); adhocButton = new JRadioButton(resourceBundle.getString("button.adHocQuery")); adhocButton.setMnemonic(KeyEvent.VK_A); adhocButton.setSelected(false); adhocButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cardLayout.show(paramEntryParentPanel, "adhocPanel"); businessQuery = false; } }); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(businessButton); buttonGroup.add(adhocButton); searchTypePanel.add(businessButton); searchTypePanel.add(adhocButton); return searchTypePanel; }
From source file:CardLayoutDemo.java
public void addCardsToPane(Container pane) { JRadioButton[] rb = new JRadioButton[strings.length]; ButtonGroup group = new ButtonGroup(); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.PAGE_AXIS)); for (int i = 0; i < strings.length; i++) { rb[i] = new JRadioButton("Show component #" + (i + 1)); rb[i].setActionCommand(String.valueOf(i)); rb[i].addActionListener(this); group.add(rb[i]); buttons.add(rb[i]);/* www. j a v a 2s .c o m*/ } rb[0].setSelected(true); //Create the panel that contains the "cards". cards = new JPanel(new CardLayout()); for (int i = 0; i < strings.length; i++) { cards.add(createComponent(strings[i]), String.valueOf(i)); } pane.add(buttons, BorderLayout.NORTH); pane.add(cards, BorderLayout.CENTER); }
From source file:MenuLookDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;//from w w w.ja va 2 s .c o m JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; // Create the menu bar. menuBar = new JMenuBar(); // Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); // a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); // menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menu.add(menuItem); // a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); menu.add(rbMenuItem); // a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); menu.add(cbMenuItem); // a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); submenu.add(menuItem); menu.add(submenu); // Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:components.MenuLookDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;// w w w . j a va 2s.c o m JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }