2

I recently just tried to use JInternalFrame component in my project which I nested inside a JPanel. However, I noticed that the title bar of JInternalFrame is dotted and I don't like it to have dots. I want it to look just like any other title bar like JDialog's which is smooth and solid.

It looks like this.

enter image description here

This is the only component that has dots on title bar. By the way, the reason I'm asking is because I used that GUI Builder of Netbeans to produce this.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
heisenberg
  • 1,784
  • 4
  • 33
  • 62
  • 1
    A JInternalFrame should not be added to a JPanel. It is designed to be added to a JDesktopPane. The different UI is part of the LAF and lets the user know that the internal frame is dragable inside the desktop pane. If you don't like the LAF, then just create your own panel with its own "title bar". – camickr Jul 13 '17 at 01:05

2 Answers2

2

As camickr has already said, would need to make a customized BasicInternalFrameTitlePane:

screenshot

import java.awt.*;
import java.util.Arrays;
import javax.swing.*;
import javax.swing.plaf.basic.*;
import javax.swing.plaf.metal.*;

public class InternalFrameTitlePaneTest {
  public JInternalFrame makeInternalFrame() {
    return new JInternalFrame("basic", true, true, true, true) {
      @Override public void updateUI() {
        super.updateUI();
        setUI(new MetalInternalFrameUI(this) {
          @Override protected JComponent createNorthPane(JInternalFrame w) {
            BasicInternalFrameTitlePane p = new BasicInternalFrameTitlePane(w) {
              @Override public Dimension getPreferredSize() {
                Dimension d = super.getPreferredSize();
                d.height = 24;
                return d;
              }
              @Override public void createButtons() {
                super.createButtons();
                Arrays.asList(closeButton, maxButton, iconButton).forEach(b -> {
                  b.setContentAreaFilled(false);
                  b.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
                });
              }
            };
            p.setBorder(BorderFactory.createMatteBorder(
                0, 0, 1, 0, MetalLookAndFeel.getPrimaryControlDarkShadow()));
            return p;
          }
        });
      }
    };
  }
  public JComponent makeUI() {
    JInternalFrame f1 = makeInternalFrame();
    f1.setSize(150, 100);
    f1.setLocation(0, 0);
    f1.setVisible(true);

    JInternalFrame f2 = new JInternalFrame("metal", true, true, true, true);
    f2.setSize(150, 100);
    f2.setLocation(80, 50);
    f2.setVisible(true);

    JDesktopPane desktop = new JDesktopPane();
    desktop.add(f1);
    desktop.add(f2);
    return desktop;
  }
  public static void main(String[] args) {
    EventQueue.invokeLater(() -> {
      JFrame f = new JFrame();
      f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      f.getContentPane().add(new InternalFrameTitlePaneTest().makeUI());
      f.setSize(320, 240);
      f.setLocationRelativeTo(null);
      f.setVisible(true);
    });
  }
}
aterai
  • 9,658
  • 4
  • 35
  • 44
1

One of the way to change a system look & feel, for example:

enter image description here

For example, code:

public static String[] str1LF = {
    "javax.swing.plaf.metal.MetalLookAndFeel",
    "javax.swing.plaf.nimbus.NimbusLookAndFeel",
    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel",
    "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel",
    "com.sun.java.swing.plaf.motif.MotifLookAndFeel",
    "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
};

...// in constructor 
        try {
            UIManager.setLookAndFeel(str1LF[4]);
            SwingUtilities.updateComponentTreeUI(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JFrame.setDefaultLookAndFeelDecorated(true);
Vasyl Lyashkevych
  • 1,920
  • 2
  • 23
  • 38