Ejemplo n.º 1
0
  public MsnTreeTest() {
    String[] tab = {"hello", "test", "blabla"};

    container = getContentPane();
    container.setLayout(null);

    eleve = new DefaultMutableTreeNode("MSN");

    worker = new DefaultMutableTreeNode("Worker");
    prof = new DefaultMutableTreeNode("Profs");

    for (int i = 0; i < tab.length; i++) {
      worker.add(new DefaultMutableTreeNode(tab[i]));
      prof.add(new DefaultMutableTreeNode(tab[i]));
    }
    //        worker.add(new DefaultMutableTreeNode("hello world2"));

    eleve.add(worker);
    eleve.add(prof);

    tree = new JTree(eleve);

    scroll = new JScrollPane(tree);
    scroll.setBounds(10, 10, 100, 100);

    container.add(scroll);

    setSize(300, 300);
    setLocation(200, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);

    //        worker.add(n);

  }
Ejemplo n.º 2
0
    /** Displays the labels and the values for the panel. */
    protected void displayPnlFields(HashMap hmPnl) {
      if (hmPnl == null || hmPnl.isEmpty()) return;

      Iterator keySetItr = hmPnl.keySet().iterator();
      String strLabel = "";
      String strValue = "";

      // if the file is empty, then create an empty set of textfields.
      if (hmPnl == null || hmPnl.isEmpty()) {
        displayNewTxf("", "");
        return;
      }

      Container container = getParent();
      if (container != null) container.setVisible(false);
      try {
        // Get each set of label and value, and display them.
        while (keySetItr.hasNext()) {
          strLabel = (String) keySetItr.next();
          strValue = (String) hmPnl.get(strLabel);

          displayNewTxf(strLabel, strValue);
        }

        if (container != null) container.setVisible(true);
        revalidate();
        repaint();
      } catch (Exception e) {
        Messages.writeStackTrace(e);
        // e.printStackTrace();
        Messages.postDebug(e.toString());
      }
    }
Ejemplo n.º 3
0
  public DirTreeModified() {
    Container c = getContentPane();
    // *** Build the tree and a mouse listener to handle clicks
    root = readNode();
    treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel);

    MouseListener ml =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (box.isSelected()) {
              showDetails(tree.getPathForLocation(e.getX(), e.getY()));
            }
          }
        };
    tree.addMouseListener(ml);
    // *** panel the JFrame to hold controls and the tree
    controls = new JPanel();
    box = new JCheckBox(showString);
    init(); // ** set colors, fonts, etc. and add buttons
    c.add(controls, BorderLayout.NORTH);
    c.add(tree, BorderLayout.CENTER);
    setVisible(true); // ** display the framed window
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // ** kills process on exit.
  }
Ejemplo n.º 4
0
 public void doAction(ActionEvent e) {
   String cmd = e.getActionCommand();
   // the new button creates a new set of texfields
   if (cmd.equals("new")) {
     Container container = getParent();
     if (container != null) container.setVisible(false);
     displayNewTxf("", "");
     if (container != null) container.setVisible(true);
   }
 }
 private boolean fitsInBounds(final Rectangle rect) {
   final Container container = getParent();
   if (container instanceof JViewport) {
     final Container scrollPane = container.getParent();
     if (scrollPane instanceof JScrollPane) {
       final Rectangle rectangle =
           SwingUtilities.convertRectangle(this, rect, scrollPane.getParent());
       return scrollPane.getBounds().contains(rectangle);
     }
   }
   return true;
 }
  @Override
  public void dispose() {
    PropertiesComponent instance = PropertiesComponent.getInstance();
    instance.setValue(PROP_SORTED, Boolean.toString(isAlphabeticallySorted()));
    instance.setValue(PROP_SHOWCLASSES, Boolean.toString(myShowClasses));

    if (myCopyJavadocCheckbox != null) {
      instance.setValue(PROP_COPYJAVADOC, Boolean.toString(myCopyJavadocCheckbox.isSelected()));
    }

    final Container contentPane = getContentPane();
    if (contentPane != null) {
      contentPane.removeAll();
    }
    mySelectedNodes.clear();
    myElements = null;
    super.dispose();
  }
Ejemplo n.º 7
0
  public SelectableTree() {
    super("JTree Selections");
    WindowUtilities.setNativeLookAndFeel();
    addWindowListener(new ExitListener());
    Container content = getContentPane();

    String[] namesplitStrings = mainDir.toString().split("\\\\");
    String filename = namesplitStrings[namesplitStrings.length - 1];
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(filename);

    addChildren(root, mainDir);
    tree = new JTree(root);
    tree.addTreeSelectionListener(this);
    content.add(new JScrollPane(tree), BorderLayout.CENTER);
    currentSelectionField = new JTextField("Current Selection: NONE");
    content.add(currentSelectionField, BorderLayout.SOUTH);
    setSize(250, 275);
    setVisible(true);
  }
Ejemplo n.º 8
0
  public JTrees() {
    JFrame frame = new JFrame("JTree Demo");
    Container c = frame.getContentPane();
    c.setLayout(new BorderLayout());

    // Create top node of a tree
    final DefaultMutableTreeNode top = new DefaultMutableTreeNode("Course");

    // Create a subtree UG
    final DefaultMutableTreeNode UG = new DefaultMutableTreeNode("UG");
    top.add(UG);
    final DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("B.E");
    UG.add(a1);
    final DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("B.C.A");
    UG.add(a2);
    final DefaultMutableTreeNode a3 = new DefaultMutableTreeNode("B.Sc");
    UG.add(a3);
    final DefaultMutableTreeNode a4 = new DefaultMutableTreeNode("B.Com");
    UG.add(a4);
    final DefaultMutableTreeNode a5 = new DefaultMutableTreeNode("B.A");
    UG.add(a5);

    // Create a subtree PG
    final DefaultMutableTreeNode PG = new DefaultMutableTreeNode("PG");
    top.add(PG);
    final DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("M.E");
    PG.add(b1);
    final DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("M.C.A");
    PG.add(b2);
    final DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("M.Sc");
    PG.add(b3);
    final DefaultMutableTreeNode b4 = new DefaultMutableTreeNode("M.Com");
    PG.add(b4);
    final DefaultMutableTreeNode b5 = new DefaultMutableTreeNode("M.A");
    PG.add(b5);

    // Creating tree
    final JTree tree = new JTree(top);

    int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    final JScrollPane jsp = new JScrollPane(tree, v, h);
    c.add(jsp, BorderLayout.CENTER);

    final JTextField text = new JTextField("", 20);
    c.add(text, BorderLayout.SOUTH);

    tree.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent me) {
            TreePath tp = tree.getPathForLocation(me.getX(), me.getY());
            if (tp != null) text.setText(tp.toString());
            else text.setText("");
          }
        });
    if (top.children() == b1) {
      System.out.println("M.E Cource Selected");
    }
    frame.setSize(300, 200);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }