📄 textpane.java
字号:
package edu.odu.cs.zeil.AlgAE.gui;import java.awt.BorderLayout;import java.awt.Font;import java.awt.Graphics;import java.awt.Panel;import java.awt.Scrollbar;import java.awt.event.AdjustmentEvent;import java.awt.event.AdjustmentListener;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import java.awt.*;import edu.odu.cs.zeil.AlgAE.Debug;import edu.odu.cs.zeil.AlgAE.gui.ScrollableTextCanvas;/** * TextPane.java * * A GUI element that displays a sequence of text lines, with scroll bars. * The program can request that a specific line of text be highlighted * and centered within the visible area. * * This is very similar in appearance and functionality to the * java.awt.TextArea, except that there is no way to tell a TextArea * to scroll itself to a desired line. * * Created: Wed July 30, 1998 * * @author Steven Zeil * @version */public class TextPane extends Panel{ private ScrollableTextCanvas canvas; private Scrollbar horizontal; private Scrollbar vertical; public TextPane() { canvas = new ScrollableTextCanvas (this); setLayout (new BorderLayout()); add ("Center", canvas); horizontal = new Scrollbar (Scrollbar.HORIZONTAL); vertical = new Scrollbar (Scrollbar.VERTICAL); add ("East", vertical); add ("South", horizontal); horizontal.addAdjustmentListener (new AdjustmentListener() { public void adjustmentValueChanged (AdjustmentEvent e) { canvas.setStartingColumn (e.getValue()); } }); vertical.addAdjustmentListener (new AdjustmentListener() { public void adjustmentValueChanged (AdjustmentEvent e) { canvas.setStartingLine (e.getValue()); } }); addComponentListener (new ComponentAdapter() { public void componentResized (ComponentEvent c) { Debug.show (Debug.splitters, "TextPane.resized " + c); setScrolls(); } }); } private void setScrolls() { horizontal.setMinimum (0); horizontal.setMaximum (canvas.getMaxWidth()); horizontal.setVisibleAmount (canvas.getWidth()); vertical.setMinimum (0); vertical.setMaximum (canvas.getMaxHeight()+1); vertical.setVisibleAmount (canvas.getHeight()); } public synchronized void addLine (String line) { canvas.addLine (line); setScrolls(); } public synchronized void doneAdding() { canvas.doneAdding(); setScrolls(); validate(); } public synchronized void focusOnLine (int lineNumber) { canvas.focusOnLine (lineNumber); setScrolls(); vertical.setValue (canvas.getStartingLine()); repaint(); } public void setFont (Font f) { canvas.setFont (f); repaint(); } public void paint (Graphics g) { setScrolls(); super.paint(g); } } // TextPane
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -