This question is answered.


Permlink Replies: 2 - Pages: 1 - Last Post: 15-Oct-2020 13:53 Last Post By: AndreWolff Threads: [ Previous | Next ]
AndreWolff

Posts: 1,883
Registered: 14-Dec-2007
ScrollPane problem
Posted: 15-Oct-2020 10:28
 
  Click to reply to this thread Reply
I converted the FancyBox BSH GUI to Netbeans code, but the compiled version did not shown scrollbars if the window was too small to show all controls.

So I added a scroll pane at the end:
// Tabbed pane
            JTabbedPane tabs = new JTabbedPane() {
                {
                    add(generalPanel, "General");
                    add(webPanel, "Web page");
                    add(indexPanel, "Index page");
                    add(linksPanel, "Links");
                    add(slidePanel, "Slide page");
                    add(mapPanel, "Map");
                    add(musicPanel, "Music");
                    add(aboutPanel, "About");
                }
            };
            
            JScrollPane scrollPane = new JScrollPane(tabs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) {
                {
                    scrollPane.setBorder(BorderFactory.createEmptyBorder());
                    scrollPane.setOpaque(false);
                    scrollPane.getViewport().setOpaque(false);
                    add("hfill vfill", scrollPane);
                }
            };
 
            {
                add("vtop hfill vfill", tabs);
                putClientProperty("helpPage", "https://www.andrewolff.nl/SkinsManual/");
            }
 
        };
 
// Set the UI
        window.setSkinUI(ui);
        window.pack();
    }
}


This was compiled without errors in NetBeans, but after I loaded it in the skin I get a crash:
Stack trace for jAlbum 22.0.4 using skin FancyBox 3.0.0:
 
se.datadosen.util.ScriptException: java.lang.NullPointerException in onload.bsh at line number 1
	at se.datadosen.util.ScriptException.of(ScriptException.java:59)
	at se.datadosen.jalbum.AlbumBean.processScript(AlbumBean.java:2579)
	at se.datadosen.jalbum.JAlbumFrame.executeScript(JAlbumFrame.java:1282)
	at se.datadosen.jalbum.JMainSettingsPanel$5$1.run(JMainSettingsPanel.java:313)
Caused by: javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``new FancyBox(engine);    ;'' : Object constructor : at Line: 1 : in file: inline evaluation of: ``new FancyBox(engine);    ;'' : new FancyBox ( engine ) 
 
Target exception: java.lang.NullPointerException
 in inline evaluation of: ``new FancyBox(engine);    ;'' at line number 1
	at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:90)
	at bsh.BshScriptEngine.eval(BshScriptEngine.java:57)
	at java.scripting/javax.script.AbstractScriptEngine.eval(Unknown Source)
	at se.datadosen.jalbum.AlbumBean.doProcessExpression(AlbumBean.java:2636)
	at se.datadosen.jalbum.AlbumBean.processExpression(AlbumBean.java:2621)
	at se.datadosen.jalbum.AlbumBean.processScript(AlbumBean.java:2577)
	... 2 more
Caused by: java.lang.NullPointerException
	at FancyBox$1$10.<init>(FancyBox.java:2004)
	at FancyBox$1.<init>(FancyBox.java:2002)
	at FancyBox.<init>(FancyBox.java:136)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)


Line 2003 is the line starting with JScrollPane scrollPane = new JScrollPane(

What do I wrongly?

Edit:
This was ofcourse not my own code, I did copy it from Pluto, but the Pluto code
                JScrollPane scrollPane = new JScrollPane(tabs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                scrollPane.setBorder(BorderFactory.createEmptyBorder());
                scrollPane.setOpaque(false);
                scrollPane.getViewport().setOpaque(false);
                add("hfill vfill", scrollPane);
showed red lines below the last 4 lines. I could remove these ony by adding brackets as you see above.

Edit2:
I solved the crash with this code:
            JScrollPane scrollPane = new JScrollPane(tabs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) {
                {
                    setBorder(BorderFactory.createEmptyBorder());
                    setOpaque(false);
                    getViewport().setOpaque(false);
                }              
            };
 
            {  
                add("hfill vfill", scrollPane);               
                add("vtop hfill vfill", tabs);
                putClientProperty("helpPage", "https://www.andrewolff.nl/SkinsManual/");
            }
 
        };
 
// Set the UI
        window.setSkinUI(ui);
        window.pack();
    }
}
But I see no scrollbars on small windows, also not if I interchange the last 2 add statements.

Edited by: AndreWolff on 15-Oct-2020 10:47

Edited by: AndreWolff on 15-Oct-2020 10:55
davidekholm

Posts: 3,454
Registered: 18-Oct-2002
Re: ScrollPane problem
Posted: 15-Oct-2020 13:24   in response to: AndreWolff in response to: AndreWolff
Correct
  Click to reply to this thread Reply
Change the following:
            JScrollPane scrollPane = new JScrollPane(tabs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) {
                {
                    scrollPane.setBorder(BorderFactory.createEmptyBorder());
                    scrollPane.setOpaque(false);
                    scrollPane.getViewport().setOpaque(false);
                    add("hfill vfill", scrollPane);
                }
            };
 
            {
                add("vtop hfill vfill", tabs);
                putClientProperty("helpPage", "https://www.andrewolff.nl/SkinsManual/");
            }
to
            JScrollPane scrollPane = new JScrollPane(tabs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) {
                {
                    setBorder(BorderFactory.createEmptyBorder());
                    setOpaque(false);
                    getViewport().setOpaque(false);
                }
            };
 
            {
                add("vtop hfill vfill", scrollPane);
                putClientProperty("helpPage", "https://www.andrewolff.nl/SkinsManual/");
            }


I removed the "scrollPane." references from the anonymous constructor as the instance variable "scrollPane" hasn't been assigned at that point. It's also redundant. I also removed the add statement and adjusted the lower add statement to refer to the scrollPane instead of the tabs within, otherwise you're bypassing the scrollpane. It in itself contains the tabs, so you should not add the tabs again to another parent component.
AndreWolff

Posts: 1,883
Registered: 14-Dec-2007
Re: ScrollPane problem
Posted: 15-Oct-2020 13:53   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Yes, that brings up the scroll bars in small windows!

Thanks!
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums