This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
If you add components to (or remove from) a JComponent after it's already visible, you need to revalidate() and repaint() the JComponent. Another easy fix is to not display the user interface until it's completely finished - move the call to frame.setVisible(true) to the end.
It only shows when I remove the buttons and panel and display it on the frame
When you add the Rectangle directly to the frame it get added to the content pane which uses a BorderLayout by default. The component get added to the center which means it automatically get resized to fill the entire area of the frame.
By default a JPanel uses a FlowLayout, which displays components at their preferred size.
As Darryl suggested you did not override the getPreferredSize() method of your component so its size is 0 and it doesn't get painted. You need to implement the getPreferredSize() method to return an appropriate value.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: How to get a panel to display a button and a component?