• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to do this??  RSS feed

 
Michelle Wang
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends:
My project has following requirements
[1]. One splitPane has TWO separate Panels, Panel_A and Panel_B ;
[2]. Panel_A has some JLabels on it such as jlabel_1, jlabel_2, etc;
[3]. Panel_B will display some properties of jlabel_X in Panel_A, here X=1,2,3,... etc

[4]. When I click jlabel_1 in Panel_A, Panel_B will load jlabel_1's property panel etc; When I click jlabel_2 in Panel_A, Panel_B will load jlabel_2's property panel etc;

I use the code in last post MyDeletingLabels.java to implement it:

public void mousePressed(MouseEvent e) {
Point p = e.getPoint();

Component[] c = ((JPanel)e.getSource()).getComponents();
System.out.println("c.length = " + c.length);
for(int j = 0; j < c.length; j++) {
if(c[j].getBounds().contains(p)) {
if(selectedLabel != null && selectedLabel != JLabelc[j])
selectedLabel.setBorder(BorderFactory.createEtchedBorder());
selectedLabel = (JLabel)c[j];
System.out.println("mousePressed was clicked!! selectedLabel.getLabelFor()=" + selectedLabel.getToolTipText());
selectedLabel.setBorder(BorderFactory.createLineBorder(Color.red));

JLabel_1_Property lg = new JLabel_1_Property();
tpp.TabbedPaneLowPass(lg);
System.out.println("Here is JLabel_1_Property =" + lg );

}

break;
}
}
}


I hope when I press the mouse on jlabel_1, then this property panel JLabel_1_Property will be loaded, press the mouse on jlabel_2, its property panel JLabel_2_Property will be loaded, etc,
looks like not success, please advice.
Do I need ContainerListener or ComponentListener instead of mousePressed??

Thanks
[ May 27, 2007: Message edited by: Michelle Wang ]
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I need ContainerListener or ComponentListener instead of mousePressed??
A ContainerListener is for adding/removing components from a Container. A ComponentListener
is for things like resizing of a component. Neither would be useful here. A MouseListener
would do well here. You want to know when the user has clicked the mouse on a component.
 
Michelle Wang
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! success!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!