Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Cloned Panel

Reply
Thread Tools

Cloned Panel

 
 
cdvr
Guest
Posts: n/a
 
      07-11-2007
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?

 
Reply With Quote
 
 
 
 
Sideswipe
Guest
Posts: n/a
 
      07-11-2007
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



On Jul 11, 5:15 am, cdvr <codecr...@gmail.com> wrote:
> 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?



 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-12-2007
On Wed, 11 Jul 2007 12:15:05 -0000, cdvr <> wrote,
quoted or indirectly quoted someone who said :

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Session management when browser window is cloned mikharakiri_nospaum@yahoo.com Java 11 04-26-2006 07:11 PM
dvd menu on cloned disc Pavel Ferenc DVD Video 0 11-11-2005 05:53 PM
Re: Cloned disk "thinks" it is much smaller than it is. Nomen Nescio Computer Security 2 08-13-2005 03:25 PM
Cloned disk "thinks" it is much smaller than it is. Nomen Nescio Computer Security 5 08-12-2005 08:08 PM
Virtual Access Interface not cloned from Template Matthew Melbourne Cisco 0 11-11-2003 11:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57