import java.awt.*; import javax.swing.*; import javax.swing.tree.*; public class Okno extends javax.swing.JFrame { /** Creates new form Okno */ public Okno() { initComponents(); } /** 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. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jTree1 = new javax.swing.JTree(); area = new javax.swing.JLayeredPane(); jButton1 = new javax.swing.JButton(); jCheckBox1 = new javax.swing.JCheckBox(); jRadioButton1 = new javax.swing.JRadioButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jScrollPane1.setViewportView(jTree1); area.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jButton1.setText("jButton1"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton1.setBounds(10, 10, 75, 23); area.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER); jCheckBox1.setText("jCheckBox1"); jCheckBox1.setBounds(10, 40, 81, 23); area.add(jCheckBox1, javax.swing.JLayeredPane.DEFAULT_LAYER); jRadioButton1.setText("jRadioButton1"); jRadioButton1.setBounds(10, 70, 93, 23); area.add(jRadioButton1, javax.swing.JLayeredPane.DEFAULT_LAYER); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE) .addGap(18, 18, 18) .addComponent(area, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(area, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)) .addContainerGap()) ); pack(); }// //GEN-END:initComponents // import java.awt.*; // import javax.swing.*; // import javax.swing.tree.*; DefaultTreeModel model; private void show (MyNode above, Container cont) { int n = cont.getComponentCount(); for (int i = 0; i < n; i++) { Component c = cont.getComponent(i); MyNode node = new MyNode (c); above.add (node); if (c instanceof Container) show (node, (Container) c); } } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed MyNode root = new MyNode (this); show (root, this); model = new DefaultTreeModel (root); jTree1.setModel (model); }//GEN-LAST:event_jButton1ActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Okno().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLayeredPane area; private javax.swing.JButton jButton1; private javax.swing.JCheckBox jCheckBox1; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTree jTree1; // End of variables declaration//GEN-END:variables }