java swing 如何实现工具条任意拖拽的功能,类似与word的工具条,请大侠指点 本帖最后由 u011386820 于 2013-07-12 17:06:01 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Swing提供一个工具条组件,根据工具条的方向,工具条组件包含一行按钮或一列按钮。工具条通常提供对普通特性的简单访问。工具条还可以是悬浮的,这样,可以把工具条在窗口中任意拖动或拖到一个单独的窗口中。 程序中的工具条是可以任意拖动的package bbs_713;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Test extends JApplet { Icon dukeStanding = new ImageIcon("duke_standing.gif"), dukeWaving = new ImageIcon("duke_waving.gif"), dukeStandingSmall = new ImageIcon("duke_standing_small.gif"), dukeWavingSmall = new ImageIcon("duke_waving_small.gif"); public void init() { Container contentPane = getContentPane(); Action[] actions = { new NewAction(), new OpenAction(), new CutAction(), new CopyAction(), new PasteAction(), new ExitAction() }; JToolBar toolbar = new JToolBar(); JMenuBar menubar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JRadioButton menubarDuke = new JRadioButton(dukeStandingSmall), menuDuke = new JRadioButton( dukeStandingSmall), toolbarDuke = new JRadioButton(dukeStanding); menuDuke.setRolloverIcon(dukeWavingSmall); menubarDuke.setRolloverIcon(dukeWavingSmall); toolbarDuke.setRolloverIcon(dukeWaving); menubar.add(menubarDuke); toolbar.add(toolbarDuke); fileMenu.add(menuDuke); for (int i = 0; i < actions.length; ++i) { fileMenu.add(actions[i]); if (i != actions.length - 1) toolbar.add(actions[i]); if (i == 2 || i == actions.length - 2) { toolbar.addSeparator(); fileMenu.addSeparator(); } } menubar.add(fileMenu); contentPane.add(toolbar, BorderLayout.NORTH); getRootPane().setJMenuBar(menubar); System.out.println(contentPane.getClass().getName()); LayoutManager lm = contentPane.getLayout(); System.out.println(lm.getClass()); } class NewAction extends AbstractAction { public NewAction() { super("New ...", new ImageIcon("new.gif")); } public void actionPerformed(ActionEvent event) { showStatus("new"); } } class OpenAction extends AbstractAction { public OpenAction() { super("Open ...", new ImageIcon("open.gif")); } public void actionPerformed(ActionEvent event) { showStatus("open"); } } class CutAction extends AbstractAction { public CutAction() { super("Cut", new ImageIcon("cut.gif")); } public void actionPerformed(ActionEvent event) { showStatus("cut"); } } class CopyAction extends AbstractAction { public CopyAction() { super("Copy", new ImageIcon("copy.gif")); } public void actionPerformed(ActionEvent event) { showStatus("copy"); } } class PasteAction extends AbstractAction { public PasteAction() { super("Paste", new ImageIcon("paste.gif")); } public void actionPerformed(ActionEvent event) { showStatus("paste"); } } class ExitAction extends AbstractAction { public ExitAction() { super("Exit"); putValue(Action.SMALL_ICON, dukeWavingSmall); } public void actionPerformed(ActionEvent event) { System.exit(0); } }} 获取JDK路径 help!!! 大家看看这个错怎么解决 ??????????????????????????? 请问这到底是个什么错误啊?请指教 救急。。。这是什么原因啊!!! 等中文版太迟了,请大家总结一下的外国的技术好网站和论坛 【各位大哥帮帮忙,关于在EditPlus下编译和执行java的问题】 问几个关于eclipse的几个问题,谢谢指点! 怎么java一个程序,让他在后台运行? 线程简单问题 JLayeredPane 不同层的控件重叠显示的问题,急!
import java.awt.*;
import java.awt.event.*;public class Test extends JApplet {
Icon dukeStanding = new ImageIcon("duke_standing.gif"),
dukeWaving = new ImageIcon("duke_waving.gif"),
dukeStandingSmall = new ImageIcon("duke_standing_small.gif"),
dukeWavingSmall = new ImageIcon("duke_waving_small.gif"); public void init() {
Container contentPane = getContentPane();
Action[] actions = { new NewAction(), new OpenAction(),
new CutAction(), new CopyAction(), new PasteAction(),
new ExitAction() };
JToolBar toolbar = new JToolBar();
JMenuBar menubar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JRadioButton menubarDuke = new JRadioButton(dukeStandingSmall), menuDuke = new JRadioButton(
dukeStandingSmall), toolbarDuke = new JRadioButton(dukeStanding); menuDuke.setRolloverIcon(dukeWavingSmall);
menubarDuke.setRolloverIcon(dukeWavingSmall);
toolbarDuke.setRolloverIcon(dukeWaving);
menubar.add(menubarDuke);
toolbar.add(toolbarDuke);
fileMenu.add(menuDuke);
for (int i = 0; i < actions.length; ++i) {
fileMenu.add(actions[i]);
if (i != actions.length - 1)
toolbar.add(actions[i]);
if (i == 2 || i == actions.length - 2) {
toolbar.addSeparator();
fileMenu.addSeparator();
}
}
menubar.add(fileMenu);
contentPane.add(toolbar, BorderLayout.NORTH);
getRootPane().setJMenuBar(menubar);
System.out.println(contentPane.getClass().getName());
LayoutManager lm = contentPane.getLayout();
System.out.println(lm.getClass());
} class NewAction extends AbstractAction {
public NewAction() {
super("New ...", new ImageIcon("new.gif"));
} public void actionPerformed(ActionEvent event) {
showStatus("new");
}
} class OpenAction extends AbstractAction {
public OpenAction() {
super("Open ...", new ImageIcon("open.gif"));
} public void actionPerformed(ActionEvent event) {
showStatus("open");
}
} class CutAction extends AbstractAction {
public CutAction() {
super("Cut", new ImageIcon("cut.gif"));
} public void actionPerformed(ActionEvent event) {
showStatus("cut");
}
} class CopyAction extends AbstractAction {
public CopyAction() {
super("Copy", new ImageIcon("copy.gif"));
} public void actionPerformed(ActionEvent event) {
showStatus("copy");
}
} class PasteAction extends AbstractAction {
public PasteAction() {
super("Paste", new ImageIcon("paste.gif"));
} public void actionPerformed(ActionEvent event) {
showStatus("paste");
}
} class ExitAction extends AbstractAction {
public ExitAction() {
super("Exit");
putValue(Action.SMALL_ICON, dukeWavingSmall);
} public void actionPerformed(ActionEvent event) {
System.exit(0);
}
}
}