List of usage examples for javax.swing JCheckBox JCheckBox
public JCheckBox(Action a)
From source file:FontPicker.java
public FontChooser(Frame parent) { super(parent, "Font Chooser", true); setSize(450, 450);/*from w ww . j ava2s . c om*/ attributes = new SimpleAttributeSet(); // Make sure that any way the user cancels the window does the right // thing addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { closeAndCancel(); } }); // Start the long process of setting up our interface Container c = getContentPane(); JPanel fontPanel = new JPanel(); fontName = new JComboBox(new String[] { "TimesRoman", "Helvetica", "Courier" }); fontName.setSelectedIndex(1); fontName.addActionListener(this); fontSize = new JTextField("12", 4); fontSize.setHorizontalAlignment(SwingConstants.RIGHT); fontSize.addActionListener(this); fontBold = new JCheckBox("Bold"); fontBold.setSelected(true); fontBold.addActionListener(this); fontItalic = new JCheckBox("Italic"); fontItalic.addActionListener(this); fontPanel.add(fontName); fontPanel.add(new JLabel(" Size: ")); fontPanel.add(fontSize); fontPanel.add(fontBold); fontPanel.add(fontItalic); c.add(fontPanel, BorderLayout.NORTH); // Set up the color chooser panel and attach a change listener so that // color // updates get reflected in our preview label. colorChooser = new JColorChooser(Color.black); colorChooser.getSelectionModel().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { updatePreviewColor(); } }); c.add(colorChooser, BorderLayout.CENTER); JPanel previewPanel = new JPanel(new BorderLayout()); previewLabel = new JLabel("Here's a sample of this font."); previewLabel.setForeground(colorChooser.getColor()); previewPanel.add(previewLabel, BorderLayout.CENTER); // Add in the Ok and Cancel buttons for our dialog box JButton okButton = new JButton("Ok"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { closeAndSave(); } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { closeAndCancel(); } }); JPanel controlPanel = new JPanel(); controlPanel.add(okButton); controlPanel.add(cancelButton); previewPanel.add(controlPanel, BorderLayout.SOUTH); // Give the preview label room to grow. previewPanel.setMinimumSize(new Dimension(100, 100)); previewPanel.setPreferredSize(new Dimension(100, 100)); c.add(previewPanel, BorderLayout.SOUTH); }
From source file:com.sshtools.common.ui.SshToolsConnectionKerberosTab.java
/** * Creates a new SshToolsConnectionKerberosTab object. *//* ww w .j av a 2 s . c o m*/ public SshToolsConnectionKerberosTab() { super(); // Create the main connection details panel JPanel mainConnectionDetailsPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.insets = new Insets(0, 2, 2, 2); // enabled option //gbc.fill = GridBagConstraints.NONE; useKerberos = new JCheckBox("Use MyProxy Kerberos support"); UIUtil.jGridBagAdd(mainConnectionDetailsPanel, useKerberos, gbc, GridBagConstraints.REMAINDER); // Host name UIUtil.jGridBagAdd(mainConnectionDetailsPanel, new JLabel("Hostname"), gbc, GridBagConstraints.REMAINDER); //gbc.fill = GridBagConstraints.HORIZONTAL; UIUtil.jGridBagAdd(mainConnectionDetailsPanel, jTextHostname, gbc, GridBagConstraints.REMAINDER); //gbc.fill = GridBagConstraints.NONE; // Username UIUtil.jGridBagAdd(mainConnectionDetailsPanel, new JLabel("Username"), gbc, GridBagConstraints.REMAINDER); //gbc.fill = GridBagConstraints.HORIZONTAL; UIUtil.jGridBagAdd(mainConnectionDetailsPanel, jTextUsername, gbc, GridBagConstraints.REMAINDER); JPanel settingsPanel = new JPanel(new GridBagLayout()); settingsPanel .setBorder(BorderFactory.createTitledBorder("Settings if krb5.conf or krb5.ini file not found: ")); GridBagConstraints gbc2 = new GridBagConstraints(); gbc2.fill = GridBagConstraints.HORIZONTAL; gbc2.anchor = GridBagConstraints.NORTHWEST; gbc2.insets = new Insets(0, 2, 2, 2); gbc2.weightx = 1.0; // realm UIUtil.jGridBagAdd(settingsPanel, new JLabel("Realm"), gbc2, GridBagConstraints.REMAINDER); gbc2.fill = GridBagConstraints.HORIZONTAL; UIUtil.jGridBagAdd(settingsPanel, jTextRealm, gbc2, GridBagConstraints.REMAINDER); gbc2.fill = GridBagConstraints.NONE; // kdc UIUtil.jGridBagAdd(settingsPanel, new JLabel("KDC"), gbc2, GridBagConstraints.REMAINDER); gbc2.fill = GridBagConstraints.HORIZONTAL; gbc2.weighty = 1.0; UIUtil.jGridBagAdd(settingsPanel, jTextKDC, gbc2, GridBagConstraints.REMAINDER); gbc2.fill = GridBagConstraints.NONE; // gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.insets = new Insets(4, 2, 2, 2); UIUtil.jGridBagAdd(mainConnectionDetailsPanel, settingsPanel, gbc, GridBagConstraints.REMAINDER); IconWrapperPanel iconMainConnectionDetailsPanel = new IconWrapperPanel( new ResourceIcon(SshToolsConnectionHostTab.class, AUTH_ICON), mainConnectionDetailsPanel); setLayout(new GridBagLayout()); setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(2, 2, 2, 2); gbc.weightx = 1.0; gbc.weighty = 1.0; UIUtil.jGridBagAdd(this, iconMainConnectionDetailsPanel, gbc, GridBagConstraints.REMAINDER); }
From source file:EditorPaneExample11.java
public EditorPaneExample11() { super("JEditorPane Example 11"); 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 av a 2 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"); // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // 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); // Display an empty tree while loading tree.setModel(emptyModel); tree.paintImmediately(0, 0, tree.getSize().width, tree.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)); TreeNode node = buildHeadingTree(doc); tree.setModel(new DefaultTreeModel(node)); 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)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); }
From source file:LicenseGenerator.java
/** * Initialize the contents of the frame. *//*from w w w . j a v a 2 s . co m*/ private void initialize() { try { UIManager.setLookAndFeel(new WindowsLookAndFeel()); } catch (UnsupportedLookAndFeelException ex) { } m_frame = new JFrame(); m_frame.setTitle("License?"); m_frame.setResizable(false); m_frame.setBounds(100, 100, 496, 483); m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); m_frame.getContentPane().setLayout(null); chkDate = new JCheckBox("?"); chkDate.setSelected(true); chkDate.setBounds(6, 6, 103, 23); m_frame.getContentPane().add(chkDate); txtDate = new JTextField(); txtDate.setText("20131231"); txtDate.setHorizontalAlignment(SwingConstants.RIGHT); txtDate.setBounds(131, 7, 193, 21); m_frame.getContentPane().add(txtDate); txtDate.setColumns(10); chkAdapterNum = new JCheckBox("???"); chkAdapterNum.setSelected(true); chkAdapterNum.setBounds(6, 37, 119, 23); m_frame.getContentPane().add(chkAdapterNum); txtAdapterNum = new JTextField(); txtAdapterNum.setText("000012"); txtAdapterNum.setHorizontalAlignment(SwingConstants.RIGHT); txtAdapterNum.setColumns(10); txtAdapterNum.setBounds(131, 38, 193, 21); m_frame.getContentPane().add(txtAdapterNum); chkAdapter = new JCheckBox( "??? (?? ???)"); chkAdapter.setSelected(true); chkAdapter.setBounds(6, 76, 465, 23); m_frame.getContentPane().add(chkAdapter); chkHTTP_C = new JCheckBox("http.c"); chkHTTP_C.setSelected(true); chkHTTP_C.setBounds(43, 130, 76, 23); m_frame.getContentPane().add(chkHTTP_C); txtHTTP_C = new JTextField(); txtHTTP_C.setText("20131231"); txtHTTP_C.setHorizontalAlignment(SwingConstants.RIGHT); txtHTTP_C.setBounds(131, 131, 103, 21); m_frame.getContentPane().add(txtHTTP_C); txtHTTP_C.setColumns(10); chkSOAP_C = new JCheckBox("soap.c"); chkSOAP_C.setSelected(true); chkSOAP_C.setBounds(43, 161, 76, 23); m_frame.getContentPane().add(chkSOAP_C); txtSOAP_C = new JTextField(); txtSOAP_C.setText("20131231"); txtSOAP_C.setHorizontalAlignment(SwingConstants.RIGHT); txtSOAP_C.setColumns(10); txtSOAP_C.setBounds(131, 162, 103, 21); m_frame.getContentPane().add(txtSOAP_C); chkTCP_C = new JCheckBox("tcp.c"); chkTCP_C.setSelected(true); chkTCP_C.setBounds(43, 192, 76, 23); m_frame.getContentPane().add(chkTCP_C); txtTCP_C = new JTextField(); txtTCP_C.setText("20131231"); txtTCP_C.setHorizontalAlignment(SwingConstants.RIGHT); txtTCP_C.setColumns(10); txtTCP_C.setBounds(131, 193, 103, 21); m_frame.getContentPane().add(txtTCP_C); chkUDP_C = new JCheckBox("udp.c"); chkUDP_C.setSelected(true); chkUDP_C.setBounds(43, 223, 76, 23); m_frame.getContentPane().add(chkUDP_C); txtUDP_C = new JTextField(); txtUDP_C.setText("20131231"); txtUDP_C.setHorizontalAlignment(SwingConstants.RIGHT); txtUDP_C.setColumns(10); txtUDP_C.setBounds(131, 224, 103, 21); m_frame.getContentPane().add(txtUDP_C); chkTUXEDO_C = new JCheckBox("tuxedo.c"); chkTUXEDO_C.setSelected(true); chkTUXEDO_C.setBounds(43, 254, 76, 23); m_frame.getContentPane().add(chkTUXEDO_C); txtTUXEDO_C = new JTextField(); txtTUXEDO_C.setText("20131231"); txtTUXEDO_C.setHorizontalAlignment(SwingConstants.RIGHT); txtTUXEDO_C.setColumns(10); txtTUXEDO_C.setBounds(131, 255, 103, 21); m_frame.getContentPane().add(txtTUXEDO_C); chkMQ_C = new JCheckBox("mq.c"); chkMQ_C.setSelected(true); chkMQ_C.setBounds(43, 286, 76, 23); m_frame.getContentPane().add(chkMQ_C); txtMQ_C = new JTextField(); txtMQ_C.setText("20131231"); txtMQ_C.setHorizontalAlignment(SwingConstants.RIGHT); txtMQ_C.setColumns(10); txtMQ_C.setBounds(131, 287, 103, 21); m_frame.getContentPane().add(txtMQ_C); chkHTTP_S = new JCheckBox("http.s"); chkHTTP_S.setSelected(true); chkHTTP_S.setBounds(283, 130, 76, 23); m_frame.getContentPane().add(chkHTTP_S); txtHTTP_S = new JTextField(); txtHTTP_S.setText("20131231"); txtHTTP_S.setHorizontalAlignment(SwingConstants.RIGHT); txtHTTP_S.setColumns(10); txtHTTP_S.setBounds(368, 130, 103, 21); m_frame.getContentPane().add(txtHTTP_S); chkSOAP_S = new JCheckBox("soap.s"); chkSOAP_S.setSelected(true); chkSOAP_S.setBounds(283, 161, 76, 23); m_frame.getContentPane().add(chkSOAP_S); txtSOAP_S = new JTextField(); txtSOAP_S.setText("20131231"); txtSOAP_S.setHorizontalAlignment(SwingConstants.RIGHT); txtSOAP_S.setColumns(10); txtSOAP_S.setBounds(368, 161, 103, 21); m_frame.getContentPane().add(txtSOAP_S); chkTCP_S = new JCheckBox("tcp.s"); chkTCP_S.setSelected(true); chkTCP_S.setBounds(283, 192, 76, 23); m_frame.getContentPane().add(chkTCP_S); txtTCP_S = new JTextField(); txtTCP_S.setText("20131231"); txtTCP_S.setHorizontalAlignment(SwingConstants.RIGHT); txtTCP_S.setColumns(10); txtTCP_S.setBounds(368, 192, 103, 21); m_frame.getContentPane().add(txtTCP_S); chkUDP_S = new JCheckBox("udp.s"); chkUDP_S.setSelected(true); chkUDP_S.setBounds(283, 223, 76, 23); m_frame.getContentPane().add(chkUDP_S); txtUDP_S = new JTextField(); txtUDP_S.setText("20131231"); txtUDP_S.setHorizontalAlignment(SwingConstants.RIGHT); txtUDP_S.setColumns(10); txtUDP_S.setBounds(368, 223, 103, 21); m_frame.getContentPane().add(txtUDP_S); chkTUXEDO_S = new JCheckBox("tuxedo.s"); chkTUXEDO_S.setSelected(true); chkTUXEDO_S.setBounds(283, 254, 76, 23); m_frame.getContentPane().add(chkTUXEDO_S); txtTUXEDO_S = new JTextField(); txtTUXEDO_S.setText("20131231"); txtTUXEDO_S.setHorizontalAlignment(SwingConstants.RIGHT); txtTUXEDO_S.setColumns(10); txtTUXEDO_S.setBounds(368, 254, 103, 21); m_frame.getContentPane().add(txtTUXEDO_S); chkMQ_S = new JCheckBox("mq.s"); chkMQ_S.setSelected(true); chkMQ_S.setBounds(283, 286, 76, 23); m_frame.getContentPane().add(chkMQ_S); txtMQ_S = new JTextField(); txtMQ_S.setText("20131231"); txtMQ_S.setHorizontalAlignment(SwingConstants.RIGHT); txtMQ_S.setColumns(10); txtMQ_S.setBounds(368, 286, 103, 21); m_frame.getContentPane().add(txtMQ_S); JLabel lblAdapterType1 = new JLabel("???"); lblAdapterType1.setBounds(43, 105, 115, 15); m_frame.getContentPane().add(lblAdapterType1); JLabel lblAdapterType2 = new JLabel("??"); lblAdapterType2.setBounds(283, 105, 103, 15); m_frame.getContentPane().add(lblAdapterType2); JLabel lblAdapterDate1 = new JLabel("?"); lblAdapterDate1.setHorizontalAlignment(SwingConstants.RIGHT); lblAdapterDate1.setBounds(168, 106, 66, 15); m_frame.getContentPane().add(lblAdapterDate1); JLabel lblAdapterDate2 = new JLabel("?"); lblAdapterDate2.setHorizontalAlignment(SwingConstants.RIGHT); lblAdapterDate2.setBounds(405, 105, 66, 15); m_frame.getContentPane().add(lblAdapterDate2); JButton cmdLicense = new JButton("?license"); cmdLicense.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cmdLicense_click(e); } }); cmdLicense.setBounds(302, 332, 169, 23); m_frame.getContentPane().add(cmdLicense); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(6, 367, 478, 82); m_frame.getContentPane().add(scrollPane); txtLicense = new JTextArea(); txtLicense.setEditable(false); scrollPane.setViewportView(txtLicense); }
From source file:DragColorDemo.java
public DragColorDemo() { super(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); JColorChooser chooser = new JColorChooser(); chooser.setDragEnabled(true);/*from w ww. j av a 2s . c o m*/ add(chooser, BorderLayout.PAGE_START); //Create the color transfer handler. colorHandler = new ColorTransferHandler(); //Create a matrix of 9 buttons. JPanel buttonPanel = new JPanel(new GridLayout(3, 3)); for (int i = 0; i < 9; i++) { JButton tmp = new JButton("Button " + i); tmp.setTransferHandler(colorHandler); buttonPanel.add(tmp); } add(buttonPanel, BorderLayout.CENTER); //Create a check box. toggleForeground = new JCheckBox("Change the foreground color."); toggleForeground.setSelected(true); toggleForeground.addActionListener(this); JPanel textPanel = new JPanel(new BorderLayout()); textPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); textPanel.add(toggleForeground, BorderLayout.PAGE_START); //Create a label. JLabel label = new JLabel("Change the color of any button or this label by dropping a color."); label.setTransferHandler(colorHandler); label.setOpaque(true); //So the background color can be changed. textPanel.add(label, BorderLayout.PAGE_END); add(textPanel, BorderLayout.PAGE_END); }
From source file:EditorPaneExample12.java
public EditorPaneExample12() { super("JEditorPane Example 12"); 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;//www . j a v a 2 s. co 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"); // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // 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)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:EditorPaneExample16.java
public EditorPaneExample16() { super("JEditorPane Example 16"); pane = new JEditorPane(); pane.setEditable(true); // Editable 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 ww w .j a v a2s . co 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.gridy = 5; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; editableBox = new JCheckBox("Editable JEditorPane"); panel.add(editableBox, c); editableBox.setSelected(true); editableBox.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"); // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Change editability based on the checkbox editableBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editableBox.isSelected()); pane.revalidate(); pane.repaint(); } }); // 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)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:EditorPaneExample15.java
public EditorPaneExample15() { super("JEditorPane Example 15"); 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;// w w w. j av a 2 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"); // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // 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)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:EditorPaneExample17.java
public EditorPaneExample17() { super("JEditorPane Example 17"); pane = new JEditorPane(); pane.setEditable(true); // Editable 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 www .ja va 2 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.gridy = 5; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; editableBox = new JCheckBox("Editable JEditorPane"); panel.add(editableBox, c); editableBox.setSelected(true); editableBox.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"); // Register a custom EditorKit for HTML ClassLoader loader = getClass().getClassLoader(); if (loader != null) { // Java 2 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit", loader); } else { // JDK 1.1 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit"); } // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Change editability based on the checkbox editableBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editableBox.isSelected()); pane.revalidate(); pane.repaint(); } }); // 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)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:SwingCheckBoxDemo.java
public SwingCheckBoxDemo() { super(new BorderLayout()); //Create the check boxes. chinButton = new JCheckBox("Chin"); chinButton.setMnemonic(KeyEvent.VK_C); chinButton.setSelected(true);/* w w w . j a v a 2s.c om*/ glassesButton = new JCheckBox("Glasses"); glassesButton.setMnemonic(KeyEvent.VK_G); glassesButton.setSelected(true); hairButton = new JCheckBox("Hair"); hairButton.setMnemonic(KeyEvent.VK_H); hairButton.setSelected(true); teethButton = new JCheckBox("Teeth"); teethButton.setMnemonic(KeyEvent.VK_T); teethButton.setSelected(true); //Register a listener for the check boxes. chinButton.addItemListener(this); glassesButton.addItemListener(this); hairButton.addItemListener(this); teethButton.addItemListener(this); //Indicates what's on the geek. choices = new StringBuffer("cght"); //Set up the picture label pictureLabel = new JLabel(); pictureLabel.setFont(pictureLabel.getFont().deriveFont(Font.ITALIC)); updatePicture(); /*Put the check boxes in a column in a panel*/ JPanel checkPanel = new JPanel(new GridLayout(0, 1)); checkPanel.add(chinButton); checkPanel.add(glassesButton); checkPanel.add(hairButton); checkPanel.add(teethButton); add(checkPanel, BorderLayout.LINE_START); add(pictureLabel, BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }