🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
3 messages
3 total messages Started by Alex Stylianos Tue, 14 Sep 2004 06:02
CardLayout
#1019
Author: Alex Stylianos
Date: Tue, 14 Sep 2004 06:02
24 lines
1693 bytes
Hi all

I suppose this must be a common problem but I cannot find a good solution:

I am using JDK 1.4.2_01-b06 and the problem is that I cannot have a 
CardLayout switch cards properly.
There are no errors reported by JBuilder but the CardLayout does not update 
as it should. I have tried switching panels with the following 3 different 
ways:

1) ((CardLayout)pnMain.getLayout()).show(pnMain, pn);  // where pn is the 
name of the new panel

2) explicitly hidding all cards and showing the one that should be in front

3) starting a JTimer with an interval of 3 seconds (3000 msec) in order to 
avoid the collision of multiple repaint() calls

nothing seems to work as it should

is this a known problem? or what am I missing??

TIA
Alex 
Re: CardLayout
#1020
Author: Alex Stylianos
Date: Tue, 14 Sep 2004 06:54
51 lines
2652 bytes
"Alex Stylianos" <alex@dreamedge.com> wrote in message 
news:41468990@newsgroups.borland.com...
> Hi all
>
> I suppose this must be a common problem but I cannot find a good solution:
>
> I am using JDK 1.4.2_01-b06 and the problem is that I cannot have a 
> CardLayout switch cards properly.
> There are no errors reported by JBuilder but the CardLayout does not 
> update as it should. I have tried switching panels with the following 3 
> different ways:
>
> 1) ((CardLayout)pnMain.getLayout()).show(pnMain, pn);  // where pn is the 
> name of the new panel
>
> 2) explicitly hidding all cards and showing the one that should be in 
> front
>
> 3) starting a JTimer with an interval of 3 seconds (3000 msec) in order to 
> avoid the collision of multiple repaint() calls
>
> nothing seems to work as it should
>
> is this a known problem? or what am I missing??
>
> TIA
> Alex
>

perhaps I should add that I have created my own version of JPanel because I 
want to have background images so I needed to override the paint() method.. 
the code for paint() is here (although I don't think it makes any difference 
for the problem):

  public void paint(Graphics g) {
    if (tracker != null && image != null) {
      if ((tracker.statusAll(false) & MediaTracker.ERRORED) != 0) { }
      else if (tracker.statusID(imageID, true) == MediaTracker.COMPLETE) {
        int x = 0, y = 0;
        while (y < getSize().height) {
          x = 0;
          while (x < getSize().width) {
            g.drawImage(image, x, y, this);
            x += image.getWidth(null);
          }
          y += image.getHeight(null);
        }
      }
    }
    super.paint(g);
  }
Re: CardLayout
#1023
Author: John McGrath [TeamB]
Date: Tue, 21 Sep 2004 01:46
57 lines
3307 bytes
On 9/14/2004 at 2:54:02 AM, Alex Stylianos wrote:

Sorry you have not gotten an earlier response.  Many Borlanders and TeamB
members were at BorCon last week, and most TeamB members attended the
annual TeamB conference after that.

> > I am using JDK 1.4.2_01-b06 and the problem is that I cannot have a 
> > CardLayout switch cards properly.

> > I have tried switching panels with the following 3 different ways:

> > 1) ((CardLayout)pnMain.getLayout()).show(pnMain, pn);  // where pn is
> > the name of the new panel

This is the correct way to switch panes with a CardLayout.

> perhaps I should add that I have created my own version of JPanel
> because I want to have background images so I needed to override the
> paint() method..  the code for paint() is here (although I don't think
> it makes any difference for the problem):
> 
>   public void paint(Graphics g) {

I am not sure if this is your problem, but this is not the normal way to 
do painting in a Swing application.  In general, you should override the
paintComponent() method rather than the paint() method.  paintComponent()
is responsible for painting just the main part of the JComponent, whereas
paint() handles lots of other things like painting the background,
borders, child components, etc.

>     if (tracker != null && image != null) {
>       if ((tracker.statusAll(false) & MediaTracker.ERRORED) != 0) { }
>       else if (tracker.statusID(imageID, true) == MediaTracker.COMPLETE)

This logic should not be necessary in most cases and it may be interfering
with the proper painting of the component.  The
ImageProducer/ImageObserver infrastructure automatically deals with
waiting for the image to load and painting when it is has loaded.
Normally, all you need to do is to call drawImage().

>     super.paint(g);
>   }

When you override painting-related methods (e.g. paint, paintComponent),
you do want to call the superclass method from your override method, but
you should do this *first*, not last.  Since the default implementation of
paint() paints the background under most circumstances, it will end up
painting over anything that you paint before it is called.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads