2

I am creating a class that acts as a container which holds a label and buttons. I want the buttons to only appear when I mouseover the label on a new layer, and be clickable, but this is not my question (I have discovered OyverLay Layout and JLayeredPane for this purpose, and I will figure that out later). Like I said I plan to use JLayeredPane vs regular JPanel (because of it's multi layer abilities) most likely, but my first question is this the correct type of container to use if this class will instantiate objects onto another classes JFrame container? I don't think it is because as a panel it creates a window with a title bar and buttons, and I don't want that. I just want this class to instantiate a box with my label and buttons and add it to a JFrame to be in a grid with other buttons???

My main issue is, I want this container that holds the label and buttons to be added to a JFrame that is apart of a class who's main job is to hold the containers from my first class and have the user be able to add more and remove via a UI.

Essentially I want a form with text boxes and a button, and the button adds a new ListItem object to the JFrame of another class and the new objects label text is built form the text boxes, instantiating a new object on that JFrame. So, if I hit the button 5 times I'll see 5 boxes with 5 labels in them with unique words one right on top of the other.

I have looked into using the root container, using JInternalFrames, and tried every other magic tricks but can't seem to get it to work right.

Here is the code for the class I have built.

*above this in my class is the importing of the objects I need, and the creation of various strings, buttons and labels used here. what I have pasted here is the meat of my code, the object which is created and displayed when instanciated***

public ListItem(String nameC, String timeC, String recordNum)
{
    JLayeredPane panel1 = new JLayeredPane();
    name = nameC; time = timeC; recordN = recordNum;
            //fullItemString is a String object
    fullItemString = "Help " + name + " at " + time + " regarding " + "Record # " + recordNum;
            //item is a label
    item.setText(fullItemString);
    item.setFont(verdana);

    minusButton.putClientProperty("JButton.buttonType", "square");
    exportButton.putClientProperty("JButton.buttonType", "square");
    editButton.putClientProperty("JButton.buttonType", "square");

    // setSize(425, 50);
    //setDefaultCloseOperation(EXIT_ON_CLOSE);

    minusButton.setBounds(175, -1, 35, 30);
    editButton.setBounds(210, -1, 35, 30);
    exportButton.setBounds(130, -1, 35, 30);

    panel1.add(minusButton);//, new Integer(2));
    panel1.add(top);//, new Integer(1));
    panel1.add(editButton);//, new Integer(3));
    panel1.add(exportButton, new Integer(4));

    minusButton.addActionListener(this);
    item.addMouseListener(this);

    exportButton.setVisible(false);
    minusButton.setVisible(false);
    editButton.setVisible(false);

    lp.setVisible(true);
    setVisible(true);
}
jzd
  • 23,473
  • 9
  • 54
  • 76
harveytech
  • 207
  • 1
  • 3
  • 7
  • See this [example](http://stackoverflow.com/questions/4128432/auto-populate-a-jtextfield-with-netbeans/4130167#4130167). – trashgod Aug 02 '11 at 04:48

1 Answers1

1

Multiple panel adding in JFrame using CardLayout. try it...

Mohammed Aslam
  • 995
  • 9
  • 14
  • Hi aslu - thank you for the recommendation - looking at the Java Tutorials on CardLayout reminded me of it when I studied it in school - and it actually gave me an idea of changing my layout to a card/tabbed layout instead of my idea. However, regarding how I initially wanted to do it, the CardLayout wouldn't work based on it's description on Java Tutorials because you can only show one pane at a time. If anyone has any ideas on my initial question the would be great, but I'm going to build a tabbed layout and see if I like it. Thanks again – harveytech Aug 02 '11 at 21:51