Results 1 to 9 of 9
  1. #1
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default Plz Urgent!...How to display a list of items and on click display subitems?

    Hi all,

    I need the java code which on execution will display items, say 5 items. Then, when I click on one of these items, that item will expand and show subitems, say 5 subitems( one item as a web link). Please provide me with the java code. Its urgent and I need it badly. IF the execution is different then simple java programs( like how it is executed in command prompt), then please guide the execution part also.
    Last edited by mandyj; 12-27-2008 at 06:32 PM.

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Sorry...

    This is not a code factory, it's a java forum to help developers with their questions, problems and doubts. The best that I can help you with is the following link to lists in swing:
    How to Use Lists (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Swing Components)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Hello and welcome to the forum. You know of course that all of the folks here are volunteers who enjoy helping others learn Java, and we'll gladly help you with your code or with specific questions on how you can create a certain program. On the other hand, what this forum isn't is a code-producing mill that gives out code on demand.

    So on that note, let's see a decent try by you towards a solution first. After you've done this and posted it with your specific questions, I'm sure that several of us will be be glad to help you along.

    Best of luck!

    [edit: now it's my time to be slow and to be beaten by cjslman!]

  4. #4
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default

    Thanks...

    But sorry to post it here as a newbie cud not help asking my doubt. Let me see if I can come up with a valid question!

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Getting back at your original question, it suggests a tree of some sort, so perhaps a JTree may fit your bill here?

    But even before exploring this option, please make sure that you are looking for a Java solution here and not a JavaScript solution as the latter is often involved in web applications (though Java is quite useful for web apps too), and the two platforms are completely different.

    Again, good luck.

  6. #6
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default

    Hi all,

    Got something here after a great struggle... this is the code

    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.lang.*;
    public class progtest extends Applet implements ActionListener
    {
    TextField num;
    Choice ch;
    Label l;
    String msg="";
    progtest(String title)
    {
    super(title);
    ch=new Choice();
    ch.add("1");
    ch.add("2");
    ch.add("3");
    ch.add("4");
    ch.add("5");
    num=new TextField(6);
    setLayout(new FlowLayout());
    Label numb=new Label("News:",Label.RIGHT);
    add(numb);
    add(ch);
    add(num);
    num.addActionListener(this);
    ch.addActionListener(this)
    }

    public void actionPerformed(ActionEvent ae)
    {
    repaint();
    }
    public void paint(Graphics g)
    {
    int f=0;
    StringBuffer sb=new StringBuffer(num.getText());
    g.drawString("Number=" +num.getText(),6,100);
    }
    }

    But my confusion is...i want to display this->

    News: 1

    News: 1
    Hornets Beat Rockets, 88-79

    Link - weblink here
    Author - By BRETT MARTEL AP Sports Writer
    Reporting Place - NEW ORLEANS
    Date - December 26, 2008

    Similarly ->
    News: 2

    News: 2
    The Biggest CEO Firings of 2008

    Link - weblink here
    Author - By MATTHEW KIRDAHY
    Reporting Place - Forbes.com
    Date - Dec. 25, 2008


    That is as the News number changes in the drop down list...the News content below should change and display accordingly...Plz help!!!

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    You may want to first go through the GUI tutorials before attempting to code a GUI.

    For starters, you appear to be trying to code an applet but are initializing your code in a constructor rather than the init() method. Your code also doesn't compile as you're calling methods that don't exist for the objects that you're trying to call them on.

    Is there a reason that you're using AWT here instead of Swing for your GUI library? My own bias is to not code with AWT but to use the more robust and richer Swing platform.

    Also just curious: What is your motivation for creating this and why such an urgent hurry?

    Pete

  8. #8
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default

    Hi,

    Yes I know its not compiling and I had done this in my class to code an applet only and no idea about how to do in an init() method. So, basically, my code here is messed up....

    I also have no idea about Swing( will surely learn in a time to come) but I really need this code to run now....as its a matter of confidence. Plz help and without expecting ne delay..i need someone to organize the code and make it run.

  9. #9
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default

    Okay friends,
    I got this code now...

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;

    public class Tree1 extends JFrame
    {
    public static void main(String args[])
    {
    Tree1 frame = new Tree1(" A Tree");
    frame.setSize(200,200);
    frame.setVisible(true);
    }
    public Tree1(String title)
    {
    setTitle(title);
    DefaultMutableTreeNode root=new DefaultMutableTreeNode ("Engineering");
    DefaultMutableTreeNode style=new DefaultMutableTreeNode ("Information Technology");
    root.add(style);
    style=new DefaultMutableTreeNode("Electronics");
    root.add(style);
    style=new DefaultMutableTreeNode ("Computer Science");
    root.add(style);
    style=new DefaultMutableTreeNode ("Mechanical");
    root.add(style);
    style=new DefaultMutableTreeNode ("Electrical");
    root.add(style);
    style=new DefaultMutableTreeNode ("Sound");
    root.add(style);

    JTree jt=new JTree(root);
    Container contentPane=getContentPane();
    contentPane.add(new JScrollPane(jt));
    }
    }

    But here i am able to show only one root node and then the leaf nodes....If I have to show some more root nodes and leaf nodes under them then how do I do that?? Please help!

Similar Threads

  1. Replies: 0
    Last Post: 06-28-2008, 10:26 PM
  2. Display items in the JCombo Box
    By eddy001 in forum AWT / Swing
    Replies: 1
    Last Post: 01-21-2008, 01:27 AM
  3. To display as a list
    By yuvi461 in forum New To Java
    Replies: 2
    Last Post: 01-09-2008, 01:06 PM
  4. Adding List to MIDlet Display
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-23-2007, 03:07 PM
  5. Display program
    By nhlfan in forum New To Java
    Replies: 2
    Last Post: 11-22-2007, 01:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •