1

I'm working on a school project in Netbeans. Tried to build a simple GUI panel and frame with some options to draw a few objects. I started to add some new text fields and a button to let the user draw an object with some input like hight, width and quantity.

After this the program would not run anymore, it throws an exception which looks like an Illegal argument of some kind? This is the error:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid size at javax.swing.GroupLayout.checkResizeType(GroupLayout.java:354) at javax.swing.GroupLayout.checkSize(GroupLayout.java:339) at javax.swing.GroupLayout.access$500(GroupLayout.java:208) at javax.swing.GroupLayout$GapSpring.<init>(GroupLayout.java:3173) at javax.swing.GroupLayout$Group.addGap(GroupLayout.java:1550) at javax.swing.GroupLayout$SequentialGroup.addGap(GroupLayout.java:1855) at ProjectPanel.initComponents(ProjectPanel.java:322) at ProjectPanel.<init>(ProjectPanel.java:26) at ProjectFrame.<init>(ProjectFrame.java:18) at ProjectFrame$1.run(ProjectFrame.java:78) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) atjava.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:726) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) BUILD STOPPED (total time: 9 seconds) 

I tried to debug and see where this error is created but I can't seem to find a specific line.

I'm sorry to post this complete code but I can't seem to find another option to get this back running..

import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.ImageIcon; import javax.swing.JOptionPane; public class ProjectPanel extends javax.swing.JPanel { private int kind = 0; private int strandstoel; private String vliegerKleur = "Groen"; private int aantal, hoogte, breedte; public ProjectPanel() { initComponents(); repaint(); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); //Strand Color myBeach = new Color(240, 230, 140); g.setColor(myBeach); g.fillRect(0, 600, 1500, 400); //Sky Color mySky = new Color(245, 255, 250); g.setColor(mySky); g.fillRect(0, 0, 1500, 600); //SunShine if (jCheckBoxZon.isSelected()) { Color sunShine = new Color(255, 215, 0); g.setColor(sunShine); g.fillOval(500, 150, 200, 200); } else { // REGEN + DONKERE LUCHT Color darkSky = new Color(128, 128, 128); g.setColor(darkSky); g.fillRect(0, 0, 1500, 600); Color rain = new Color(30, 144, 255); g.setColor(rain); g.drawLine(100, 50, 100, 200); g.drawLine(200, 50, 200, 1); g.drawLine(300, 50, 300, 100); g.drawLine(400, 50, 400, 1); g.drawLine(500, 50, 500, 100); g.drawLine(600, 50, 600, 1); g.drawLine(700, 50, 700, 150); g.drawLine(800, 50, 800, 1); g.drawLine(850, 50, 850, 200); g.drawLine(900, 50, 900, 150); g.drawLine(1000, 50, 1000, 1); g.drawLine(1100, 50, 1100, 100); g.drawLine(1150, 50, 1150, 200); g.drawLine(1200, 50, 1200, 1); g.drawLine(1300, 50, 1300, 150); g.drawLine(1400, 50, 1400, 1); g.drawLine(1500, 50, 1500, 100); } //Zee Color seaShore = new Color(0, 191, 255); g.setColor(seaShore); g.fillRect(0, 400, 1500, 200); //Kite Color flyKite = new Color(0, 255, 127); g.setColor(flyKite); g.fillPolygon(new int[]{100, 300, 350}, new int[]{100, 300, 65}, 3); // Kinderen int x1 = 125; int x2 = 150; int x3 = 130; int x4 = 200; int x5 = 95; int x6 = 175; int x7 = 205; int y1 = 40; int y2 = 150; int y3 = 50; int y4 = 200; int y5 = 250; int y6 = 95; int y7 = 75; int y8 = 205; int y9 = 225; for (int i = 0; i < kind; i++) { g.setColor(Color.black); g.fillOval( x3,330, 40,40 ); // Hoofd g.drawLine( x2,370, y2,380 ); // Nek g.fillRect( x1,380, 50,150 ); // Lichaam g.drawLine( x2,400, y4,470 ); // R Arm g.drawLine( x4,430, y5,470 ); g.drawLine( x1,430, y1,490 ); // L Arm g.drawLine( x1,530, y6,620 ); // L Been g.drawLine( x5,620, y7,620 ); g.drawLine( x6,530, y8,620 ); // R Been g.drawLine( x7,620, y9,620 ); x1 = 100 + x1; x2 = x2 + 100; x3 = x3 + 100; x4 = x4 + 100; x5 = x5 + 100; x6 = x6 + 100; x7 = x7 + 100; y1 = 100 + y1; y2 = y2 + 100; y3 = y3 + 100; y4 = y4 + 100; y5 = y5 + 100; y6 = y6 + 100; y7 = y7 + 100; y8 = y8 + 100; } //afbeelding int tel; int xSS = 100; int ySS = 550; for (tel = 1; tel <= strandstoel; tel++) { Graphics2D g2d = (Graphics2D) g; ImageIcon strandstoel = new ImageIcon(this.getClass().getResource("/images/beach-chair.png")); g2d.drawImage(strandstoel.getImage(), xSS, ySS, null); xSS = xSS + 250; ySS = ySS + 0; } //RookPluim int teller; for (teller = 1; teller <= aantal; teller++) { g.setColor(Color.GRAY); } // Versiering Vlieger if (null != vliegerKleur) { switch (vliegerKleur) { case "Rood": g.setColor(Color.RED); g.fillOval(120, 100, 10, 10); g.fillOval(160, 95, 10, 10); g.fillOval(200, 90, 10, 10); g.fillOval(240, 85, 10, 10); g.fillOval(280, 80, 10, 10); g.fillOval(320, 70, 20, 20); g.fillOval(320, 120, 10, 10); g.fillOval(310, 160, 10, 10); g.fillOval(305, 200, 10, 10); g.fillOval(299, 240, 10, 10); g.fillOval(294, 280, 10, 10); break; case "Oranje": g.setColor(Color.ORANGE); g.fillOval(120, 100, 10, 10); g.fillOval(160, 95, 10, 10); g.fillOval(200, 90, 10, 10); g.fillOval(240, 85, 10, 10); g.fillOval(280, 80, 10, 10); g.fillOval(320, 70, 20, 20); g.fillOval(320, 120, 10, 10); g.fillOval(310, 160, 10, 10); g.fillOval(305, 200, 10, 10); g.fillOval(299, 240, 10, 10); g.fillOval(294, 280, 10, 10); break; case "Blauw": // Was normaal groen vlgs de opdracht, maar dit was niet zo goed zichtbaar g.setColor(Color.BLUE); g.fillOval(120, 100, 10, 10); g.fillOval(160, 95, 10, 10); g.fillOval(200, 90, 10, 10); g.fillOval(240, 85, 10, 10); g.fillOval(280, 80, 10, 10); g.fillOval(320, 70, 20, 20); g.fillOval(320, 120, 10, 10); g.fillOval(310, 160, 10, 10); g.fillOval(305, 200, 10, 10); g.fillOval(299, 240, 10, 10); g.fillOval(294, 280, 10, 10); break; default: break; } } repaint(); } private void jCheckBoxZonActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: repaint(); } private void jSliderKinderenMouseReleased(java.awt.event.MouseEvent evt) { // TODO add your handling code here: kind = this.jSliderKinderen.getValue(); repaint(); } private void jTextFieldAantalStoelenActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try{ strandstoel = Integer.parseInt(this.jTextFieldAantalStoelen.getText()); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Vul een getal in"); } repaint(); } private void jList1MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: vliegerKleur = this.jList1.getSelectedValue(); repaint(); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try{ aantal = Integer.parseInt(this.jTextFieldAantal.getText()); breedte = Integer.parseInt(this.jTextFieldBreedte.getText()); hoogte = Integer.parseInt(this.jTextFieldHoogte.getText()); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Vul een aantal + Hoogte en Breedte in"); } repaint(); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JCheckBox jCheckBoxZon; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JList<String> jList1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JSlider jSliderKinderen; private javax.swing.JTextField jTextFieldAantal; private javax.swing.JTextField jTextFieldAantalStoelen; private javax.swing.JTextField jTextFieldBreedte; private javax.swing.JTextField jTextFieldHoogte; // End of variables declaration } 
2
  • I'm thinking you might need to override getPreferredSize and return a valid default size Commented Dec 9, 2017 at 21:55
  • The error is at line 322 of ProjectPanel, inside its initComponent() method. But you didn't post it. Commented Dec 10, 2017 at 10:06

2 Answers 2

1

Also another possible cause for that error, which was the case for mine, is that you may unknowingly have added an element such as a JLabel, JTextField, etc. but it's very very tiny small that you are unable to recognize its presence thus while you compile it has an invalid smaller size.

To solve this, open your navigator and click on each element checking where it on the JFrame so that you can also see that tiny one.

I got it to work like that.

Sign up to request clarification or add additional context in comments.

Comments

0

Well, that error is because sometimes when you create jFrame with textBox and Labels or another component and you forgot the identifier for example label

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.