Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2004

Tip: Looking for answers? Try searching our database.

repainting

Thread view: 
Jeff - 02 Feb 2004 19:10 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.  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).


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.