简体   繁体   中英

GUI Won't load after changing size

In a bit of a panic. Been working on a project for the past two months. I changed a few of the box sizes a couple of days ago and saved it. Reloaded it this morning and the window size has gone stupidly small and I get the error:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JButton[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.synth.SynthBorder@ce623f,flags=288,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=Search,defaultCapable=true] is not attached to a horizontal group

Any ideas??!?!?!?!

The error message says it all. You have a certain component (a JButton ) which you have added to a vertical group but forgot to add it to a horizontal group as well in your GroupLayout . See the How to use GroupLayout part of the LayoutManager tutorial and the corresponding sample code

layout.setHorizontalGroup(
   layout.createSequentialGroup()
      .addComponent(c1)
      .addComponent(c2)
      .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
           .addComponent(c3)
           .addComponent(c4))
);
layout.setVerticalGroup(
   layout.createSequentialGroup()
      .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
           .addComponent(c1)
           .addComponent(c2)
           .addComponent(c3))
      .addComponent(c4)
);

If you would remove the addComponent(c3) part from the first line you would receive a similar exception.

Of course, without seeing your code I cannot pinpoint where exactly in your project you messed up, but a decent VCS-based diff tool to compare between those 2 versions should reveal this pretty quickly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM