Reputation: 1954
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.
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.
Upvotes: 2
Views: 652
Reputation: 9808
As camickr has already said, would need to make a customized BasicInternalFrameTitlePane
:
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);
});
}
}
Upvotes: 2
Reputation: 2222
One of the way to change a system look & feel, for example:
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);
Upvotes: 1