1. Introduction
Under most look and feels, the user can drag the toolbar away from the original window component (unless the Floatable property is set to false). To be able to implement the drag effect normally, an instance of the class is suggested to be added to four edges in the BorderLayout layout-managed container.
2. Code
PackageCn.test2;Importjava.awt.BorderLayout;ImportJava.awt.Color;Importjava.awt.Dimension;ImportJavax.swing.JButton;ImportJavax.swing.JFrame;ImportJavax.swing.JPanel;ImportJavax.swing.JToolBar; Public classjtoolbartest {JFrame JF=NewJFrame ("JToolBar test"); JToolBar Toolbar=NewJToolBar (); Public voidinit () {JButton tool1=NewJButton ("Tool One"); JButton tool2=NewJButton ("Tool Two"); JButton tool3=NewJButton ("Tool three"); Toolbar.add (TOOL1); Toolbar.add (tool2); Toolbar.add (TOOL3); Jf.add (toolbar,borderlayout.west); JPanel Panel=NewJPanel (); Panel.setbackground (color.red); Jf.add (panel); Jf.setpreferredsize (NewDimension (500, 500)); Jf.pack (); Jf.setdefaultcloseoperation (Jframe.exit_on_close); Jf.setvisible (true); } Public Static voidMain (string[] args) {Newjtoolbartest (). Init (); }}
:
Use of the "Java" JToolBar class