有没有办法在JInternalFrame
图标菜单中添加/删除项目(这就是它的名称?)?
感谢@camickr,我能够使用Swing Utils深入挖掘UIManager。我发现的是:我打印出了Nimbus
LookAndFeel HashMap
for(Entry<Object, Object> entry : SwingUtils.getUIDefaultsOfClass(JInternalFrame.class).entrySet()) {
System.out.println(entry.getKey().toString() + " ----------- " + entry.getValue().toString());
System.out.println("*********************************");
}
这就是出现的情况:
closeButton"[Pressed].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneCloseButtonPainter@1dddec9e
*********************************
titleAlignment ----------- CENTER
*********************************
titleFont ----------- java.awt.Font[family=SansSerif,name=sansserif,style=bold,size=12]
*********************************
iconifyButton".contentMargins ----------- javax.swing.plaf.InsetsUIResource[top=9,left=9,bottom=9,right=9]
*********************************
iconifyButton"[Pressed+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneIconifyButtonPainter@2dfbc274
*********************************
menuButton".WindowNotFocused ----------- WindowNotFocused
*********************************
maximizeButton".contentMargins ----------- javax.swing.plaf.InsetsUIResource[top=9,left=9,bottom=9,right=9]
*********************************
maxFrameIconSize ----------- javax.swing.plaf.DimensionUIResource[width=18,height=18]
*********************************
maximizeButton"[MouseOver].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@4e2899d0
*********************************
disabledText ----------- DerivedColor(color=0,0,0 parent=text offsets=0.0,0.0,0.0,0 pColor=0,0,0
*********************************
backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFramePainter@4b8a4ec6
*********************************
InternalFrameUI ----------- javax.swing.plaf.synth.SynthLookAndFeel
*********************************
closeButton"[Disabled].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneCloseButtonPainter@38d9e447
*********************************
menuButton"[MouseOver+WindowNotFocused].iconPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMenuButtonPainter@6ef66f2f
*********************************
menuButton".test ----------- am InternalFrameTitlePane.menuButton
*********************************
menuButton"[MouseOver].iconPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMenuButtonPainter@74fdaf92
*********************************
textForeground ----------- DerivedColor(color=142,143,145 parent=nimbusDisabledText offsets=0.0,0.0,0.0,0 pColor=142,143,145
*********************************
maximizeButton"[Enabled+WindowMaximized+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@67e61dd0
*********************************
iconifyButton"[MouseOver+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneIconifyButtonPainter@48a5d3d5
*********************************
closeButton"[Enabled].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneCloseButtonPainter@5a5cbad
*********************************
iconifyButton".WindowNotFocused ----------- WindowNotFocused
*********************************
foreground ----------- DerivedColor(color=0,0,0 parent=text offsets=0.0,0.0,0.0,0 pColor=0,0,0
*********************************
menuButton".icon ----------- javax.swing.plaf.nimbus.NimbusIcon@26cb216f
*********************************
maximizeButton"[Enabled+WindowMaximized].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@47decdc0
*********************************
maximizeButton"[MouseOver+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@74961d1c
*********************************
contentMargins ----------- javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0]
*********************************
menuButton".contentMargins ----------- javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0]
*********************************
iconifyButton".States ----------- Enabled,MouseOver,Pressed,Disabled,Focused,Selected,WindowNotFocused
*********************************
maximizeButton"[Pressed].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@2b515510
*********************************
maximizeButton"[Pressed+WindowMaximized].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@68a7a3a7
*********************************
background ----------- DerivedColor(color=214,217,223 parent=control offsets=0.0,0.0,0.0,0 pColor=214,217,223
*********************************
closeButton".contentMargins ----------- javax.swing.plaf.InsetsUIResource[top=9,left=9,bottom=9,right=9]
*********************************
menuButton"[Enabled].iconPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMenuButtonPainter@73d6af61
*********************************
menuButton"[Pressed].iconPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMenuButtonPainter@139444b1
*********************************
maximizeButton"[Enabled].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@27f5ad1c
*********************************
font ----------- javax.swing.plaf.FontUIResource[family=SansSerif,name=sansserif,style=plain,size=12]
*********************************
maximizeButton"[Pressed+WindowMaximized+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@72381dc2
*********************************
maximizeButton"[Disabled+WindowMaximized].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@4229e623
*********************************
windowBindings ----------- [Ljava.lang.Object;@2d10609a
*********************************
maximizeButton"[MouseOver+WindowMaximized].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@4cc425c4
*********************************
menuButton"[Enabled+WindowNotFocused].iconPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMenuButtonPainter@618b8e3b
*********************************
menuButton"[Disabled].iconPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMenuButtonPainter@1126f585
*********************************
iconifyButton"[MouseOver].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneIconifyButtonPainter@14c0f78f
*********************************
closeButton".WindowNotFocused ----------- WindowNotFocused
*********************************
disabled ----------- DerivedColor(color=214,217,223 parent=control offsets=0.0,0.0,0.0,0 pColor=214,217,223
*********************************
maximizeButton"[Enabled+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@8bcd7ee
*********************************
States ----------- Enabled,WindowFocused
*********************************
maximizeButton"[Pressed+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@26044ebd
*********************************
iconifyButton"[Pressed].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneIconifyButtonPainter@64cd6dca
*********************************
closeButton"[Enabled+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneCloseButtonPainter@5f203fe5
*********************************
actionMap ----------- javax.swing.plaf.basic.LazyActionMap@82f0668
*********************************
InternalFrameTitlePaneUI ----------- javax.swing.plaf.synth.SynthLookAndFeel
*********************************
closeButton"[Pressed+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneCloseButtonPainter@22b1513e
*********************************
menuButton".States ----------- Enabled,MouseOver,Pressed,Disabled,Focused,Selected,WindowNotFocused
*********************************
WindowFocused ----------- WindowFocused
*********************************
maximizeButton"[Disabled].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@274ccf3d
*********************************
maximizeButton".States ----------- Enabled,MouseOver,Pressed,Disabled,Focused,Selected,WindowNotFocused,WindowMaximized
*********************************
closeButton"[MouseOver+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneCloseButtonPainter@23b9c1f3
*********************************
iconifyButton"[Disabled].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneIconifyButtonPainter@223dd567
*********************************
iconifyButton"[Enabled].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneIconifyButtonPainter@9856ec1
*********************************
maximizeButton"[MouseOver+WindowMaximized+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter@172a45c9
*********************************
closeButton".States ----------- Enabled,MouseOver,Pressed,Disabled,Focused,Selected,WindowNotFocused
*********************************
menuButton"[Pressed+WindowNotFocused].iconPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneMenuButtonPainter@584b9b00
*********************************
closeButton"[MouseOver].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneCloseButtonPainter@4bad4a49
*********************************
maximizeButton".WindowNotFocused ----------- WindowNotFocused
*********************************
maximizeButton".WindowMaximized ----------- WindowMaximized
*********************************
iconifyButton"[Enabled+WindowNotFocused].backgroundPainter ----------- javax.swing.plaf.nimbus.InternalFrameTitlePaneIconifyButtonPainter@5de8256f
*********************************
答案 0 :(得分:0)
不要以为你可以删除它们(没有创建你自己的自定义UI,这对我来说太复杂了。)
你应该可以禁用它们。查看JInternalFrame
API构造函数,了解将属性设置为false的方法。或者,您可以使用setter方法单独禁用给定属性。
编辑:
注意到Windows上的默认LAF没有该菜单,所以肯定是LAF问题。
编辑2:
也许作为一个黑客你可以使用Darryl的Swing Utils来获取为内部框架定义的所有JMenuItem组件的List。然后,您可以简单地从其父JMenu中删除菜单项。
编辑3:
我建议获取JMenuItem组件的列表,而不是UIDefaults。这假设BasicInternalFrameUI使用了JMenuBar,JMenu和JMenuItems。这个假设是正确的。
事实证明,Metal LAF扩展了基本的LAF,并没有将JMenubar添加到内部框架的标题窗格中。相反,只需在左上角绘制一个图标,解释为什么没有系统菜单。
但是,Windows LAF实际上使用自定义绘制的JLabel来显示系统菜单的图标,然后只响应mousePressed事件以显示弹出菜单。因此,对于Window LAF,您可以使用SwingUtils查找此标签,只需从标签中删除MouseListener即可。下面的“框架”变量是您的内部框架。
java.util.List<JLabel> labels = SwingUtils.getDescendantsOfType(JLabel.class, frame, true);
for (JLabel label: labels)
{
System.out.println(label.getClass().getName());
MouseListener[] ml = (MouseListener[])label.getListeners(MouseListener.class);
for (int i = 0; i < ml.length; i++)
label.removeMouseListener( ml[i] );
}
正如我之前提到的,这实际上只是一个黑客,应该不会被使用,因为它不是一个跨平台的解决方案。