List of usage examples for javax.swing ButtonGroup ButtonGroup
public ButtonGroup()
ButtonGroup
. From source file:TArea.java
public void init() { Container container = getContentPane(); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(2, 2)); resetButton = new JRadioButton("Reset", true); addButton = new JRadioButton("Add"); subtractButton = new JRadioButton("Subtract"); intersectButton = new JRadioButton("Intersect"); exclusiveORButton = new JRadioButton("ExclusiveOR"); ButtonGroup group = new ButtonGroup(); group.add(resetButton);// w ww .j a v a 2s.co m group.add(addButton); group.add(subtractButton); group.add(intersectButton); group.add(exclusiveORButton); group.add(resetButton); resetButton.addActionListener(this); addButton.addActionListener(this); subtractButton.addActionListener(this); intersectButton.addActionListener(this); exclusiveORButton.addActionListener(this); panel.add(addButton); panel.add(subtractButton); panel.add(intersectButton); panel.add(exclusiveORButton); container.add(panel, BorderLayout.NORTH); container.add(resetButton, BorderLayout.SOUTH); canvas = new DrawingCanvas(); container.add(canvas); }
From source file:FramewithMenuShortcut.java
public FramewithMenuShortcut(String title) { JMenu fileMenu = new JMenu("File"); // Create File menu JMenu elementMenu = new JMenu("Elements"); // Create Elements menu fileMenu.setMnemonic('F'); // Create shortcut elementMenu.setMnemonic('E'); // Create shortcut setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);// ww w. j a v a2 s . co m newItem = fileMenu.add("New"); openItem = fileMenu.add("Open"); closeItem = fileMenu.add("Close"); fileMenu.addSeparator(); saveItem = fileMenu.add("Save"); saveAsItem = fileMenu.add("Save As..."); fileMenu.addSeparator(); printItem = fileMenu.add("Print"); elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true)); elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false)); elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false)); ButtonGroup types = new ButtonGroup(); types.add(lineItem); types.add(rectangleItem); types.add(circleItem); elementMenu.addSeparator(); elementMenu.add(redItem = new JCheckBoxMenuItem("Red", false)); elementMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false)); menuBar.add(fileMenu); menuBar.add(elementMenu); newItem.setAccelerator(KeyStroke.getKeyStroke('N', CTRL_DOWN_MASK)); openItem.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK)); saveItem.setAccelerator(KeyStroke.getKeyStroke('S', CTRL_DOWN_MASK)); printItem.setAccelerator(KeyStroke.getKeyStroke('P', CTRL_DOWN_MASK)); lineItem.setAccelerator(KeyStroke.getKeyStroke('L', CTRL_DOWN_MASK)); rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', CTRL_DOWN_MASK)); circleItem.setAccelerator(KeyStroke.getKeyStroke('I', CTRL_DOWN_MASK)); elementMenu.addSeparator(); redItem.setAccelerator(KeyStroke.getKeyStroke('R', CTRL_DOWN_MASK)); yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', CTRL_DOWN_MASK)); menuBar.add(fileMenu); menuBar.add(elementMenu); }
From source file:ScrollDemo2.java
public void init() { JRadioButton form[][] = new JRadioButton[12][5]; String counts[] = { "", "0-1", "2-5", "6-10", "11-100", "101+" }; String categories[] = { "Household", "Office", "Extended Family", "Company (US)", "Company (World)", "Team", "Will", "Birthday Card List", "High School", "Country", "Continent", "Planet" }; JPanel p = new JPanel(); p.setSize(600, 400);// w w w. ja v a 2 s . c o m p.setLayout(new GridLayout(13, 6, 10, 0)); for (int row = 0; row < 13; row++) { ButtonGroup bg = new ButtonGroup(); for (int col = 0; col < 6; col++) { if (row == 0) { p.add(new JLabel(counts[col])); } else { if (col == 0) { p.add(new JLabel(categories[row - 1])); } else { form[row - 1][col - 1] = new JRadioButton(); bg.add(form[row - 1][col - 1]); p.add(form[row - 1][col - 1]); } } } } scrollpane = new JScrollPane(p); // Add in some JViewports for the column and row headers JViewport jv1 = new JViewport(); jv1.setView(new JLabel(new ImageIcon("columnlabel.gif"))); scrollpane.setColumnHeader(jv1); JViewport jv2 = new JViewport(); jv2.setView(new JLabel(new ImageIcon("rowlabel.gif"))); scrollpane.setRowHeader(jv2); // And throw in an information button JButton jb1 = new JButton(new ImageIcon("question.gif")); jb1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JOptionPane.showMessageDialog(null, "This is an Active Corner!", "Information", JOptionPane.INFORMATION_MESSAGE); } }); scrollpane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, jb1); getContentPane().add(scrollpane, BorderLayout.CENTER); }
From source file:MenuTest.java
public MenuTest() { super();/*w ww . j a v a2s. c o m*/ MenuListener listener = new MenuListener() { public void menuCanceled(MenuEvent e) { dumpInfo("Canceled", e); } public void menuDeselected(MenuEvent e) { dumpInfo("Deselected", e); } public void menuSelected(MenuEvent e) { dumpInfo("Selected", e); } private void dumpInfo(String s, MenuEvent e) { JMenu menu = (JMenu) e.getSource(); System.out.println(s + ": " + menu.getText()); } }; JMenu fileMenu = new JMenu("File"); fileMenu.addMenuListener(listener); fileMenu.add(new JMenuItem("Open")); fileMenu.add(new JMenuItem("Close")); fileMenu.add(new JMenuItem("Exit")); JMenu helpMenu = new JMenu("Help"); helpMenu.addMenuListener(listener); helpMenu.add(new JMenuItem("About MenuTest")); helpMenu.add(new JMenuItem("Class Hierarchy")); helpMenu.addSeparator(); helpMenu.add(new JCheckBoxMenuItem("Balloon Help")); JMenu subMenu = new JMenu("Categories"); subMenu.addMenuListener(listener); JRadioButtonMenuItem rb; ButtonGroup group = new ButtonGroup(); subMenu.add(rb = new JRadioButtonMenuItem("A Little Help", true)); group.add(rb); subMenu.add(rb = new JRadioButtonMenuItem("A Lot of Help")); group.add(rb); helpMenu.add(subMenu); JMenuBar mb = new JMenuBar(); mb.add(fileMenu); mb.add(helpMenu); setJMenuBar(mb); }
From source file:WeatherFrame.java
public WeatherFrame() { initComponents();/*w w w. j a v a 2 s. c om*/ fc = new JFileChooser(); fc.setMultiSelectionEnabled(true); //only can select a single button a time ButtonGroup group = new ButtonGroup(); group.add(AllRadioButton); group.add(YearlyRadioButton); group.add(MonthlyRadioButton); group.add(WeeklyRadioButton); group.add(DailyRadioButton); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Temperature", "Humidity", "Barometric Pressure", "Windspeed", "UVindex", "Raindfall" })); TempSet = new TimeSeriesCollection(); JFreeChart chart = ChartFactory.createXYLineChart("Temperature", "", "Degree Fahrenheit", TempSet, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); ChartPanel.setLayout(new java.awt.BorderLayout()); ChartPanel CP = new ChartPanel(chart); CP.setPreferredSize(new Dimension(ChartPanel.getWidth(), ChartPanel.getHeight())); ChartPanel.add(CP, BorderLayout.CENTER); DefaultValueDataset dataset = new DefaultValueDataset(20f); ThermometerPlot thermometerplot = new ThermometerPlot(dataset); JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, thermometerplot, true); jfreechart.setBackgroundPaint(new Color(240, 240, 240)); thermometerplot.setThermometerPaint(Color.lightGray); thermometerplot.setThermometerStroke(new BasicStroke(2.0F)); ChartPanel DP = new ChartPanel(jfreechart); DP.setPreferredSize(new Dimension(TempThermoPanel.getWidth(), TempThermoPanel.getHeight())); TempThermoPanel.setLayout(new java.awt.BorderLayout()); TempThermoPanel.add(DP); TempThermoPanel.validate(); }
From source file:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);/* w w w. ja va2 s. c o m*/ JMenu fileMenu = new JMenu("File"); JMenu elementMenu = new JMenu("Elements"); fileMenu.setMnemonic('F'); elementMenu.setMnemonic('E'); // Construct the file pull down menu newItem = fileMenu.add("New"); openItem = fileMenu.add("Open"); closeItem = fileMenu.add("Close"); fileMenu.addSeparator(); saveItem = fileMenu.add("Save"); saveAsItem = fileMenu.add("Save As..."); JMenu colorMenu = new JMenu("Color"); fileMenu.addSeparator(); printItem = fileMenu.add("Print"); newItem.setAccelerator(KeyStroke.getKeyStroke('N', Event.CTRL_MASK)); openItem.setAccelerator(KeyStroke.getKeyStroke('O', Event.CTRL_MASK)); saveItem.setAccelerator(KeyStroke.getKeyStroke('S', Event.CTRL_MASK)); printItem.setAccelerator(KeyStroke.getKeyStroke('P', Event.CTRL_MASK)); elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true)); elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false)); elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false)); elementMenu.add(curveItem = new JRadioButtonMenuItem("Curve", false)); ButtonGroup types = new ButtonGroup(); types.add(lineItem); types.add(rectangleItem); types.add(circleItem); types.add(curveItem); lineItem.setAccelerator(KeyStroke.getKeyStroke('L', Event.CTRL_MASK)); rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', Event.CTRL_MASK)); circleItem.setAccelerator(KeyStroke.getKeyStroke('I', Event.CTRL_MASK)); curveItem.setAccelerator(KeyStroke.getKeyStroke('V', Event.CTRL_MASK)); elementMenu.addSeparator(); elementMenu.add(colorMenu); // Add the sub-menu colorMenu.add(redItem = new JCheckBoxMenuItem("Red", false)); colorMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false)); colorMenu.add(greenItem = new JCheckBoxMenuItem("Green", false)); colorMenu.add(blueItem = new JCheckBoxMenuItem("Blue", true)); // Add element color accelerators redItem.setAccelerator(KeyStroke.getKeyStroke('R', Event.CTRL_MASK)); yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', Event.CTRL_MASK)); greenItem.setAccelerator(KeyStroke.getKeyStroke('G', Event.CTRL_MASK)); blueItem.setAccelerator(KeyStroke.getKeyStroke('B', Event.CTRL_MASK)); menuBar.add(fileMenu); menuBar.add(elementMenu); }
From source file:MainClass.java
public MainClass() { setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);//from w ww . ja v a 2 s.c o m JMenu fileMenu = new JMenu("File"); JMenu elementMenu = new JMenu("Elements"); fileMenu.setMnemonic('F'); elementMenu.setMnemonic('E'); // Construct the file pull down menu newItem = fileMenu.add("New"); openItem = fileMenu.add("Open"); closeItem = fileMenu.add("Close"); fileMenu.addSeparator(); saveItem = fileMenu.add("Save"); saveAsItem = fileMenu.add("Save As..."); JMenu colorMenu = new JMenu("Color"); fileMenu.addSeparator(); printItem = fileMenu.add("Print"); newItem.setAccelerator(KeyStroke.getKeyStroke('N', Event.CTRL_MASK)); openItem.setAccelerator(KeyStroke.getKeyStroke('O', Event.CTRL_MASK)); saveItem.setAccelerator(KeyStroke.getKeyStroke('S', Event.CTRL_MASK)); printItem.setAccelerator(KeyStroke.getKeyStroke('P', Event.CTRL_MASK)); elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true)); elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false)); elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false)); elementMenu.add(curveItem = new JRadioButtonMenuItem("Curve", false)); ButtonGroup types = new ButtonGroup(); types.add(lineItem); types.add(rectangleItem); types.add(circleItem); types.add(curveItem); lineItem.setAccelerator(KeyStroke.getKeyStroke('L', Event.CTRL_MASK)); rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', Event.CTRL_MASK)); circleItem.setAccelerator(KeyStroke.getKeyStroke('I', Event.CTRL_MASK)); curveItem.setAccelerator(KeyStroke.getKeyStroke('V', Event.CTRL_MASK)); elementMenu.addSeparator(); elementMenu.add(colorMenu); // Add the sub-menu colorMenu.add(redItem = new JCheckBoxMenuItem("Red", false)); colorMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false)); colorMenu.add(greenItem = new JCheckBoxMenuItem("Green", false)); colorMenu.add(blueItem = new JCheckBoxMenuItem("Blue", true)); // Add element color accelerators redItem.setAccelerator(KeyStroke.getKeyStroke('R', Event.CTRL_MASK)); yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', Event.CTRL_MASK)); greenItem.setAccelerator(KeyStroke.getKeyStroke('G', Event.CTRL_MASK)); blueItem.setAccelerator(KeyStroke.getKeyStroke('B', Event.CTRL_MASK)); menuBar.add(fileMenu); menuBar.add(elementMenu); }
From source file:Main.java
public FramewithMenuShortcut() { JMenu fileMenu = new JMenu("File"); // Create File menu JMenu elementMenu = new JMenu("Elements"); // Create Elements menu fileMenu.setMnemonic('F'); // Create shortcut elementMenu.setMnemonic('E'); // Create shortcut setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);//from w ww .j a va2 s.c om newItem = fileMenu.add("New"); openItem = fileMenu.add("Open"); closeItem = fileMenu.add("Close"); fileMenu.addSeparator(); saveItem = fileMenu.add("Save"); saveAsItem = fileMenu.add("Save As..."); fileMenu.addSeparator(); printItem = fileMenu.add("Print"); elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true)); elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false)); elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false)); ButtonGroup types = new ButtonGroup(); types.add(lineItem); types.add(rectangleItem); types.add(circleItem); elementMenu.addSeparator(); elementMenu.add(redItem = new JCheckBoxMenuItem("Red", false)); elementMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false)); menuBar.add(fileMenu); menuBar.add(elementMenu); newItem.setAccelerator(KeyStroke.getKeyStroke('N', CTRL_DOWN_MASK)); openItem.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK)); saveItem.setAccelerator(KeyStroke.getKeyStroke('S', CTRL_DOWN_MASK)); printItem.setAccelerator(KeyStroke.getKeyStroke('P', CTRL_DOWN_MASK)); lineItem.setAccelerator(KeyStroke.getKeyStroke('L', CTRL_DOWN_MASK)); rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', CTRL_DOWN_MASK)); circleItem.setAccelerator(KeyStroke.getKeyStroke('I', CTRL_DOWN_MASK)); elementMenu.addSeparator(); redItem.setAccelerator(KeyStroke.getKeyStroke('R', CTRL_DOWN_MASK)); yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', CTRL_DOWN_MASK)); menuBar.add(fileMenu); menuBar.add(elementMenu); }
From source file:BorderTest.java
public BorderFrame() { setTitle("BorderTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); demoPanel = new JPanel(); buttonPanel = new JPanel(); group = new ButtonGroup(); addRadioButton("Lowered bevel", BorderFactory.createLoweredBevelBorder()); addRadioButton("Raised bevel", BorderFactory.createRaisedBevelBorder()); addRadioButton("Etched", BorderFactory.createEtchedBorder()); addRadioButton("Line", BorderFactory.createLineBorder(Color.BLUE)); addRadioButton("Matte", BorderFactory.createMatteBorder(10, 10, 10, 10, Color.BLUE)); addRadioButton("Empty", BorderFactory.createEmptyBorder()); Border etched = BorderFactory.createEtchedBorder(); Border titled = BorderFactory.createTitledBorder(etched, "Border types"); buttonPanel.setBorder(titled);/* ww w.j a v a 2 s .c om*/ setLayout(new GridLayout(2, 1)); add(buttonPanel); add(demoPanel); }
From source file:GeMSE.Visualization.BoxAndWhiskerPlot.java
/** * Creates new form BoxAndWhiskerPlot/* ww w . j a v a 2 s . co m*/ * * @param space */ public BoxAndWhiskerPlot(Space space) { initComponents(); _space = space; ButtonGroup group = new ButtonGroup(); group.add(RowsCategoryRB); group.add(ColumnsCategoryRB); RowsCategoryRB.setSelected(true); Plot(); }