Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2009, 09:00 AM
Registered User
 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Runtime checkbox with Jtree

Hi friends,

i am happy to join in this forum. i have a problem in adding checkbox in runtime.

in my code i can create Jtree(c:). In this all c: files and folders i want to add checkbox. could anyone help me please this is urgent for me.

Below i attach code (i want to add only checkbox)


[code}

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeModel;
import java.io.*;
import java.util.Vector;

public class MyTree extends JFrame implements ActionListener{

File[] rt;

File drive;
private DefaultComboBoxModel comboModel;

MyTreeModel model;
File root = null;
JTree tree;

public MyTree() {

initComponents();

}

public void initComponents() {

setLayout(new BorderLayout());
setDefaultCloseOperation(javax.swing.WindowConstan ts.DISPOSE_ON_CLOSE);


panelB = new javax.swing.JPanel();


//panelB.setLayout(new BorderLayout());

//panelB.setLayout(null);


comboModel = new DefaultComboBoxModel();


selectDrive = new JComboBox(comboModel);

rt=File.listRoots();





for (int i=0; i<rt.length; i++)
{
drive = rt[i];

//comboModel.addElement(drive);
comboModel.addElement(drive);

}

selectDrive.setModel(comboModel);

selectDrive.addActionListener(this);
selectDrive.setActionCommand("sel_drive");
tree = new JTree();


tscrollPane = new JScrollPane(tree);

displayTree();


//panelB.add(selectDrive,BorderLayout.NORTH);
// panelB.add(tscrollPane,BorderLayout.CENTER);

panelB.add(selectDrive,BorderLayout.NORTH);
panelB.add(tscrollPane,BorderLayout.CENTER);

add(panelB,BorderLayout.NORTH);

pack();

}

public void actionPerformed(ActionEvent e)
{

String cmd = e.getActionCommand();

if(cmd.equals("sel_drive")){
//displayTree();
}
}

public void displayTree(){
Object obj = comboModel.getSelectedItem();
String str = obj.toString();
File f = new File(str);
System.out.println();


model = new MyTreeModel(f);
tree.setModel(model);



}

public static void main(String args[]){
MyTree treefr = new MyTree();




treefr.setSize(500, 500);
treefr.setVisible(true);

}

public JComboBox selectDrive;

public JPanel panelB;
public JScrollPane tscrollPane;


}
[/code]
 
Old October 5th, 2009, 01:48 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sorry for the delayed reply, check the following link on using check boxes as tree nodes

http://www.jroller.com/santhosh/date/20050610
__________________
- Rakesh
http://iam-rakesh.blogspot.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create runtime Checkbox button ? piscarian VB.NET 0 November 18th, 2007 08:27 PM
Adding nodes to JTree sriharshareddyk Java Basics 0 May 4th, 2007 01:18 PM
Creating CheckBox at runtime. sachingowdar Java GUI 2 April 22nd, 2007 09:55 PM
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
filling JTree from database Yerkin Java Databases 0 August 10th, 2005 05:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.