gpt4 book ai didi

java - 在 Netbeans 7.2 中隐藏 TopComponent 选项卡

转载 作者:行者123 更新时间:2023-12-01 14:23:29 24 4
gpt4 key购买 nike

我正在使用 Netbeans 平台版本 7.2 和 JDK 1.7 创建应用程序。我希望能够隐藏安装到编辑器位置的 TopComponent 元素上的选项卡。我用谷歌搜索发现this post Geertjan Wielenga 的博客上似乎准确地解释了要做什么,但我似乎仍然无法使其发挥作用。

我的应用程序由两个项目组成。其中一个是 Netbeans 模块,另一个是“Netbeans 平台应用程序”项目。该模块由三个类组成:Installer.javaNoTabsTabDisplayerUI.javaStupidTopComponent.javaInstaller.java 非常简单,由

组成
package org.foo;

import javax.swing.UIManager;
import org.openide.modules.ModuleInstall;

public class Installer extends ModuleInstall {

@Override
public void restored() {
UIManager.put("EditorTabDisplayerUI", "org.foo.NoTabsTabDisplayerUI");
}
}

NoTabsTabDisplayerUI.java 或多或少逐字取自 Geertjan 的博客,看起来像

package org.foo;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle;
import javax.swing.DefaultSingleSelectionModel;
import javax.swing.JComponent;
import javax.swing.SingleSelectionModel;
import javax.swing.plaf.ComponentUI;
import org.netbeans.swing.tabcontrol.TabDisplayer;
import org.netbeans.swing.tabcontrol.TabDisplayerUI;

public class NoTabsTabDisplayerUI extends TabDisplayerUI {

public NoTabsTabDisplayerUI(TabDisplayer displayer) {
super(displayer);
}

public static ComponentUI createUI(JComponent jc) {
assert jc instanceof TabDisplayer;
return new NoTabsTabDisplayerUI((TabDisplayer) jc);
}

private static final int[] PTS = new int[] { 0, 0, 0 };
@Override
public Polygon getExactTabIndication(int i) {
//Should never be called
return new Polygon(PTS, PTS, PTS.length);
}

@Override
public Polygon getInsertTabIndication(int i) {
return new Polygon(PTS, PTS, PTS.length);
}

@Override
public int tabForCoordinate(Point point) {
return -1;
}

@Override
public Rectangle getTabRect(int i, Rectangle rectangle) {
return new Rectangle(0,0,0,0);
}

@Override
protected SingleSelectionModel createSelectionModel() {
return new DefaultSingleSelectionModel();
}

public java.lang.String getCommandAtPoint(Point point) {
return null;
}

@Override
public int dropIndexOfPoint(Point point) {
return -1;
}

@Override
public void registerShortcuts(javax.swing.JComponent jComponent) {
//do nothing
}

@Override
public void unregisterShortcuts(javax.swing.JComponent jComponent) {
//do nothing
}

@Override
protected void requestAttention(int i) {
//do nothing
}

@Override
protected void cancelRequestAttention(int i) {
//do nothing
}

@Override
public Dimension getPreferredSize(javax.swing.JComponent c) {
return new Dimension(0, 0);
}

@Override
public Dimension getMinimumSize(javax.swing.JComponent c) {
return new Dimension(0, 0);
}

@Override
public Dimension getMaximumSize(javax.swing.JComponent c) {
return new Dimension(0, 0);
}
}

StupidTopComponent.java 只是一个带有标签的 TopComponent。代码如下:

package org.foo;

import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

/**
* Top component which displays something.
*/
@ConvertAsProperties(
dtd = "-//org.foo//Stupid//EN",
autostore = false)
@TopComponent.Description(
preferredID = "StupidTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "editor", openAtStartup = true)
@ActionID(category = "Window", id = "org.foo.StupidTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
displayName = "#CTL_StupidAction",
preferredID = "StupidTopComponent")
@Messages({
"CTL_StupidAction=Stupid",
"CTL_StupidTopComponent=Stupid Window",
"HINT_StupidTopComponent=This is a Stupid window"
})
public final class StupidTopComponent extends TopComponent {

public StupidTopComponent() {
initComponents();
setName(Bundle.CTL_StupidTopComponent());
setToolTipText(Bundle.HINT_StupidTopComponent());

}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jLabel1 = new javax.swing.JLabel();

org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(StupidTopComponent.class, "StupidTopComponent.jLabel1.text")); // NOI18N

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(74, 74, 74)
.addComponent(jLabel1)
.addContainerGap(267, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(88, 88, 88)
.addComponent(jLabel1)
.addContainerGap(198, Short.MAX_VALUE))
);
}// </editor-fold>

// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
// End of variables declaration
@Override
public void componentOpened() {
// TODO add custom code on component opening
}

@Override
public void componentClosed() {
// TODO add custom code on component closing
}

void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
p.setProperty("version", "1.0");
// TODO store your settings
}

void readProperties(java.util.Properties p) {
String version = p.getProperty("version");
// TODO read your settings according to their version
}
}

平台应用程序项目仅包含此模块。当我运行它时,它仍然显示 TopComponent 上的选项卡。

在调试器中运行它,我从未看到它命中 NoTabsTabDisplayerUI.java 中的任何代码。它似乎从未调用该类中的构造函数或任何其他函数。我的第一个想法是由于某种原因没有找到该类,但我不确定如何测试是否是这种情况。

我在这里遗漏了一些明显的东西吗?

最佳答案

您需要将对 UIManager.put() 的调用包装在 Runnable 中并在 EDT 上运行它:

SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
UIManager.put("EditorTabDisplayerUI", "org.foo.NoTabsTabDisplayerUI");
}
});

在 Geertjan 在那篇博客文章中使用的 NB 版本中,您不需要这样做。

关于java - 在 Netbeans 7.2 中隐藏 TopComponent 选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17348861/

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