I have a Jpanel containing two JPanels, a chart and some controls. Most of
the time, I don't want the controls visible. When a user double clicks the
panel, the
controls should become visible. I can't figure out what call to use to make
the controls JPanel visible. .repaint() hasn't worked. In the following
code, the
first call to showcontrols works fine. The call from the mouseListener does
not change the screen. I'd appreciate any wisdom on how I should make the
controls appear from the mouse listener.
Thanks
public class chartPanel extends JPanel {
Mouser mouser = new Mouser();
public void main() {
boolean controlsVisible = true;
// --------- controls for real time, history, animated,
etc --------------
if ( controlsVisible ) showControls(); // puts the tivo controls at
the bottom of the panel
mouser.setMainPanel( this );
chart.addMouseListener( mouser );
} // close constructor
// adds controls to bottom of panel - controls don't appear when called
from Mouser
public void showControls() {
this.add( "South" , controls );
final JPanel panel = this;
//this.repaint();
// since repaint didn't work, I tried using invokeLater
System.out.println("scheduling repaint");
SwingUtilities.invokeLater(new Runnable() {
public void run() {
panel.repaint();
System.out.println("RePainting Later");
}
});
} // show controls
class Mouser implements java.awt.event.MouseListener {
AbstractChartPanel mainPanel;
TivoPanel controls;
public void setMainPanel(AbstractChartPanel panelArg ) {
mainPanel = panelArg;
System.out.println("Added Mouser");
}
public void mouseClicked( java.awt.event.MouseEvent e ) {
System.out.println("mouse clicked: Got mouse clicked event!");
mainPanel.showControls();
}
public void mouseEntered( java.awt.event.MouseEvent e ) {}
public void mouseExited( java.awt.event.MouseEvent e ) {}
public void mouseReleased( java.awt.event.MouseEvent e ) {}
public void mousePressed( java.awt.event.MouseEvent e ) {}
} // Mouser

Signature
Jeffrey Drew
President and Founder
Trading Metrics, Inc.
917-453-0302
Ryan Stewart - 02 Feb 2004 23:40 GMT
> I have a Jpanel containing two JPanels, a chart and some controls. Most of
> the time, I don't want the controls visible. When a user double clicks the
[quoted text clipped - 58 lines]
> public void mousePressed( java.awt.event.MouseEvent e ) {}
> } // Mouser
That code has some serious problems besides what you're trying to figure
out. If you sort it out and post some actual compilable code, someone here
might be more able (and willing) to help you. This may help:
http://www.physci.org/codes/sscce.jsp
A. Bolmarcich - 03 Feb 2004 04:35 GMT
> I have a Jpanel containing two JPanels, a chart and some controls. Most of
> the time, I don't want the controls visible. When a user double clicks the
> panel, the
> controls should become visible. I can't figure out what call to use to make
> the controls JPanel visible. .repaint() hasn't worked.
[snip]
Invoke revalidate() on the controls JPanel. If the controls JPanel is
sometimes visible and sometimes invisible, after making it invisible
but before making it visible invoke setSize(0,0) on it. This
should cause revalidate() to repaint the whole controls JPanel (even
though the contents of the controls JPanel have not changed).
Followup-to set to comp.lang.java.gui (the more appropriate of the two
newsgroups posted to).