📄 toolbarexample4.java
字号:
package JFCBook.Chapter6.jdk13;
import javax.swing.*;
import javax.swing.plaf.basic.BasicToolBarUI;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import JFCBook.Chapter6.NullAction;
public class ToolBarExample4 extends JFrame {
public ToolBarExample4(String title) {
super(title);
JToolBar toolBar = new JToolBar("Editing Tools");
toolBar.setMargin(new Insets(8, 12, 8, 12));
addActions(toolBar);
// Set various floating control attributes:
if (toolBar.getUI() instanceof BasicToolBarUI) {
BasicToolBarUI ui = (BasicToolBarUI)(toolBar.getUI());
ui.setDockingColor(Color.orange);
ui.setFloatingColor(Color.green);
toolBar.setFloatable(true);
}
JTextArea textArea = new JTextArea(10, 40);
Container cp = this.getContentPane();
cp.add(toolBar, BorderLayout.NORTH); // Put the toolbar at the top
cp.add(new JScrollPane(textArea), BorderLayout.CENTER); // Text area gets the rest
}
public void addActions(JToolBar toolBar) {
toolBar.add(newAction);
toolBar.add(openAction);
toolBar.add(saveAction);
toolBar.add(copyAction);
toolBar.add(cutAction);
toolBar.add(pasteAction);
}
public static void main(String[] args) {
JFrame f = new ToolBarExample4("Toolbar Example 4");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
f.pack();
f.setVisible(true);
}
static Class thisClass = ToolBarExample4.class;
static Action newAction = new NullAction("New", new ImageIcon(thisClass.getResource("images/new.gif")));
static Action openAction = new NullAction("Open", new ImageIcon(thisClass.getResource("images/open.gif")));
static Action saveAction = new NullAction("Save", new ImageIcon(thisClass.getResource("images/save.gif")));
static Action copyAction = new NullAction("Copy", new ImageIcon(thisClass.getResource("images/copy.gif")));
static Action cutAction = new NullAction("Cut", new ImageIcon(thisClass.getResource("images/cut.gif")));
static Action pasteAction = new NullAction("Paste", new ImageIcon(thisClass.getResource("images/paste.gif")));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -