How do I embed output window tab to another component?
You have to create IOContainer
which provides access (for IOProvider
) to your component where you want to embed OW tab (IO tab). Then you need to pass IOContainer
instance to IOProvider.getIO(String name, Action actions, IOContainer ioContainer)
. IOContainer
is created by IOContainer.create(IOContainer.Provider)
. The following code demonstrates how to add OW to custom TopComponent.:
IOContainer ioc = IOContainer.create(new IOC());
InputOutput io = IOProvider.getDefault().getIO("test", new Action[0], ioc);
io.getOut().println("Hi there");
io.select();
// implement IOContainer.Provider in TopComponent where OW tab will be added
class IOC extends TopComponent implements IOContainer.Provider {
JComponent ioComp;
CallBacks ioCb;
public IOC() {
setLayout(new BorderLayout());
setDisplayName("Test");
}
@Override
public int getPersistenceType() {
return PERSISTENCE_NEVER;
}
public void add(JComponent comp, CallBacks cb) {
if (ioComp != null) {
remove(ioComp);
if (ioCb != null) {
ioCb.closed();
}
}
ioComp = comp;
ioCb = cb;
add(comp);
validate();
}
public JComponent getSelected() {
return ioComp;
}
boolean activated;
public boolean isActivated() {
return activated;
}
@Override
protected void componentActivated() {
super.componentActivated();
activated = true;
if (ioCb != null) {
ioCb.activated();
}
}
@Override
protected void componentDeactivated() {
super.componentDeactivated();
activated = false;
if (ioCb != null) {
ioCb.deactivated();
}
}
public boolean isCloseable(JComponent comp) {
return false;
}
public void remove(JComponent comp) {
if (comp == ioComp) {
ioComp = null;
ioCb = null;
}
}
public void select(JComponent comp) {
}
public void setIcon(JComponent comp, Icon icon) {
}
public void setTitle(JComponent comp, String name) {
}
public void setToolTipText(JComponent comp, String text) {
}
public void setToolbarActions(JComponent comp, Action[] toolbarActions) {
}
}
Applies to: NetBeans 6.7