📄 toolbartest.java
字号:
package flow.graph.app;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JRadioButton;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.ImageIcon;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import com.jgoodies.looks.Options;
import com.jgoodies.looks.demo.Settings;
import com.jgoodies.looks.plastic.PlasticLookAndFeel;
import flow.graph.gui.tools.JButtonGroup;
import flow.graph.gui.tools.SelectButton;
import flow.graph.gui.tools.SimpleButton;
import flow.graph.gui.tree.ServerTreeView;
import flow.graph.test.JSelectButton;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class ToolBarTest extends JFrame
{
public ToolBarTest(){
super("多级菜单测试");
configureUI();
setSize(500,350);
getContentPane().setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
//new GetToolBar(this.getRootPane());
createToolBar();
this.setVisible(true);
}
public static void main(String[] args){
new ToolBarTest();
}
public void createToolBar(){
JToolBar toolBar = new JToolBar();
toolBar.setFloatable(true);
toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));
SimpleButton sb = new SimpleButton(new ImageIcon(FlowManager.class.getResource("images/copy.gif")));
sb.setToolTipText("copy");
sb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("sb");
}});
toolBar.add(sb);
SelectButton sb1 = new SelectButton(new ImageIcon(FlowManager.class.getResource("images/new.gif")));
sb1.setToolTipText("new");
sb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("sb1");
}});
toolBar.add(sb1);
toolBar.addSeparator();
SelectButton sb2 = new SelectButton(new ImageIcon(FlowManager.class.getResource("images/cut.gif")));
sb2.setToolTipText("cut");
sb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("sb2");
}});
toolBar.add(sb2);
SelectButton sb3 = new SelectButton(new ImageIcon(FlowManager.class.getResource("images/find.gif")));
sb3.setToolTipText("cut");
sb3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("sb3");
}});
toolBar.add(sb3);
SelectButton sb4 = new SelectButton(new ImageIcon(FlowManager.class.getResource("images/save.gif")));
sb4.setToolTipText("cut");
sb4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("sb4");
}});
toolBar.add(sb4);
SelectButton sb5 = new SelectButton(new ImageIcon(FlowManager.class.getResource("images/print.gif")));
sb5.setToolTipText("cut");
sb5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("sb5");
}});
toolBar.add(sb5);
toolBar.addSeparator();
SelectButton sb6 = new SelectButton(new ImageIcon(FlowManager.class.getResource("images/next.gif")));
sb6.setToolTipText("cut");
sb6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("sb6");
}});
toolBar.add(sb6);
SelectButton sb7 = new SelectButton(new ImageIcon(FlowManager.class.getResource("images/tips.gif")));
sb7.setToolTipText("cut");
sb7.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("sb7");
//System.exit(0);
}});
toolBar.add(sb7);
JButtonGroup bg = new JButtonGroup();
bg.add(sb1);
bg.add(sb2);
bg.add(sb3);
bg.add(sb4);
bg.add(sb5);
JButtonGroup bg2 = new JButtonGroup();
bg2.add(sb6);
bg2.add(sb7);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(toolBar, BorderLayout.NORTH);
}
public void configureUI(){
Settings settings = Settings.createDefault();
Options.setDefaultIconSize(new Dimension(18, 18));
Options.setUseNarrowButtons(settings.isUseNarrowButtons());
// Global options
Options.setTabIconsEnabled(settings.isTabIconsEnabled());
UIManager.put(Options.POPUP_DROP_SHADOW_ENABLED_KEY,
settings.isPopupDropShadowEnabled());
// Swing Settings
LookAndFeel selectedLaf = settings.getSelectedLookAndFeel();
if (selectedLaf instanceof PlasticLookAndFeel) {
PlasticLookAndFeel.setPlasticTheme(settings.getSelectedTheme());
PlasticLookAndFeel.setTabStyle(settings.getPlasticTabStyle());
PlasticLookAndFeel.setHighContrastFocusColorsEnabled(
settings.isPlasticHighContrastFocusEnabled());
} else if (selectedLaf.getClass() == MetalLookAndFeel.class) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
}
// Work around caching in MetalRadioButtonUI
JRadioButton radio = new JRadioButton();
radio.getUI().uninstallUI(radio);
JCheckBox checkBox = new JCheckBox();
checkBox.getUI().uninstallUI(checkBox);
try {
UIManager.setLookAndFeel(selectedLaf);
} catch (Exception e) {
System.out.println("Can't change L&F: " + e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -