// This sample demonstrates how to host // Java components in diagram nodes // Create the controls to be hosted JTextArea textArea = new JTextArea(); JButton button = new JButton(); // Initialize the controls textArea.setText("Hello, world!"); button.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { onClick(); } }); button.setText("Show"); // Create two ControlNode objects ControlNode editNode = new ControlNode(); editNode.setBounds(new Rectangle2D.Float(10, 10, 40, 8)); editNode.setMouseInputMode(MouseInputMode.HandledByHostedControl); diagram.getNodes().add(editNode); ControlNode buttonNode = new ControlNode(); buttonNode.setBounds(new Rectangle2D.Float(10, 20, 40, 8)); diagram.getNodes().add(buttonNode); // Setup hosts editNode.setControl(textArea); editNode.setTag("edit"); buttonNode.setControl(button); ... private void onClick() { // Show a message box with the text currently // displayed within the TextBox control ControlNode host = (ControlNode)diagram.findNode("edit"); if (host != null) { JTextArea textArea = (JTextArea)host.getControl(); JOptionPane.showMessageDialog(this, textArea.getText()); } }