GUI run problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blackraven1425
    New Member
    • Mar 2008
    • 27

    GUI run problem

    every time I run this code, the "remove" button only shows up if there's no picture there. is there any fix for this?
    [code=java]
    while(r<list.si ze()){
    JPanel panel2 = new JPanel();
    panel2.add(getS ingle(list, isSmall, r));
    panel2.setName( ""+r);
    panel2.setPrefe rredSize(new Dimension(200,6 00));
    System.out.prin tln(panel2.getN ame());
    panel2.setVisib le(true);
    JPanel picture = new JPanel();
    ImageIcon icon = new ImageIcon(list. get(r).picture) ;
    picture.add(new JLabel(icon), "South");
    panel2.add(pict ure, "Center");
    panel2.addMouse Listener(this);
    Button remove = new Button("Remove Item");
    remove.setName( "R"+r);
    remove.addMouse Listener(this);
    panel2.add(remo ve, "South");
    panel.add(panel 2, "East");
    r++;
    }[/code]
    Last edited by Nepomuk; Aug 28 '08, 10:26 PM. Reason: Please use [code] tags
  • NaftoliGug
    New Member
    • Aug 2008
    • 13

    #2
    I don't have an exact answer to your question, but maybe it would help to clarify to things:
    1) What layout is panel2? If it's BorderLayout, the first item that you added to it without specifying a side should be in the center, and then the picture which you specify center for will replace it. That wouldn't explain why the remove button is not there, though - for that you specify south.
    2) Just a side point - it's recommended to use constants instead of strings to specify the layout constraints. panel2.add(comp onent, BorderLayout.SO UTH) or even better: pane2.add(compo nent, BorderLayout.PA GE_END). The second notation is more cross-platform because it is will follow text orientation.
    3) panel is not defined in your snippet but if for every iteration of the loop you add a different 'panel2' to panel / EAST it should replace the previous panel2 and you'll only end up with one panel2.

    Comment

    Working...