Results 1 to 5 of 5
  1. #1
    doru.chiulan is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Problems with Swing JLayer (calling repaint() doesn't update my layerUI)

    Hy folks, it's my first post here, i hope i fill find a solution for my problem because it gives me headaches.

    Ok i'll try to explain my problem correctly.

    What i am trying to do: Make a Animated Busy Indicator like this one from the Java Turorial (see bottom of the page)Click Here.

    ok, i changed the original signature of the WaitLayerUI class like this :
    Java Code:
    class WaitLayerUI extends LayerUI<ListViewCell> implements ActionListener {}
    You can see also what ListViewCell is.
    Java Code:
    class ListViewCell extends JPanel implements ListCellRenderer
    The problem i have starts in this method of the WaitLayerUI
    Java Code:
    @Override
      public void applyPropertyChange(PropertyChangeEvent pce, JLayer l) {
        if ("tick".equals(pce.getPropertyName())) {
          l.repaint();
        }
      }
    the repaint() method call should call the WaitLayerUI's "paint(Graphics g, JComponent j)" when a "tick" event occurs and some changes should occur (the indicator should spin).
    The problem is that my paint method is called only once. and i don't understand the problem.
    I have to mention that the event arrives every tick so the repaint() is called every "tick", the problem is what repaint does.
    That JLayer and LayerUI are created and instantiated in this method of my ListViewCell
    Java Code:
     public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        WaitLayerUI layerUI = new WaitLayerUI();
        JLayer<ListViewCell> jlayer = new JLayer<ListViewCell>(this, layerUI);
    }
    I can't understand why repaint doesn't call the paint method every "tick"

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Problems with Swing JLayer (calling repaint() doesn't update my layerUI)

    To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

    the repaint() method call should call the WaitLayerUI's "paint(Graphics g, JComponent j)"
    What if it does? The renderer has already done its job.
    Java Code:
    class ListViewCell extends JPanel implements ListCellRenderer
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    doru.chiulan is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Re: Problems with Swing JLayer (calling repaint() doesn't update my layerUI)

    Quote Originally Posted by DarrylBurke View Post
    To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.


    What if it does? The renderer has already done its job.
    db
    So the problem is that after the first paint is done, the panel is returned by the renderer to the JList as it was after the first paint and the layer is updated but not rendered again in the JList?

    I will try to post a SSCCE soon.

    PS. Ok seems that's the problem, i am looking now for solutions for adding an animated JLayer to a JList Cell.
    Last edited by doru.chiulan; 07-27-2012 at 10:57 PM.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Problems with Swing JLayer (calling repaint() doesn't update my layerUI)

    You will need to repaint() the component that uses the renderer -- in this case, the JList.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    doru.chiulan is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Re: Problems with Swing JLayer (calling repaint() doesn't update my layerUI)

    Thank you for your help. I solved my problem :D, You can close this thread.

Similar Threads

  1. Problems with LayerUI on Mac
    By pete051 in forum New To Java
    Replies: 4
    Last Post: 02-14-2012, 08:51 PM
  2. Replies: 3
    Last Post: 11-20-2011, 05:50 PM
  3. panel wont update when repaint is called
    By yemista in forum AWT / Swing
    Replies: 3
    Last Post: 10-25-2011, 06:58 PM
  4. Java Swing repaint
    By sz20b in forum Advanced Java
    Replies: 1
    Last Post: 10-04-2010, 02:59 PM
  5. Repaint calling Statement Doesn't Work in my code ?
    By nitin_daviet88 in forum CLDC and MIDP
    Replies: 2
    Last Post: 07-24-2010, 03:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •