0

I've been working on building an MS paint like program for a class, but I've just realize that the TA marks in Linux and I've been building my program on a Mac. I didn't think it was going to be a big deal, but I thought I'd test it on a linux anyways, and I'm getting errors that won't let me even open the program.

I'm getting "main" java.lang.ArrayIndexOutOfBoundsException: No such child: 0 thrown at frame.pack(); in my main method and all over the place in Container and JComponent, ect and Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: No such child: 0thrown at Container and JComponent and BorderLayouts.

I have no idea where the problem is, so I've just put the whole program up on pasteBin. I really have no idea what I've done and I don't have any idea how to fix it. This works 100% fine on my Mac. I don't understand what the difference between the operating systems are. If anyone could please help I really need it.

http://pastebin.com/KDKm7D9w

Josephine
  • 261
  • 2
  • 10
  • 20
  • 4
    Start the UI from within the confines of the EDT, see [Initial Threads](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html); – MadProgrammer Oct 21 '14 at 04:02
  • 2
    [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/questions/7229226/should-i-avoid-the-use-of-setpreferredmaximumminimumsize-methods-in-java-swi) – MadProgrammer Oct 21 '14 at 04:03
  • 2
    Don't use `getGraphics`, this is not how painting is done in Swing, see [Performing Custom Painting](http://docs.oracle.com/javase/tutorial/uiswing/painting/) for more details – MadProgrammer Oct 21 '14 at 04:06
  • 2
    Use the `BorderLayout` constants instead of `String` literals (that is `BorderLayout.NORTH` instead of `"North"`), this way you won't be caught out if things change – MadProgrammer Oct 21 '14 at 04:08
  • 2
    You're screwing around with the `JColorChooser`, whose look and feel is likely depended on the system look and feel, these tend to change between systems, this is a REALLY, REALLY bad idea – MadProgrammer Oct 21 '14 at 04:11
  • 2
    You add the preview pane to the `bottomCC`, but, by adding it to the `colorBar`, remove it again...? – MadProgrammer Oct 21 '14 at 04:12
  • 2
    On, Windows at least, it doesn't like you doing `colourBar.add(bottomCC.getPreviewPanel());` this...which is a bad idea anyway... – MadProgrammer Oct 21 '14 at 04:14
  • I only understand about 10% of what you're saying right now -.- I've never worked with Java Swing before and I had five days to put this project together. I really had (have) no idea what I'm doing. I don't understand what I'm supposed to do to start the UI within the confines of the EDT and I don't understand why putting the preview panel in colourBar is a bad idea. – Josephine Oct 21 '14 at 04:18
  • 2
    You add the preview pane to the color chooser, you then add it to the color bar, effectively removing it from the color chooser, as a component can only have a single parent. For some reason, this is screwing up the color chooser when it comes to perform it's layout...So, don't add it to the color chooser in the first place, same result (it expect it will work) – MadProgrammer Oct 21 '14 at 04:20
  • Oh whoa you're right. Just removing the colour chooser from the toolbar fixed everything. Okay. Thanks so much. – Josephine Oct 21 '14 at 04:31

0 Answers0