import java.io.IOException;
import com.esri.arcgis.addins.desktop.Button;
import com.esri.arcgis.framework.IApplication;
import com.esri.arcgis.framework.IDockableWindow;
import com.esri.arcgis.framework.IDockableWindowManager;
import com.esri.arcgis.framework.IDockableWindowManagerProxy;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.system.UID;
public final class btnMain extends Button
{
private IDockableWindow docWin;
@Override
public void init(IApplication app) {
try {
IDockableWindowManager dwm = new IDockableWindowManagerProxy(app);
UID uid = new UID();
uid.setValue("com.esri.arcgis.arcmap.addin.frmMain");
docWin = dwm.getDockableWindow(uid);
}
catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onClick() throws IOException, AutomationException {
try {
if (docWin != null) {
docWin.show(!docWin.isVisible());
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import com.esri.arcgis.addins.desktop.DockableWindow;
import com.esri.arcgis.arcmapui.IMxDocument;
import com.esri.arcgis.framework.IApplication;
import com.esri.arcgis.interop.AutomationException;
public final class frmMain extends DockableWindow
{
private JButton jButton;
private JPanel jPanel;
private IApplication app;
public static void main(String[] args){
}
@Override
public Component createUI() {
jButton = new JButton("Click Me!");
jPanel = new JPanel();
jButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Hello, World");
}
});
jPanel.setLayout(new BorderLayout());
jPanel.add(jButton, BorderLayout.NORTH);
return jPanel;
}
@Override
public void init(IApplication app) {
this.app = app;
try {
IMxDocument mxDocument = (IMxDocument)app.getDocument();
} catch (AutomationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Setting properties
A dockable window has a number of properties for you to set. The following is a list of all of the properties with an explanation for each:
- id* - The id represents the unique name that is used to identify your dockable window. It is possible for you to create more than one dockable window for a given project and this id property is used to distinguish between the different dockable windows. Notice that the previous image shows a default value for this property. Ideally, you should replace this id with a more meaningful name. It is also highly recommended that the Java package naming convention is used when constructing your id property value. For example, com.esri.arcgis.arcmap.addin.arcmapdockablewindow could be used to represent the add-in dockable window being created for this document (Required).
Two things.
1. The command will be found in the Java Commands section under customize, like so:
[ATTACH=CONFIG]32370[/ATTACH]
2. The id value of your dockable window, assuming you took the defaults, would be "dockablewindow1".
The sample you are looking at uses the following for the id value: "com.esri.arcgis.arcmap.addin.arcmapdockablewindow"
That probably worked for the developer making the sample, but for people who follow the sample and don't use the same package structure, it doesn't work.
You probably missed this part:
Sure, create your GUI in window builder like you would normally.
In your Dockable Window class, and in this method: public Component createUI()
Just instantiate your form in that method and return an instance of it.
Basically like this:
MyGUIForm mygui = new MyGUIForm();
return mygui;
There are patterns that you can follow that will give you only one instance of that of form, so that you don't get new instances of the MyGUIForm every time you click the button.
Just to be a little more specific. I would stick to extending JPanel rather than a JFrame in your custom GUI.
While the API says that createGUI() will take a Swing or AWT component, I'm not sure that you would need a JFrame and the window events that go along with that inside a DockableWindow, since the DockableWindow has a dispose() method.
Well, I was wrong about being able to instantiate an instance of another class that extends JPanel from within the createGUI() method.
So today we learned that the createGUI() method of DockableWindow will return a component that is a JPanel as long as the code lives in the createGUI() method, but it is unhappy to allow an instance created of a JPanel or even Component from another class.
Just create your JPanel in WindowBuilder and copy the code into the createGUI() method of DockableWindows.
As for your Java Commands problem.
See this:
[ATTACH=CONFIG]32405[/ATTACH]