View unanswered posts | View active topics It is currently Wed Apr 26, 2017 1:24 am



Reply to topic  [ 2 posts ] 
 Exception when using MigLayout on JLayeredPane, JComboBox 
Author Message

Joined: Thu Nov 22, 2012 1:19 pm
Posts: 1
Post Exception when using MigLayout on JLayeredPane, JComboBox
Hi,

I am using JDK7 and miglayout-4.0-swing.jar.

I get a IllegalArgumentException in MigLayout.setComponentConstraintsImpl() when using MigLayout on a JLayeredPane, adding a JComboBox and clicking on the arrow down of the JComboBox. A working example and the full message are attached below.

I think the JComboBox is adding another component for the drop down list and adds it silently. In a JLayeredPane this component must have the same layer index so an Integer is given automatically as ComponentConstraint. However MigLayout expects a String as Constraint and throws an exception.

When not in a JLayeredPane this doesn't fail, so MigLayout knows somehow that the additional component of the JComboBox is related to it and for example should not disturb the other components.

As a solution one might decide to not throw the exception when the component is related to something like a JComboBox and silently ignore the Integer.

Working Example:
Code:
package org.tests.miglayout;

import java.awt.Dimension;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.WindowConstants;
import net.miginfocom.swing.MigLayout;

/**
 *
 */
public class ComboBoxTest {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // create a frame
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame.setSize(new Dimension(400, 400));
       
        // and a combobox
        JComboBox<String> languageSelection = new JComboBox<>();
        languageSelection.setModel(new DefaultComboBoxModel<>(new String[]{"English", "Spanish"}));       
       
        // set miglayout to layered pane
        JLayeredPane pane = frame.getLayeredPane();
        pane.setLayout(new MigLayout());
       
        // add combobox
        pane.add(languageSelection, "pos 0.5al 0.5al", 1);
       
        // make frame visible
        frame.setVisible(true);
    }
}

Run and click on arrow to show ComboBox options.

Exeption trace
Code:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Constraint must be String or ComponentConstraint: class java.lang.Integer
   at net.miginfocom.swing.MigLayout.setComponentConstraintsImpl(Unknown Source)
   at net.miginfocom.swing.MigLayout.addLayoutComponent(Unknown Source)
   at java.awt.Container.addImpl(Container.java:1120)
   at javax.swing.JLayeredPane.addImpl(JLayeredPane.java:230)
   at java.awt.Container.add(Container.java:998)
   at javax.swing.PopupFactory$LightWeightPopup.show(PopupFactory.java:754)
   at javax.swing.JPopupMenu.getPopup(JPopupMenu.java:840)
   at javax.swing.JPopupMenu.setVisible(JPopupMenu.java:789)
   at javax.swing.JPopupMenu.show(JPopupMenu.java:959)
   at javax.swing.plaf.basic.BasicComboPopup.show(BasicComboPopup.java:208)
   at javax.swing.plaf.basic.BasicComboPopup.togglePopup(BasicComboPopup.java:1128)
   at javax.swing.plaf.basic.BasicComboPopup$Handler.mousePressed(BasicComboPopup.java:825)
   at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:280)
   at java.awt.Component.processMouseEvent(Component.java:6502)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)


Thu Nov 22, 2012 1:30 pm
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Exception when using MigLayout on JLayeredPane, JComboBo
Hello,

Thanks, the issue is put in the work queue for the next version.

Cheers,
Mikael


Sat Nov 24, 2012 4:18 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.