Mega Code Archive

 
Categories / Java / Swing JFC
 

If the toolbar is to be floatable, it must be added to a container with a BorderLayout

import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JToolBar; public class Main {   public static void main(String[] argv) throws Exception {     // Add the toolbar to a frame     JFrame frame = new JFrame();     JToolBar toolbar = new JToolBar();     frame.getContentPane().add(toolbar, BorderLayout.NORTH);     frame.pack();     frame.setVisible(true);   } }