seesaw
seesaw copied to clipboard
Mig-panel and multiline text together cause NPE
Calling this function:
(defn show-sample-dialog
[]
(with-widgets [(text
:id :sample-text
:multi-line? true)
(mig-panel :id :sample-panel
:items [[sample-text "grow, push, wrap"]])]
(let [sample-dialog (dialog :content sample-panel
:option-type :ok-cancel)]
(-> sample-dialog pack! show!))))
results in very strange NPE:
java.lang.NullPointerException
at javax.swing.BoxLayout.preferredLayoutSize(BoxLayout.java:301)
at javax.swing.plaf.basic.BasicOptionPaneUI.getPreferredSize(BasicOptionPaneUI.java:270)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1651)
at javax.swing.JRootPane$RootLayout.preferredLayoutSize(JRootPane.java:917)
at java.awt.Container.preferredSize(Container.java:1788)
at java.awt.Container.getPreferredSize(Container.java:1773)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1653)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:719)
at java.awt.Container.preferredSize(Container.java:1788)
at seesaw.core.proxy$javax.swing.JDialog$Tag$a79ba523.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Container.java:1773)
at seesaw.core.proxy$javax.swing.JDialog$Tag$a79ba523.getPreferredSize(Unknown Source)
at net.miginfocom.swing.MigLayout.adjustWindowSize(Unknown Source)
at net.miginfocom.swing.MigLayout.layoutContainer(Unknown Source)
at net.miginfocom.swing.MigLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Container.java:1788)
at seesaw.core.proxy$javax.swing.JPanel$Tag$a79ba523.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Container.java:1773)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1653)
at seesaw.core.proxy$javax.swing.JPanel$Tag$a79ba523.getPreferredSize(Unknown Source)
at java.awt.GridBagLayout.GetLayoutInfo(GridBagLayout.java:1109)
at java.awt.GridBagLayout.getLayoutInfo(GridBagLayout.java:910)
at java.awt.GridBagLayout.preferredLayoutSize(GridBagLayout.java:730)
at java.awt.Container.preferredSize(Container.java:1788)
at java.awt.Container.getPreferredSize(Container.java:1773)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1653)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:719)
at java.awt.Container.preferredSize(Container.java:1788)
at java.awt.Container.getPreferredSize(Container.java:1773)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1653)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:719)
at java.awt.Container.preferredSize(Container.java:1788)
at java.awt.Container.getPreferredSize(Container.java:1773)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1653)
at javax.swing.BoxLayout.checkRequests(BoxLayout.java:483)
at javax.swing.BoxLayout.preferredLayoutSize(BoxLayout.java:300)
at javax.swing.plaf.basic.BasicOptionPaneUI.getPreferredSize(BasicOptionPaneUI.java:270)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1651)
at javax.swing.JRootPane$RootLayout.preferredLayoutSize(JRootPane.java:917)
at java.awt.Container.preferredSize(Container.java:1788)
at java.awt.Container.getPreferredSize(Container.java:1773)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1653)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:719)
at java.awt.Container.preferredSize(Container.java:1788)
at seesaw.core.proxy$javax.swing.JDialog$Tag$a79ba523.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Container.java:1773)
at seesaw.core.proxy$javax.swing.JDialog$Tag$a79ba523.getPreferredSize(Unknown Source)
at java.awt.Window.pack(Window.java:809)
at seesaw.core.proxy$javax.swing.JDialog$Tag$a79ba523.pack(Unknown Source)
at seesaw.core$pack_BANG_.invoke(core.clj:291)
at odh.ui$show_sample_dialog.invoke(ui.clj:13)
...
Deleting :multi-line? true
option removes the problem (obviously, text entry become regular instead of multi-line, which is sad :( ).
Hey. Yep. I've seen this before. It's a bug in Mig, actually. Here's a discussion: http://migcalendar.com/forums/viewtopic.php?f=8&t=3808
It looks like it was actually fixed in the last week. Do you have time to try out a newer mig version and see if it works? Otherwise, I can try to look at it this weekend.
Sure, I will try the new mig tomorrow.
Just tried Mig layout git master version. The problem has gone :) Waiting for the 4.3 version then. BTW, why you are depending on Mig v3.7.4 while there is already v4.2?
3.7.4 was the version when I added it. Glad to here 4.3 fixes it. Care to submit a pull req when it's available?
It has been at least a year and 4.3 is still not available in the maven repo. It took me a while to figure out how to use maven to build the miglayout source, and even then I had errors building miglayout-swing despite it passing validation. JavaFX is a whole other story, just skip it.
I ended up downloading the jars from here: http://typesafe.artifactoryonline.com/typesafe/repo/com/miglayout/miglayout-swing/4.3-SNAPSHOT/ , installing to a local repository using this method: http://nakkaya.com/2010/03/16/adding-custom-libraries-into-local-leiningen-repository/ and then referencing core
and swing
as dependencies like: [self/miglayout-core "4.3-SNAPSHOT"] [self/miglayout-swing "4.3-SNAPSHOT"]
and it stopped giving me the error: NullPointerException javax.swing.BoxLayout.preferredLayoutSize (BoxLayout.java:301)
Hope this helps anyone else who comes across this. If there is a better way, please let me know.
I too had this problem. I think the best solution is to just push the latest 5.0-SNAPSHOT of MigLayout to clojars as a frozen dependency. I have tested this by changing the miglayout dependency in seesaw to (after putting ["sonatype" {:url "http://oss.sonatype.org/content/repositories/snapshots"}] in the project :repositories):
[com.miglayout/miglayout-core "5.0-SNAPSHOT"] [com.miglayout/miglayout-swing "5.0-SNAPSHOT"]
Then I did lein install to install seesaw with this miglayout dependecy.
All tests pass and the bug disappears when used in my project. I don't know if @daveray would agree to this. I could upload these jars to clojars as [org.clojars.pauld/miglayout-core "5.0-20141021"] [org.clojars.pauld/miglayout-swing"5.0-20141021"] or [cawala/miglayout-core "5.0-20141021"] [cawala/miglayout-swing"5.0-20141021"]
Then seesaw could depend on it? If this sounds good, I'll upload the jars to clojars and submit a pull request.
The new miglayout at sonatype (currently 5.1) solves this issue but it is still SNAPSHOT. Not sure what the deal is. I'm currently using it in my custom seesaw dev branch for an app I'm using.
https://oss.sonatype.org/content/repositories/snapshots/com/miglayout/miglayout-swing/