I have trouble with adding a menu bar to my layout using Java Swing. Each time a drag the menu bar from the Swing menus I receive this message (See link). I've tried adding a panel and changing to boarder layout, even updated my JDK. This is the first component I'm trying to add to my layout. Can't really understand what's wrong. Any ideas? screenshot here
Asked
Active
Viewed 251 times
1
-
Not sure about through the IDE but programmatically you can se these links: https://stackoverflow.com/a/13366959/11330114 or https://stackoverflow.com/a/12543334/1133011 – David Kroukamp Nov 05 '20 at 14:34
-
Not sure if it's the same problem. Added a screenshot to my question now! It says "The following exception has been thrown during painting the form. Use the navigator window to fix or remove the problematic components. – NewToThis Nov 05 '20 at 14:54
-
2Don't use the IDE to generate your form. You are spending time learning the IDE and not learning Java/Swing. Write the layout code manually. It will be easier to understand and easier to maintain. Read the section from the Swing tutorial on [How to Use Menus](https://docs.oracle.com/javase/tutorial/uiswing/components/menu.html) for working examples you can download and modify. – camickr Nov 05 '20 at 14:57
-
@camickr Using the IDE is a perfectly valid way to generate a simple GUI. Yes, it may not be as flexible or efficient, but there are advantages, especially when prototyping. – thetechnician94 Nov 05 '20 at 14:58
-
Thanks @camickr but my school requires us to use the IDE. But I'll try look into the code as well in my spare time. – NewToThis Nov 05 '20 at 15:06
-
2@thetechnician94 I didn't say don't use the IDE. I suggested you don't use the IDE to generate Swing components and frames. The IDE helps with debugging and organization of classes and method creation etc. People who asks questions use the IDE to generated code because they don't understand Swing. People who answer questions don't use the IDE to generate code. I prefer to learn Swing first and the IDE second. Then once you understand how Swing works, yes you can use the IDE for quick prototyping but you don't learn anything as a beginner if you depend on the IDE. – camickr Nov 05 '20 at 15:19
-
@camickr "Don't use the IDE to generate your form." I use the IDE to generate code. I started with the IDE and learned swing from it. Not everyone learns the same way. Don't knock someone else's way of learning just because it doesn't work for you. – thetechnician94 Nov 05 '20 at 15:24
-
2@thetechnician94, I'm giving advice based on my decade of answering questions in the forum and the recommendations of other Swing developers. The OP may not be aware of other options for developing a Swing application and what others have found helpful. The advice was not for you. If you don't like the advice, then fine, provide an answer for the OP. I gave advice and links on how to implement the advice if they so choose. – camickr Nov 05 '20 at 15:31
-
@camickr My problem was with the content of what you said, but the way you said it. To me it didn't seem like a suggestion, but more of a "this is not the way you should do this in any instance" kind of comment, which I disagreed with. But this comment thread is already too long and off topic, so I'll leave it there. – thetechnician94 Nov 05 '20 at 15:55
-
2I think the best analogy is as a bicycle mechanic it's perfectly fine if you can only ride a tricycle. But you only begin to understand things better when you take the training wheels off. Otherwise years down the line you are still learning the basics of the 2 wheeled beast. – David Kroukamp Nov 05 '20 at 16:41
1 Answers
0
Try changing the Look and Feel of Netbeans itself.
- Click Tools
- Options
- Appearance
- Look and Feel
- Nimbus or Metal (or anything else probably).
To me it seems that the Apple LAF isn't compatible...

thetechnician94
- 545
- 2
- 21
-
Thank you @thetechnician94! I switched the Look and Feel back to Mac OSX and now the menu bar works fine!! I would never have thought of it! – NewToThis Nov 05 '20 at 15:58
-
@NewToThis I'm glad to hear it! To be honest I thought it was a stretch anyway. In case you didn't know, you can accept an answer if it solved it for you. This helps future users to know what solution ended up working. Have a good one! – thetechnician94 Nov 05 '20 at 16:02
-