How do you make a JToolBar floating and at the same time not resizable?

John Zukowski

You need to create a new ToolBarUI. The following example is from John Zukowski's Definitive Guide to Swing for Java 2:

import javax.swing.*;
import javax.swing.plaf.metal.MetalToolBarUI;
import java.awt.*;
import java.awt.event.*;

public class CustomToolBarUI extends MetalToolBarUI {
  public final static String FRAME_IMAGEICON = "ToolBar.frameImageIcon";

  protected JFrame createFloatingFrame(JToolBar toolbar) {
    JFrame frame = new JFrame(toolbar.getName());
    Icon icon = UIManager.getIcon(FRAME_IMAGEICON);
    if (icon instanceof ImageIcon) {
      Image iconImage = ((ImageIcon)icon).getImage();
    WindowListener windowListener = createFrameListener();
    return frame;
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact