List of usage examples for javax.swing JCheckBox JCheckBox
public JCheckBox(Action a)
From source file:Wallpaper.java
private static JPanel createPanel() { JPanel p = new JPanel(); ButtonGroup entreeGroup = new ButtonGroup(); JRadioButton radioButton;//from ww w . ja v a 2s .com p.add(radioButton = new JRadioButton("Beef", true)); entreeGroup.add(radioButton); p.add(radioButton = new JRadioButton("Chicken")); entreeGroup.add(radioButton); p.add(radioButton = new JRadioButton("Vegetable")); entreeGroup.add(radioButton); p.add(new JCheckBox("Ketchup")); p.add(new JCheckBox("Mustard")); p.add(new JCheckBox("Pickles")); p.add(new JLabel("Special requests:")); p.add(new JTextField(20)); JButton orderButton = new JButton("Place Order"); p.add(orderButton); return p; }
From source file:GlassPaneDemo.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//* w w w . j av a 2s .co m*/ private static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("GlassPaneDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Start creating and adding components. JCheckBox changeButton = new JCheckBox("Glass pane \"visible\""); changeButton.setSelected(false); // Set up the content pane, where the "main GUI" lives. Container contentPane = frame.getContentPane(); contentPane.setLayout(new FlowLayout()); contentPane.add(changeButton); contentPane.add(new JButton("Button 1")); contentPane.add(new JButton("Button 2")); // Set up the menu bar, which appears above the content pane. JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Menu"); menu.add(new JMenuItem("Do nothing")); menuBar.add(menu); frame.setJMenuBar(menuBar); // Set up the glass pane, which appears over both menu bar // and content pane and is an item listener on the change // button. myGlassPane = new MyGlassPane(changeButton, menuBar, frame.getContentPane()); changeButton.addItemListener(myGlassPane); frame.setGlassPane(myGlassPane); // Show the window. frame.pack(); frame.setVisible(true); }
From source file:EditorPaneExample10A.java
public EditorPaneExample10A() { super("JEditorPane Example 10 - using getIterator"); pane = new JEditorPane(); pane.setEditable(false); // 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 .j a va2 s .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("URL: ", 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.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); try { // Check if the new page and the old // page are the same. URL url; if (selection instanceof URL) { url = (URL) selection; } else { url = new URL((String) selection); } URL loadedURL = pane.getPage(); if (loadedURL != null && loadedURL.sameFile(url)) { return; } // Try to display the page urlCombo.setEnabled(false); // Disable input urlCombo.paintImmediately(0, 0, urlCombo.getSize().width, urlCombo.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); timeLabel.setText(""); timeLabel.paintImmediately(0, 0, timeLabel.getSize().width, timeLabel.getSize().height); startTime = System.currentTimeMillis(); // Choose the loading method if (onlineLoad.isSelected()) { // Usual load via setPage pane.setPage(url); loadedType.setText(pane.getContentType()); } else { pane.setContentType("text/html"); loadedType.setText(pane.getContentType()); if (loader == null) { loader = new HTMLDocumentLoader(); } HTMLDocument doc = loader.loadDocument(url); loadComplete(); pane.setDocument(doc); displayLoadTime(); populateCombo(findLinks(doc, null)); enableInput(); } } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", selection.toString() }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); enableInput(); } } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); enableInput(); } } }); }
From source file:layout.Find.java
public Find() { JLabel label = new JLabel("Find What:"); ;//from w w w . j a v a 2s. co m JTextField textField = new JTextField(); JCheckBox caseCheckBox = new JCheckBox("Match Case"); JCheckBox wrapCheckBox = new JCheckBox("Wrap Around"); JCheckBox wholeCheckBox = new JCheckBox("Whole Words"); JCheckBox backCheckBox = new JCheckBox("Search Backwards"); JButton findButton = new JButton("Find"); JButton cancelButton = new JButton("Cancel"); // remove redundant default border of check boxes - they would hinder // correct spacing and aligning (maybe not needed on some look and feels) caseCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); wrapCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); wholeCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); backCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(label) .addGroup(layout.createParallelGroup(LEADING).addComponent(textField) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(LEADING).addComponent(caseCheckBox) .addComponent(wholeCheckBox)) .addGroup(layout.createParallelGroup(LEADING).addComponent(wrapCheckBox) .addComponent(backCheckBox)))) .addGroup(layout.createParallelGroup(LEADING).addComponent(findButton).addComponent(cancelButton))); layout.linkSize(SwingConstants.HORIZONTAL, findButton, cancelButton); layout.setVerticalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE).addComponent(label).addComponent(textField) .addComponent(findButton)) .addGroup(layout.createParallelGroup(LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE).addComponent(caseCheckBox) .addComponent(wrapCheckBox)) .addGroup(layout.createParallelGroup(BASELINE).addComponent(wholeCheckBox) .addComponent(backCheckBox))) .addComponent(cancelButton))); setTitle("Find"); pack(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }
From source file:lookandfeel.SynthDialog.java
public SynthDialog() { JLabel label = new JLabel("Find What:"); ;/* w w w. jav a 2s . com*/ JTextField textField = new JTextField(); JCheckBox caseCheckBox = new JCheckBox("Match Case"); JCheckBox wrapCheckBox = new JCheckBox("Wrap Around"); JCheckBox wholeCheckBox = new JCheckBox("Whole Words"); JCheckBox backCheckBox = new JCheckBox("Search Backwards"); JButton findButton = new JButton("Find"); JButton cancelButton = new JButton("Cancel"); // remove redundant default border of check boxes - they would hinder // correct spacing and aligning (maybe not needed on some look and feels) caseCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); wrapCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); wholeCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); backCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(label) .addGroup(layout.createParallelGroup(LEADING).addComponent(textField) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(LEADING).addComponent(caseCheckBox) .addComponent(wholeCheckBox)) .addGroup(layout.createParallelGroup(LEADING).addComponent(wrapCheckBox) .addComponent(backCheckBox)))) .addGroup(layout.createParallelGroup(LEADING).addComponent(findButton).addComponent(cancelButton))); layout.linkSize(SwingConstants.HORIZONTAL, findButton, cancelButton); layout.setVerticalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE).addComponent(label).addComponent(textField) .addComponent(findButton)) .addGroup(layout.createParallelGroup(LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE).addComponent(caseCheckBox) .addComponent(wrapCheckBox)) .addGroup(layout.createParallelGroup(BASELINE).addComponent(wholeCheckBox) .addComponent(backCheckBox))) .addComponent(cancelButton))); setTitle("Find"); pack(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }
From source file:lookandfeel.SynthDialog.java
public SynthDialog() { JLabel label = new JLabel("Find What:");; JTextField textField = new JTextField(); JCheckBox caseCheckBox = new JCheckBox("Match Case"); JCheckBox wrapCheckBox = new JCheckBox("Wrap Around"); JCheckBox wholeCheckBox = new JCheckBox("Whole Words"); JCheckBox backCheckBox = new JCheckBox("Search Backwards"); JButton findButton = new JButton("Find"); JButton cancelButton = new JButton("Cancel"); // remove redundant default border of check boxes - they would hinder // correct spacing and aligning (maybe not needed on some look and feels) caseCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); wrapCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); wholeCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); backCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout);/* w w w . ja v a 2 s . c o m*/ layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addComponent(label) .addGroup(layout.createParallelGroup(LEADING) .addComponent(textField) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(LEADING) .addComponent(caseCheckBox) .addComponent(wholeCheckBox)) .addGroup(layout.createParallelGroup(LEADING) .addComponent(wrapCheckBox) .addComponent(backCheckBox)))) .addGroup(layout.createParallelGroup(LEADING) .addComponent(findButton) .addComponent(cancelButton)) ); layout.linkSize(SwingConstants.HORIZONTAL, findButton, cancelButton); layout.setVerticalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE) .addComponent(label) .addComponent(textField) .addComponent(findButton)) .addGroup(layout.createParallelGroup(LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE) .addComponent(caseCheckBox) .addComponent(wrapCheckBox)) .addGroup(layout.createParallelGroup(BASELINE) .addComponent(wholeCheckBox) .addComponent(backCheckBox))) .addComponent(cancelButton)) ); setTitle("Find"); pack(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }
From source file:org.jfree.chart.demo.CategoryLabelPositionsDemo1.java
public static JPanel createDemoPanel() { CategoryDataset categorydataset = createDataset(); chart = createChart(categorydataset); JPanel jpanel = new JPanel(new BorderLayout()); JPanel jpanel1 = new JPanel(new BorderLayout()); JPanel jpanel2 = new JPanel(); invertCheckBox = new JCheckBox("Invert Range Axis?"); invertCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionevent) { CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot(); categoryplot.getRangeAxis().setInverted(CategoryLabelPositionsDemo1.invertCheckBox.isSelected()); }//from w w w.j a v a 2s . c o m }); jpanel2.add(invertCheckBox); ButtonGroup buttongroup = new ButtonGroup(); horizontalRadioButton = new JRadioButton("Horizontal", false); horizontalRadioButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionevent) { if (CategoryLabelPositionsDemo1.horizontalRadioButton.isSelected()) { CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot(); categoryplot.setOrientation(PlotOrientation.HORIZONTAL); } } }); buttongroup.add(horizontalRadioButton); verticalRadioButton = new JRadioButton("Vertical", true); verticalRadioButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionevent) { if (CategoryLabelPositionsDemo1.verticalRadioButton.isSelected()) { CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot(); categoryplot.setOrientation(PlotOrientation.VERTICAL); } } }); buttongroup.add(verticalRadioButton); jpanel2.add(horizontalRadioButton); jpanel2.add(verticalRadioButton); jpanel2.setBorder(new TitledBorder("Plot Settings: ")); JPanel jpanel3 = new JPanel(new BorderLayout()); slider = new JSlider(0, 90, 45); slider.setMajorTickSpacing(10); slider.setMinorTickSpacing(5); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent changeevent) { CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions( ((double) CategoryLabelPositionsDemo1.slider.getValue() * 3.1415926535897931D) / 180D)); } }); jpanel3.add(slider); jpanel3.setBorder(new TitledBorder("Axis Label Rotation Angle:")); jpanel1.add("North", jpanel2); jpanel1.add(jpanel3); jpanel.add(new ChartPanel(chart)); jpanel.add("South", jpanel1); return jpanel; }
From source file:ja.lingo.application.gui.main.settings.appearance.AppearanceGui.java
public AppearanceGui(Model model) { model.addApplicationModelListener(new ModelAdapter() { public void settingsUpdated(Preferences preferences) { setSelectedFontSize(preferences.getFontSize()); setSelectedFontFace(preferences.getFontFace()); dropZoneCheckBox.setSelected(preferences.isDropZoneVisible()); memoryBarCheckBox.setSelected(preferences.isMemoryBarVisible()); }/*from w w w. j a va 2s . c o m*/ }); dropZoneCheckBox = new JCheckBox(resources.text("showDropZone")); fontSizeComboBox = new JComboBox(new Integer[] { 12, 13, DEFAULT_FONT_SIZE, 15, 16, 17 }); memoryBarCheckBox = new JCheckBox(resources.text("showMemoryBar")); JPanel fontSizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Gaps.GAP5, 0)); fontSizePanel.add(resources.label("fontSize")); fontSizePanel.add(fontSizeComboBox); fontSizePanel.add(resources.label("requiresRestart")); gui = new JPanel(new TableLayout(new double[][] { { TableLayout.PREFERRED }, { TableLayout.PREFERRED, // 0: font face Gaps.GAP5, TableLayout.PREFERRED, // 2: font size Gaps.GAP5, TableLayout.PREFERRED, // 4: drop-zone Gaps.GAP5, TableLayout.PREFERRED, // 6: memory bar } })); JPanel fontFacePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Gaps.GAP5, 0)); fontFacePanel.add(resources.label("fontFace")); GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); fontFaceComboBox = new JComboBox(gEnv.getAvailableFontFamilyNames()); fontFaceComboBox.setMaximumRowCount(10); fontFacePanel.add(fontFaceComboBox); fontFacePanel.add(resources.label("requiresRestart")); gui.add(fontFacePanel, "0, 0"); gui.add(fontSizePanel, "0, 2"); gui.add(dropZoneCheckBox, "0, 4"); gui.add(memoryBarCheckBox, "0, 6"); Gaps.applyBorder5(gui); ActionBinder.bind(this); }
From source file:Main.java
public ProgressBarFrame() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // this text area holds the activity output textArea = new JTextArea(); // set up panel with button and progress bar final int MAX = 1000; JPanel panel = new JPanel(); startButton = new JButton("Start"); progressBar = new JProgressBar(0, MAX); progressBar.setStringPainted(true);/*w w w. j a v a 2 s.c om*/ panel.add(startButton); panel.add(progressBar); checkBox = new JCheckBox("indeterminate"); checkBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { progressBar.setIndeterminate(checkBox.isSelected()); progressBar.setStringPainted(!progressBar.isIndeterminate()); } }); panel.add(checkBox); add(new JScrollPane(textArea), BorderLayout.CENTER); add(panel, BorderLayout.SOUTH); // set up the button action startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { startButton.setEnabled(false); activity = new SimulatedActivity(MAX); activity.execute(); } }); }
From source file:GroupLayoutTest.java
public FontFrame() { setTitle("GroupLayoutTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); ActionListener listener = new FontAction(); // construct components JLabel faceLabel = new JLabel("Face: "); face = new JComboBox(new String[] { "Serif", "SansSerif", "Monospaced", "Dialog", "DialogInput" }); face.addActionListener(listener);/*from www.j a v a 2s . co m*/ JLabel sizeLabel = new JLabel("Size: "); size = new JComboBox(new String[] { "8", "10", "12", "15", "18", "24", "36", "48" }); size.addActionListener(listener); bold = new JCheckBox("Bold"); bold.addActionListener(listener); italic = new JCheckBox("Italic"); italic.addActionListener(listener); sample = new JTextArea(); sample.setText("The quick brown fox jumps over the lazy dog"); sample.setEditable(false); sample.setLineWrap(true); sample.setBorder(BorderFactory.createEtchedBorder()); pane = new JScrollPane(sample); GroupLayout layout = new GroupLayout(getContentPane()); setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING) .addComponent(faceLabel).addComponent(sizeLabel)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false) .addComponent(size).addComponent(face))) .addComponent(italic).addComponent(bold)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(pane) .addContainerGap())); layout.linkSize(SwingConstants.HORIZONTAL, new java.awt.Component[] { face, size }); layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(pane, GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(face).addComponent(faceLabel)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(size).addComponent(sizeLabel)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(italic, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(bold, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addContainerGap())); }