gpt4 book ai didi

java - 在 Substance LAF 中删除 JTabbedPane 上的内容填充

转载 作者:行者123 更新时间:2023-11-30 09:23:44 25 4
gpt4 key购买 nike

我正在使用 Substance LAF 进行一些实验,我正在尝试移除选项卡之间的填充。我使用的默认用户界面:

UIManager.getDefaults().put("TabbedPane.contentBorderInsets", new Insets(0,0,0,0));
UIManager.getDefaults().put("TabbedPane.tabsOverlapBorder", true);

,但这不适用于 Substance ,它似乎提供了自己的值(value)。如何使用 Substance 实现相同的效果。

最佳答案

  • 无法使用 JTabbedPane 的 UIManager 覆盖此值,

  • 这是一个很常见的问题,大多数方法都受到保护(如果它们作为键在 UIManager 中发布并不重要)而不会覆盖自己的 BasicTabbedPaneUI


  • 物质

enter image description here

javax.swing.plaf.InsetsUIResource[top=4,left=4,bottom=4,right=4]
false
  • 金属(跨平台)

enter image description here

java.awt.Insets[top=4,left=2,bottom=3,right=3] 
false
  • 灵气

enter image description here

null
null

系统(Java6上的win8)

enter image description here

javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=3,right=3]
true
  • 键的值是 Instets(0,0,0,0) 还是 InsetsUIResource(0,0,0,0) 形式都没有关系

Kirill 修改后的代码

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import org.pushingpixels.substance.api.DecorationAreaType;
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.skin.BusinessBlueSteelSkin;
import org.pushingpixels.substance.api.skin.OfficeBlack2007Skin;
import org.pushingpixels.substance.api.skin.OfficeBlue2007Skin;

/**
* Test application that shows the use of the
* {@link SubstanceLookAndFeel#getDecorationType(java.awt.Component)} API called
* on different components.
*
* @author Kirill Grouchnikov
* @see SubstanceLookAndFeel#getDecorationType(java.awt.Component)
*/
public class GetDecorationType /*extends JFrame*/ {

private static final long serialVersionUID = 1L;
private static JFrame frame = new JFrame();

/**
* Creates the main frame for
* <code>this</code> sample.
*/
public GetDecorationType() {
frame.setTitle("Get decoration type");
frame.setLayout(new BorderLayout());
final JTabbedPane tabs = new JTabbedPane();
SubstanceLookAndFeel.setDecorationType(tabs, DecorationAreaType.HEADER);
JPanel tab1 = new JPanel(new FlowLayout());
tab1.add(new JTextField("sample"));
final JComboBox combo = new JComboBox(new Object[]{"sample"});
tab1.add(combo);
SubstanceLookAndFeel.setDecorationType(tab1, DecorationAreaType.GENERAL);
JPanel tab2 = new JPanel(new FlowLayout());
tab2.add(new JTextField("sample2"));
tab2.add(new JComboBox(new Object[]{"sample2"}));
SubstanceLookAndFeel.setDecorationType(tab2, DecorationAreaType.GENERAL);
tabs.addTab("tab1", tab1);
tabs.addTab("tab2", tab2);
frame.add(tabs, BorderLayout.CENTER);
JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JButton getTypes = new JButton("Get types");
getTypes.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DecorationAreaType tabsType = SubstanceLookAndFeel.getDecorationType(tabs);
DecorationAreaType comboType = SubstanceLookAndFeel.getDecorationType(combo);
JOptionPane.showMessageDialog(frame, "Tabbed pane: " + tabsType.getDisplayName()
+ "\n" + "Combo box: " + comboType.getDisplayName());
}
});
}
});
controlPanel.add(getTypes);
frame.add(controlPanel, BorderLayout.SOUTH);
frame.setSize(400, 200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

/**
* The main method for
* <code>this</code> sample. The arguments are ignored.
*
* @param args Ignored.
*/
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
/*UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());*/
} catch (Exception e) {
return;
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
//SubstanceLookAndFeel.setSkin(new BusinessBlueSteelSkin());
//SubstanceLookAndFeel.setSkin(new OfficeBlack2007Skin());
SubstanceLookAndFeel.setSkin(new OfficeBlue2007Skin());
UIManager.put("TabbedPane.contentOpaque", Boolean.TRUE);
System.out.println(UIManager.getDefaults().get("TabbedPane.contentBorderInsets"));
System.out.println(UIManager.getDefaults().get("TabbedPane.tabsOverlapBorder"));
UIManager.getDefaults().put("TabbedPane.contentBorderInsets", new javax.swing.plaf.InsetsUIResource(0, 0, 0, 0));
UIManager.getDefaults().put("TabbedPane.tabsOverlapBorder", true);
SwingUtilities.updateComponentTreeUI(frame);
new GetDecorationType()/*.setVisible(true)*/;
}
});
}
}

关于java - 在 Substance LAF 中删除 JTabbedPane 上的内容填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15945977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com