我最近刚尝试在项目中使用JInternalFrame
组件,我将其嵌套在JPanel
中。但是,我注意到JInternalFrame
的标题栏是点缀的,我不喜欢它有点。我希望它看起来像任何其他标题栏,如JDialog
,它是平滑而坚实的。
看起来像这样。
这是标题栏上唯一包含点的组件。顺便说一句,我问的原因是因为我使用了Netbeans的GUI Builder来生成它。
答案 0 :(得分:2)
正如camickr所说,需要定制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);
});
}
}
答案 1 :(得分:1)
改变系统外观和方式的方法之一感觉,例如:
例如,代码:
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);