Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By sreinst1

Thread: NPE when painting JTabbedPane after setting layout policy

  1. #1
    sreinst1 is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default NPE when painting JTabbedPane after setting layout policy

    Hi,
    I work on a text editor, that uses a JTabbedPane to display the open files.
    I've added an option to set the layout policy of the tabbed pane (wrap / scroll). When changing the layout policy from wrap to scroll there's no problem - it works fine. When changing from scroll to wrap, there is an NPE (below) and the painting gets corrupted.
    Any idea how to solve (or work around) this problem?
    I use Java 1.6.0_26.
    Thanks,
    Shlomy

    Exception in thread "AWT-EventQueue-0"
    java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicTabbedPaneUI$Scrollabl eTabPanel.paintComponent(BasicTabbedPaneUI.java:34 63)
    at javax.swing.JComponent.paint(JComponent.java:1029)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JViewport.paint(JViewport.java:747)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintToOffscreen(JComponent .java:5124)
    at javax.swing.BufferStrategyPaintManager.paint(Buffe rStrategyPaintManager.java:278)
    at javax.swing.RepaintManager.paint(RepaintManager.ja va:1224)
    at javax.swing.JComponent._paintImmediately(JComponen t.java:5072)
    at javax.swing.JComponent.paintImmediately(JComponent .java:4882)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:785)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:713)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Re paintManager.java:693)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:125)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:641)
    at java.awt.EventQueue.access$000(EventQueue.java:84)
    at java.awt.EventQueue$1.run(EventQueue.java:602)
    at java.awt.EventQueue$1.run(EventQueue.java:600)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 611)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    To get better help sooner, post a SSCCE that clearly demonstrates your problem.

    Use code tags to post codes -- [code]CODE[/code] will display as
    Java Code:
    CODE
    db

    edit Does your code respect Swing's single threaded rule?
    Last edited by DarrylBurke; 07-29-2011 at 08:21 AM.

  3. #3
    sreinst1 is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks for the quick reply. Your suggested helped: I wrote a small test application to demonstrate the problem, and it didn't reproduce. Switching layout worked fine in my test application. So it must be something specific to the text editor. I cannot paste the code here as it's too large and complex. If you're interested, the code is here: SourceForge.net Repository - [jedit] Index of /plugins/BufferTabs/trunk. I will have to do some debugging.
    It uses the JTabbedPane in a bit unusual way: it uses the same component (a text area) for all tabs. It sets the text area as the component of the first tab, and any new tab gets a null component. It also adds a change handler that takes care of tab selections. Whenever a tab is selected, the text area is loaded with the file to which the tab belongs. I did something similar in my example application, but still could not reproduce the problem.
    I think it does respect Swing's single threaded rule. I've been using the Substance L&F for a while - this L&F usually catches (and forbids) any violations of this rule; I've fixed some threading errors, and Substance no longer shows any violations.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Could also be a bug in Substance, assuming that the Substance UI delegate for tabbed panes extends (directly or indirectly) BasicTabbedPaneUI. Can you run your original code with the default (Metal) L&F and see whether you still get the Exception?

    Oh and
    I cannot paste the code here as it's too large and complex.
    That would make it too large and complex for me to attempt to debug.

    db

  5. #5
    sreinst1 is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by DarrylBurke View Post
    Could also be a bug in Substance, assuming that the Substance UI delegate for tabbed panes extends (directly or indirectly) BasicTabbedPaneUI. Can you run your original code with the default (Metal) L&F and see whether you still get the Exception?

    Oh and

    That would make it too large and complex for me to attempt to debug.

    db
    I've tried also with Metal L&F, same thing.Thanks.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Look for a concurrency issue. My conclusion is that somewhere you're calling Swing methods (could even be constructors) on a thread other than the EDT.

    db

  7. #7
    sreinst1 is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks, I will. If I find something, I will post my finding here for the record.
    DarrylBurke likes this.

  8. #8
    sreinst1 is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    For the record: The problem was indeed with our usage of JTabbedPane. As I explained above, a single component (text area) is used for all tabs - it is set to one of the tabs, and all other tabs get a null component. In order to overcome some problems with this usage, the class that uses JTabbedPane in my editor used to override indexOfComponent(), and always returned the index of the text area. This caused wrong things to happen when the UI was uninstalled and then installed again, for obvious reasons - the same method indexOfComponent() is used to locate components that belong to the UI implementation and not only the components set for each tab.
    Sorry for the trouble.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Thanks for sharing the solution. Although the chances are slim that anyone will turn up with the identically flawed design, it could guide someone who searches and finds this thread to look at other aspects of his/her code.

    db

Similar Threads

  1. Setting sizes to JButtons in grid layout
    By sarah jain in forum AWT / Swing
    Replies: 8
    Last Post: 02-22-2011, 05:08 AM
  2. Custom JTabbedPane layout policy
    By Leanne182x in forum AWT / Swing
    Replies: 0
    Last Post: 02-15-2011, 12:53 PM
  3. Setting BG color of JTabbedPane tab
    By Onra in forum New To Java
    Replies: 2
    Last Post: 10-21-2010, 09:22 PM
  4. I have a problem in setting layout for panel.
    By Vin in forum AWT / Swing
    Replies: 5
    Last Post: 01-19-2010, 11:22 AM
  5. Djava.security.policy=applet.policy
    By willemjav in forum Java Applets
    Replies: 1
    Last Post: 03-09-2008, 02:57 AM

Posting Permissions

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