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 / General / July 2007

Tip: Looking for answers? Try searching our database.

Cloned Panel

Thread view: 
cdvr - 11 Jul 2007 13:15 GMT
I am stuck....and I am sure it is simple.  Basically I have a
panel that has some stuff in it.  I want to have another panel (kind
of an overview) that shows everything in the main panel.

So I have something like:
           mainPanel = new JPanel() {
               public void paintComponent(Graphics g) {
                   super.paintComponent(g);
                   Rectangle r = mainPanel.getBounds();
                   BufferedImage bi = new BufferedImage(r.width,
r.height, BufferedImage.TYPE_INT_ARGB);
                   Graphics biG = bi.createGraphics();
                   super.paint(biG);
                   myP.setImage(bi);
               }
           };

   public static class MyPanel extends JPanel {
       private BufferedImage bi;

       public MyPanel() {
           this.bi = new BufferedImage(1, 1,
BufferedImage.TYPE_INT_ARGB);
       }

       public void setImage(BufferedImage bi) {
           System.out.println("...new image");
           this.bi = bi;
           this.repaint();
       }

       public void paintComponent(Graphics g) {
           super.paintComponent(g);
           System.out.println("bi: " + bi.getWidth() + ", " +
bi.getHeight());
           Graphics2D g2 = (Graphics2D) g;
           g2.drawImage(bi, 0, 0, bi.getWidth(), bi.getHeight(),
null);
       }

     myP = new MyPanel();

so mainPanel has all the stuff, and myP should show it as well....but
it's not working.

any ideas?
Sideswipe - 12 Jul 2007 00:25 GMT
MVC -- Model View Controller

Each panel has the same "Model" behind it. In this case, a simple
image. What you could do is create your own subclass of JPanel, create
N instances (main panel and secondary, tertiary, etc.). In the
constuctor of your JPanel add 'this' to a static list of peers. Now,
override paint (which you are doing already) and then when it's
called, invoke the paint() method on all other PEER panels (excluding
the original caller panel -- create a private method like:
paint(Graphics g,JPanel skip) paint(g,this);

Now, you have access, as a subclass, to the listenerList. Find the
correct listener for paint event, roll your own that tells peer-panels
to refresh, then add it to the existing list. That would be a way to
integrate it with the existing listener model.

Either way, listen for the change and notify all other panels of the
change.

if you found this useful, please, rate the article in google.

Christian Bongiorno
http://christian.bongiorno.org

>     I am stuck....and I am sure it is simple.  Basically I have a
> panel that has some stuff in it.  I want to have another panel (kind
[quoted text clipped - 42 lines]
>
> any ideas?
Roedy Green - 12 Jul 2007 03:11 GMT
>    I am stuck....and I am sure it is simple.  Basically I have a
>panel that has some stuff in it.  I want to have another panel (kind
>of an overview) that shows everything in the main panel.

Your problem is not clear.  Why not just display your panel "that has
some stuff in it"  as many times as you please?

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


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



©2009 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.