📄 finddialog.java
字号:
package wapide;import java.awt.*;import javax.swing.*;import java.awt.event.*;/** * Copyright: Copyright (c) 2003 * @author Mark Busman * @version 1.0 * * For License and contact information see WAPIDE.java */public class FindDialog extends JDialog { private BorderLayout borderLayout1 = new BorderLayout(); private JPanel FindPanel = new JPanel(); private JTextField FindText = new JTextField(); private JLabel jLabel1 = new JLabel(); private JPanel ButtonPanel = new JPanel(); private JPanel jPanel3 = new JPanel(); private BorderLayout borderLayout2 = new BorderLayout(); private FlowLayout flowLayout1 = new FlowLayout(); private JButton NextButton = new JButton(); private JButton FindButton = new JButton(); private GridBagLayout gridBagLayout1 = new GridBagLayout(); /** * The pane in which searching should take place. */ private JTextPane thePane; /** * Position in pane. */ private int Pos = -1; /** * Number of times an item is found. */ private int count = 0; /** * Constructs and displays a FindDialog. */ public FindDialog(JTextPane pane) { try { thePane = pane; jbInit(); pack(); this.setResizable(true); setSize(350, 120); this.setResizable(false); show(); } catch(Exception e) { e.printStackTrace(); } } /** * Initializes the dialog components. */ private void jbInit() throws Exception { this.getContentPane().setLayout(borderLayout1); this.setResizable(false); this.setTitle("Find"); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { this_windowClosing(e); } }); jLabel1.setText("Text to find:"); jPanel3.setPreferredSize(new Dimension(105, 90)); jPanel3.setLayout(flowLayout1); ButtonPanel.setLayout(borderLayout2); NextButton.setPreferredSize(new Dimension(95, 29)); NextButton.setText("Next"); NextButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { NextButton_actionPerformed(e); } }); FindButton.setPreferredSize(new Dimension(95, 29)); FindButton.setText("Find"); FindButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { FindButton_actionPerformed(e); } }); FindPanel.setLayout(gridBagLayout1); FindPanel.setPreferredSize(new Dimension(89, 34)); FindText.setPreferredSize(new Dimension(129, 22)); FindPanel.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 195, 6)); FindPanel.add(FindText, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 1, 0), 289, 10)); this.getContentPane().add(FindPanel, BorderLayout.CENTER); this.getContentPane().add(ButtonPanel, BorderLayout.EAST); ButtonPanel.add(jPanel3, BorderLayout.NORTH); jPanel3.add(FindButton, null); jPanel3.add(NextButton, null); } /** * Performs a search for the keyword in the text pane. */ private void FindButton_actionPerformed(ActionEvent e) { Pos = -1; Pos = thePane.getText().indexOf(FindText.getText()); if (Pos > -1) { thePane.setSelectionStart(Pos); thePane.setSelectionEnd(Pos + FindText.getText().length()); } else { JOptionPane.showMessageDialog(null, "Text not found.", "Warning", JOptionPane.INFORMATION_MESSAGE); } } /** * Searches the text pane for the keyword after the initial search. */ private void NextButton_actionPerformed(ActionEvent e) { Pos = thePane.getText().indexOf(FindText.getText(), Pos + 1); if (Pos > -1) { thePane.setSelectionStart(Pos); thePane.setSelectionEnd(Pos + FindText.getText().length()); } else { Pos = -1; Pos = thePane.getText().indexOf(FindText.getText(), Pos + 1); if (Pos > -1) { thePane.setSelectionStart(Pos); thePane.setSelectionEnd(Pos + FindText.getText().length()); } else { JOptionPane.showMessageDialog(null, "Text not found.", "Warning", JOptionPane.INFORMATION_MESSAGE); } } } /** * Closes the dialog. */ private void this_windowClosing(WindowEvent e) { setVisible(false); dispose(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -