Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:41:06+00:00 2026-05-31T17:41:06+00:00

I am currently having trouble finding the index/location of a button in a table

  • 0

I am currently having trouble finding the index/location of a button in a table I am generating.

private class Node
   {
    String id;
    String[] data;
    List<Node> children = new ArrayList<Node>();
}

private Node root = buildTree();

private Node buildTree()
    {
        Node root = new Node();
        root.id = "Main Component";
        root.data = new String[]{ "example", "example", "example", "example", "example", "example",};

    Node child1 = new Node();
    child1.id = "Part 1";
    child1.data = new String[]{ "example", "example", "example", "example", "example", "example", "example"};
    root.children.add(child1);

    Node child11 = new Node();
    child11.id = "Part 1-1";
    child11.data = new String[]{ "example", "example", "example", "example", "example", "example", "example"};
    child1.children.add(child11);

    Node child2 = new Node();
    child2.id = "Part 2";
    child2.data = new String[]{ "example", "example", "example", "example", "example", "example", "example"};
    root.children.add(child2);

    Node child21 = new Node();
    child21.id = "Part 2-1";
    child21.data = new String[]{ "example", "example", "example", "example", "example", "example", "example"};
    child2.children.add(child21);

    Node child22 = new Node();
    child22.id = "Part 2-2";
    child22.data = new String[]{ "example", "example", "example", "example", "example", "example", "example"};
    child2.children.add(child22);

    Node child3 = new Node();
    child3.id = "Part 3";
    child3.data = new String[]{ "example", "example", "example", "example", "example", "example", "example"};
    root.children.add(child3);

    Node child31 = new Node();
    child31.id = "Part 3-1";
    child31.data = new String[]{ "example", "example", "example", "example", "example", "example", "example"};
    child3.children.add(child31);

    Node child32 = new Node();
    child32.id = "Part 3-2";
    child32.data = new String[]{ "example", "example", "example", "example", "example", "example", "example"};
    child3.children.add(child32);

    return root;
}

Here is my data model. The idea here is that I will add rows to the table with a couple functions however I am stuck at an early step.

private void addRow(Node nde)
{
    HorizontalPanel buttonPanel = new HorizontalPanel();

    ListBox comboBox = new ListBox();
    comboBox.addItem("option1");
    comboBox.addItem("option2");
    comboBox.addItem("option3");
    comboBox.addItem("option4");
    comboBox.addItem("option5");

    Button addRowButton = new Button("+/-");

    addRowButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            //Get the button from the click event
            //Get the row from the button - could I possibly set a class to each button that equals the id of the element being added so that I could just pull the id from the button
            //Use the row to get the first column - returns a panel
            //Get the components on the panel, find the label, and get the text
            String id = "";
            clickFunction(id);
        }
    });

    buttonPanel.add(addRowButton);
    buttonPanel.add(new Label(nde.id));

    int row = flexTable.getRowCount();
    flexTable.setWidget(row,0,buttonPanel);
    flexTable.setWidget(row,1,comboBox);
    flexTable.setText(row,2,nde.data[0]);
    flexTable.setText(row,3,nde.data[1]);
    flexTable.setText(row,4,nde.data[2]);
    flexTable.setText(row,5,nde.data[3]);
    flexTable.setText(row,6,nde.data[4]);
    flexTable.setText(row,7,nde.data[5]);
}

This is how I am adding rows, there is a horizontal panel in the first column of every row, the first element is a button and the second is a title that matches the ID of whatever node is being displayed in that row. I need a way to get that id, set it equal to the string and pass it into my clickFunction.

private void clickFunction(String curRowId)
{
    Node rowNode = findNode(root, curRowId);

            //need to determine whether or not the tree needs to be expanded or minimized.

            for(Node n : rowNode.children) {
        addRow(n);
    }

}

clickFunction uses the id passed in my findNode function

private Node findNode(Node nde, String id)
{
    if(nde.id.equals(id))
    {
        return nde;
    }

    for(Node n : nde.children)
    {
        Node rtrn = findNode(n, id);
        if(rtrn != null)
        {
            return rtrn;
        }
    }

    return null;
}

Which is called recursively to tell the code which node needs its children extended. I hope this was not too long, I wanted to make sure I included all relevant info and proved I’m actually working hard to remedy problems I’m having. Its definitely frustrating when I’ve worked so much out but can’t figure out a seemingly simple problem.

Any information is greatly appreciated! Much thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:41:08+00:00Added an answer on May 31, 2026 at 5:41 pm

    To set the id for the button, you can do something like this…

    Button b = new Button();
    DOM.setElementAttribute(b.getElement(), "id", "my-button-id");
    

    You should then be able to match it in your findNode method.

    See http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/DOM.html for more information on working with the DOM.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently having trouble creating an image from a binary string of data in
I'm currently having trouble with a destructor of a class which contains a vector
I'm having trouble finding out which tag is currently checked out. When I do:
I'm having trouble finding my way around Zend Framework documentation. I'm currently using the
I'm currently having trouble getting example code for using tweepy to access Twitter's Streaming
I am currently having trouble with a live wallpaper that does some very intensive
The part of the application that I am currently having trouble getting to work
I am currently having unnecessary trouble trying to test out RubyMine. My biggest problem
I'm currently having some trouble with getting certain input fields passed along when a
I'm having trouble getting my links the way I want them. Currently, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.