View unanswered posts | View active topics It is currently Wed May 24, 2017 5:18 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

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:
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.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

Run and click on arrow to show ComboBox options.

Exeption trace
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(
   at javax.swing.JLayeredPane.addImpl(
   at java.awt.Container.add(
   at javax.swing.PopupFactory$
   at javax.swing.JPopupMenu.getPopup(
   at javax.swing.JPopupMenu.setVisible(
   at javax.swing.plaf.basic.BasicComboPopup.togglePopup(
   at javax.swing.plaf.basic.BasicComboPopup$Handler.mousePressed(
   at java.awt.AWTEventMulticaster.mousePressed(
   at java.awt.Component.processMouseEvent(
   at javax.swing.JComponent.processMouseEvent(

Thu Nov 22, 2012 1:30 pm
Site Admin

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

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


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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.