Need to add checkbox to JTreeTables..HELP plz

hello everybody,
I am having problems adding a checkbox to a JTreeTable example from sun .
i also have a woriking checkbox Jtree class and it is working fine, i tried to add jtable to the jtree and i couldnt.
can anybody help me, either how ti add a checkbox to a JTreeTable or how to add a JTable to a JCheckBoxTree.
thanks lots.

http://forum.java.sun.com/thread.jspa?threadID=461659&messageID=4024652#4024652

Similar Messages

  • Code for complete JTree of mycomputer (dynamic) but need to add checkboxes

    //the bug is where i am sending the value to the checkbox.. if somebody can add checkboxes to every node plz reply soon
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Font;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.event.MouseEvent;
    import java.util.EventObject;
    import java.util.Vector;
    import javax.swing.AbstractCellEditor;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.UIManager;
    import javax.swing.event.ChangeEvent;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.TreeCellEditor;
    import javax.swing.tree.TreeCellRenderer;
    import javax.swing.tree.TreePath;
    public class CheckBoxNodeTreeSample {
    public static void main(String args[]) {
    JFrame frame = new JFrame("CheckBox Tree");
    /* CheckBoxNode accessibilityOptions[] = {
    new CheckBoxNode(
    "Move system caret with focus/selection changes", false),
    new CheckBoxNode("Always expand alt text for images", true) };
    CheckBoxNode browsingOptions[] = {
    new CheckBoxNode("Notify when downloads complete", true),
    new CheckBoxNode("Disable script debugging", true),
    new CheckBoxNode("Use AutoComplete", true),
    new CheckBoxNode("Browse in a new process", false) };
    Vector accessVector = new NamedVector("Accessibility",
    accessibilityOptions);
    Vector browseVector = new NamedVector("Browsing", browsingOptions);
    Object rootNodes[] = { accessVector, browseVector };
    Vector rootVector = new NamedVector("Root", rootNodes);
    setLayout(new GridLayout(1,1));
    //create the top node
    MutableTreeNode root = new DefaultMutableTreeNode("Computer");
    //get all nodes for top file systems or disks
    //On Linux/Unix this will only be '/'
    //while on Window there will typically be more: 'A:', 'C:' etc.
    File roots[] = File.listRoots();
    //loop through all these nodes and add them to the root Computer node
    int i = 0;
    for(File f : roots) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(f.getAbsoluteFile().toString());
    root.insert(node, i++);
    //create a tree model with the Computer node as root
    model = new DefaultTreeModel(root);
    JTree tree = new JTree(model);
    CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer();
    tree.setCellRenderer(renderer);
    tree.setCellEditor(new CheckBoxNodeEditor(tree));
    tree.setEditable(true);
    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
    class CheckBoxNodeRenderer implements TreeCellRenderer {
    private JCheckBox leafRenderer = new JCheckBox();
    private DefaultTreeCellRenderer nonLeafRenderer = new DefaultTreeCellRenderer();
    Color selectionBorderColor, selectionForeground, selectionBackground,
    textForeground, textBackground;
    protected JCheckBox getLeafRenderer() {
    return leafRenderer;
    public CheckBoxNodeRenderer() {
    Font fontValue;
    fontValue = UIManager.getFont("Tree.font");
    if (fontValue != null) {
    leafRenderer.setFont(fontValue);
    Boolean booleanValue = (Boolean) UIManager
    .get("Tree.drawsFocusBorderAroundIcon");
    leafRenderer.setFocusPainted((booleanValue != null)
    && (booleanValue.booleanValue()));
    selectionBorderColor = UIManager.getColor("Tree.selectionBorderColor");
    selectionForeground = UIManager.getColor("Tree.selectionForeground");
    selectionBackground = UIManager.getColor("Tree.selectionBackground");
    textForeground = UIManager.getColor("Tree.textForeground");
    textBackground = UIManager.getColor("Tree.textBackground");
    public Component getTreeCellRendererComponent(JTree tree, Object value,
    boolean selected, boolean expanded, boolean leaf, int row,
    boolean hasFocus) {
    Component returnValue;
    if (leaf) {
    String stringValue = tree.convertValueToText(value, selected,
    expanded, leaf, row, false);
    leafRenderer.setText(stringValue);
    leafRenderer.setSelected(false);
    leafRenderer.setEnabled(tree.isEnabled());
    if (selected) {
    leafRenderer.setForeground(selectionForeground);
    leafRenderer.setBackground(selectionBackground);
    } else {
    leafRenderer.setForeground(textForeground);
    leafRenderer.setBackground(textBackground);
    if ((value != null) && (value instanceof DefaultMutableTreeNode)) {
    Object userObject = ((DefaultMutableTreeNode) value)
    .getUserObject();
    if (userObject instanceof CheckBoxNode) {
    CheckBoxNode node = (CheckBoxNode) userObject;
    leafRenderer.setText(node.getText());
    leafRenderer.setSelected(node.isSelected());
    returnValue = leafRenderer;
    } else {
    returnValue = nonLeafRenderer.getTreeCellRendererComponent(tree,
    value, selected, expanded, leaf, row, hasFocus);
    return returnValue;
    class CheckBoxNodeEditor extends AbstractCellEditor implements TreeCellEditor {
    CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer();
    ChangeEvent changeEvent = null;
    JTree tree;
    public CheckBoxNodeEditor(JTree tree) {
    this.tree = tree;
    public Object getCellEditorValue() {
    JCheckBox checkbox = renderer.getLeafRenderer();
    CheckBoxNode checkBoxNode = new CheckBoxNode(checkbox.getText(),
    checkbox.isSelected());
    return checkBoxNode;
    public boolean isCellEditable(EventObject event) {
    boolean returnValue = false;
    if (event instanceof MouseEvent) {
    MouseEvent mouseEvent = (MouseEvent) event;
    TreePath path = tree.getPathForLocation(mouseEvent.getX(),
    mouseEvent.getY());
    if (path != null) {
    Object node = path.getLastPathComponent();
    if ((node != null) && (node instanceof DefaultMutableTreeNode)) {
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
    Object userObject = treeNode.getUserObject();
    returnValue = ((treeNode.isLeaf()) && (userObject instanceof CheckBoxNode));
    return returnValue;
    public Component getTreeCellEditorComponent(JTree tree, Object value,
    boolean selected, boolean expanded, boolean leaf, int row) {
    Component editor = renderer.getTreeCellRendererComponent(tree, value,
    true, expanded, leaf, row, true);
    // editor always selected / focused
    ItemListener itemListener = new ItemListener() {
    public void itemStateChanged(ItemEvent itemEvent) {
    if (stopCellEditing()) {
    fireEditingStopped();
    if (editor instanceof JCheckBox) {
    ((JCheckBox) editor).addItemListener(itemListener);
    return editor;
    class CheckBoxNode {
    String text;
    boolean selected;
    public CheckBoxNode(String text, boolean selected) {
    this.text = text;
    this.selected = selected;
    public boolean isSelected() {
    return selected;
    public void setSelected(boolean newValue) {
    selected = newValue;
    public String getText() {
    return text;
    public void setText(String newValue) {
    text = newValue;
    public String toString() {
    return getClass().getName() + "[" + text + "/" + selected + "]";
    class NamedVector extends Vector {
    String name;
    public NamedVector(String name) {
    this.name = name;
    public NamedVector(String name, Object elements[]) {
    this.name = name;
    for (int i = 0, n = elements.length; i < n; i++) {
    add(elements);
    public String toString() {
    return "[" + name + "]";

    Between when you posted the question and the entire 50 minutes you waited for an answer, I tried compiling that code you posted, with a view to help out.
    What I found was..
    That code did not compile as posted.
    - It was missing imports
    - There was a direct reference to setLayout that applied to no member
    - model was not declared properly
    It also shows unchecked add warnings, please fix those before posting.
    BTW - please do not remove indenting from posted code, it makes it very hard to read, replace any tabs in the source for 2-4 spaces instead. Also, code is easier to examine when it is enclosed in 'code' tags - this can be achieved by selecting the code and pressing the 'code' button above the form field we type the messages.
    On the subject of what you are trying to do, please trim your example down to something that tries to create this tree form any directory structure the user might specify with a JFileChooser, because I am running a slow machine with large drives, and creating a JTree of the entire file system would take far too long.
    Fix those things, and I'll take a second look.
    As an aside. If you wish to get answers 'within the hour', you will probably need a consultant or a help desk. If you post to these forums, you need to be more patient.

  • Need to add checkbox in alv header Not  in grid

    Dear Guru's,
                       My question is i want to add checkbox on top of alv grid ie on top of page .
    my requriement is for SD module- status of order -Mass Update.
    suppose status checkbox on header is HFSC is checked ( check box),
    for all the sales order which are showed on the alv grid must be updated with this status for which i am calling trasaction VA02 in program and doing changes but i am not able to create checkbox on header .
    Again i have already used ALV without classesso please give me solution accordinglly . Thanks in advance.

    Hi,
    For working with top of page we generally use SLIS_LISTHEADER right.
    In this type the first field is
    type - which can accept values as follows
               H - Heading
               S - Selection
               A - Action
    May be the options Selection or Action may help u.

  • I need an apple genious! someone help plz!

    So whenever i click on my itunes icon it give me a message saying the itunes library.itl file is locked, on a locked disk, or you do not have write permission for this file.
    now ive restarted my computer 3 times but it stays the same? Please help! Thanks

    Did you just install iTunes?
    If so, delete the itunes library.itl file in Windows Explorer.
    I bet you get a message from Norton or some other security software saying, that file can't be deleted.

  • G U I ( I need to add a gui) please help

    I am trying to design an implement a GUI for this program. This program should let the user input the interest rate, principle, and period, and should accumalate value of interest.
    * File: CDInterest.java
    * Tamar Thompson
    * Description: This application program illustrates the use of Java library
    * classes to perform certain useful calculations.
    * It uses the java.lang.Math class to calculate the principal of a
    * Certificate of Deposit (CD) invested at a certain interest rate for a certain
    * time period. It uses the java.text.NumberFormat class to format the numerical results
    * which represent dollar amounts and percentages.
    import java.io.*; // Import the Java I/O Classes
    import java.text.NumberFormat; // For formatting as $nn.dd or n%
    public class CDInterest {
    private BufferedReader input = new BufferedReader // Handles console input
    (new InputStreamReader(System.in));
    private String inputString; // Stores the input
    private double principal; // The CD's initial principal
    private double rate; // CD's interest rate
    private double years; // Number of years to maturity
    private double cdAnnual; // Accumulated principal with annual compounding
    private double cdDaily; // Accumulated principal with daily compounding
    * convertStringTodouble() converts a String of the form "54.87" into
    * its corresponding double value (54.87).
    * @param s -- stores the string to be converted
    * @return A double is returned
    private double convertStringTodouble(String s) {
    Double doubleObject = Double.valueOf(s) ;
    return doubleObject.doubleValue();
    * getInput() handles all the input required by the program. It inputs
    * three Strings and converts each to a (double) number, storing them
    * in instance variables (principal, rate, and years).
    private void getInput() throws IOException {
    // Prompt the user and get the input
    System.out.println("This program compares daily and annual compounding for a CD.");
    System.out.print(" Input the CD's initial principal, e.g. 1000.55 > ");
    inputString = input.readLine();
    principal = convertStringTodouble(inputString);
    System.out.print(" Input the CD's interest rate, e.g. 6.5 > ");
    inputString = input.readLine();
    rate = (convertStringTodouble(inputString)) / 100.0;
    System.out.print(" Input the number of years to maturity, e.g., 10.5 > ");
    inputString = input.readLine();
    years = convertStringTodouble(inputString);
    } //getInput()
    * calcAndReportResults() handles all the interest calculations and reports
    * the program's results. Note the use of Math.pow() to calculate the CD's
    * value, and the use of the NumberFormat.format() methods for making the output
    * look pretty.
    private void calcAndReportResult() {
    // Calculate and output the result
    NumberFormat dollars = NumberFormat.getCurrencyInstance(); // Set up formats
    NumberFormat percent = NumberFormat.getPercentInstance();
    percent.setMaximumFractionDigits(2);
    cdAnnual = principal * Math.pow(1 + rate, years); // Calculate interest
    cdDaily = principal * Math.pow(1 + rate/365, years*365);
    // Print the results
    System.out.println("The original principal is " + dollars.format(principal));
    System.out.println("The resulting principal compounded daily at " +
    percent.format(rate) + " is " + dollars.format(cdDaily));
    System.out.println("The resulting principal compounded yearly at " +
    percent.format(rate) + " is " + dollars.format(cdAnnual));
    } // calcAndReportResult()
    * main() creates an instance of the CDInterest object and then invokes
    * its methods to calculate the interest for a CD using values input by
    * the user.
    public static void main( String args[] ) throws IOException {
    CDInterest cd = new CDInterest();
    cd.getInput();
    cd.calcAndReportResult();
    } // main()
    } // Interest

    Then you are going to have to do a lot of rewriting, because GUI programs don't actively "get" input. (At least they shouldn't.) They passively wait until somebody keys some input into a field or clicks on a button. Have you looked at the Swing tutorial?

  • Add checkbox on header level Tab Org.data

    Dear All,
    My requirement is I need to add checkbox on header level Tab Org.data in ME21n or ME21.
    And if checkbox is checked in the tab Org.data, it should display Terms and Conditions in the print preview.
    Please suggest how to write code? Is there any user exit for transactions ME21N or ME21.
    Thanks,
    Rana.

    hi praveen,
    search this forum on how to implement a badi if you haven't done one before. also, go to transation SE18 and read the documentation on badi_fdcb_subbas01 which clearly says that its used for FB60... see the example how they have used it by going to menubar Implementation->Overview then choose FI_FDCB_SUBBAS01_EX (Example for Screen Enhancement 1 on FDCB Basic Data Screen)...you should look at the method PUT_DATA_TO_SCREEN_OBJECT and tab Subscreens where the screen exits are available to use.
    In FB60, if you go to menubar System->Status and check the Program (Subscreen) and Screen Number, you'll see it'll match the program name and screen no. provided in the Subscreen tab of the BADI.
    Hope this helps.
    Cheers,
    Sougata.

  • How to Add Checkbox and icon in ALVGRID

    Hi Experts,
      i have one Requirement. i need to add Checkbox, Selectall,icon(Unlock or inactive) infront of Contracts of ALV GRID.How to achive that.
    Thanks,
    Venkat.

    Hi
    For check box
    At declaring field catalog using structure LVC_S_FCAT
    mark CHECKBOX = 'X' and also EDIT = 'X'.
    For reference check below subroutine in program BCALV_EDIT_05.
    form build_fieldcat changing pt_fieldcat type lvc_t_fcat.
    data ls_fcat type lvc_s_fcat.
    call function 'LVC_FIELDCATALOG_MERGE'
    exporting
    i_structure_name = 'SFLIGHT'
    changing
    ct_fieldcat = pt_fieldcat.
    *§A2.Add an entry for the checkbox in the fieldcatalog
    clear ls_fcat.
    ls_fcat-fieldname = 'CHECKBOX'.
    * Essential: declare field as checkbox and
    * mark it as editable field:
    ls_fcat-checkbox = 'X'.
    ls_fcat-edit = 'X'.
    * do not forget to provide texts for this extra field
    ls_fcat-coltext = text-f01.
    ls_fcat-tooltip = text-f02.
    ls_fcat-seltext = text-f03.
    * optional: set column width
    ls_fcat-outputlen = 10.
    append ls_fcat to pt_fieldcat.
    endform.
    For Icon:
    CONSTANTS:
         icon_id_failure            LIKE icon-id   VALUE ' ((Content component not found.)) @',
         icon_id_okay              LIKE icon-id   VALUE ' ((Content component not found.)) @'.
    TYPES: BEGIN OF ls_tab,
           matnr LIKE equi-matnr,
           maktx LIKE makt-maktx,
           b_werk  LIKE equi-werk,
           b_lager LIKE equi-lager,
           lgobe LIKE t001l-lgobe,
           sernr LIKE equi-sernr,
           icon LIKE icon-id,
           objnr LIKE equi-objnr,
          END OF   ls_tab.
    *Table that display the data for the ALV.
    DATA: itab  TYPE ls_tab OCCURS 0 WITH HEADER LINE.
        PERFORM get_h_date .
        IF h_date => sy-datum .
          itab-icon = icon_id_okay.
        ELSE .
          itab-icon = icon_id_failure.
         ENDIF.
    Regards
    Sudheer

  • Need to add JList to a Panel Please do help me out!!!

    hi every body I need to add JList to Panel in a JTabbedPaneand having three columns by gridlayout,I have to add Jlist elements in one column and in the second one get elements from the database and place them in this column with a check and in third column i have some buttons
    in the first column add Jlist elements around 10 elements
    in the second column can we use check(true/false) for the data which we got from the database,when we uncheck here the list corresponding in the first should be disabled.
    I am using swings please give me ur ideas can this be made in different ways how can this work
    i am trying this since yesterday but could't get the correct way
    do help me out
    thanking you
    with regards

    Just when you change status of radiobutton or checkbox in its changeListener event call
    setEnabled( false );
    for the appropriate JList
    I hope that you didnt wanted me explain you entire possible code and blah blah

  • HT201269 I am using my daughters old laptop (which already has her iTunes on it) and need to add my iPhone and iTunes acct info but can't figure out how...   HELP!!

    I am using my daughters old laptop (which already has her iTunes on it) and need to add my iPhone and iTunes acct info but can't figure out how...   PLEASE HELP!!

    Sign her out of the iTunes copy that's on the machine, then you can sign in with your account credentials.

  • HT3702 I am unable to add my bank/card details in my apple account, every time i am getting a message that it has been declined. kindly help me in authorise my bank card in my apple account i need to purchase few apps, pls help me

    Hi,
    I am unable to add my bank/card details in my apple account, every time i am getting a message that it has been declined. kindly help me in authorise my bank card in my apple account i need to purchase few apps, pls help me

    What sort of card are you trying to use ? If it's a debit card then I don't think that they are still accepted as a valid payment method - they are not listed on this page and there have been a number of posts recently about them being declined
    If it's a credit card then is it registered to exactly the same name and address (including format and spacing etc) that you have on your iTunes account, it was issued by a bank in your country and you are currently in that country ? If it is then you could check with the card issuer to see if it's them that are declining it, and if not then try contacting iTunes support and see if they know why it's being declined : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Account Management

  • I was told I need to remove the enterprise server account I have and need to add a new one for work but the IT person did not tell me how to do this.  Can anyone help?

    I was told I need to remove the enterprise server account I have and need to add a new one for work but the IT person did not tell me how to do this.  Can anyone help?

        Jennymbell, never fear help is here!
    Have you tried contacting your IT department for assistance? You can visit http://bit.ly/QECbGh for steps on how to enterprise activation.
    Keep me posted if you need further assistance.
    John B
    Follow us on Twitter @VZWSupport

  • I need to add a new computer and take off a old one but can't find the site or place to turn it off i can only have two computers but i got three please help let me know where to go to shut one off to put the new one on?

    i need to add a new computer and take off a old one but can't find the site or place to turn it off i can only have two computers but i got three please help let me know where to go to shut one off to put the new one on?

    Hello,
    the way is written there Activation & deactivation help >>> (see there only to understand the procedure) Common activation problems >>> "Activation limit reached for [product]. This serial number has already been activated on 2 computers." "Maximum activations exceeded."
    >>> How to deactivate or sign out >>> A single license for Adobe software lets you install the applications on two computers—for example, at home and at the office. However, you can use the software on only one computer at any given time.
    If you want to install the software on a third computer, deactivate the software on the computer on which you will no longer use the software. Then, activate the software on the new computer.
    Hans-Günter

  • Help plz, i need back up my phone

    Help plz, i have iphone 4 i still have icloud  on my itunes and i need to update it to the new one but i dont want to lose any of my pictues of my kids im not sure if ive backed it up before if i have it would of been a long time ago plz help me thanks

    jennyspeedy* wrote:
    i dont want to lose any of my pictues of my kids im not sure if ive backed it up before if i have it would of been a long time ago plz help me thanks
    Then use the device as designed.  Copy the pictures off the device to the computer.  For any pictures that you desire to keep on the device, simply sync them via iTunes.
    Failure to copy the pictures off the device is only asking for problems.  If the device is ever lost/stolen or simply fails to work, without a backup they would be gone as well.

  • Need to add a record in search help

    Hi all,
    I have field in my selection screen with search help.
    serach help contains 4 records  i need to add 5 th record in that search help how can i add that one.
    Thanks,

    check it out may be helpful for u
    Re: how to add a value/entry in a exisiting search help
    check the below link also
    http://help.sap.com/saphelp_nw04s/helpdata/en/b3/4d3642eca5033be10000000a1550b0/content.htm
    Regards,
    Naveen

  • HELP! Need to add TIMECODE

    can someone please help
    I need to add a timecode to an FLV
    I added all the other controls and tied them to teh playback
    with AS but for teh life of me cannot figure this out
    Thank you all

    use:
    minus_btn.addEventListener(Event.MouseEvent,CLICK, clear)
    function clear(e:MouseEvent){
    var sql:SQLStatement = new SQLStatement();
    sql.sqlConnection = conn;
    var s:String = "DELETE from contacte WHERE nume= :numeparam AND telefon=:telefonparam";
    sql.text = s;
    sql.parameters[":numeparam"] = whatever;
    sql.parameters[":telefonparam"] = whatever else;
    //add listeners if you want
    sql.execute();

Maybe you are looking for