I’m trying to create a simple slideshow program like Powerpoint. In order to design its GUI, I used Netbeans and, then copied the GUI code from Netbeans to Eclipse.
Netbeans generated the following code:
pg = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(153, 153, 153));
pg.setBackground(new java.awt.Color(255, 255, 255));
pg.setForeground(new java.awt.Color(255, 255, 255));
pg.setPreferredSize(new java.awt.Dimension(255, 234));
javax.swing.GroupLayout pgLayout = new javax.swing.GroupLayout(pg);
pg.setLayout(pgLayout);
pgLayout.setHorizontalGroup(
pgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 357, Short.MAX_VALUE)
);
pgLayout.setVerticalGroup(
pgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 257, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 62, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 279, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pg, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(pg, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
.addContainerGap())
);
pack();
My problem is, I want to change the jPanel1 on the right to my own class which extends JPanel. To do this, I wrote:
JPanel jPanel1 = new JPanel();
jPanel1.add(new ToolBoxGUI("ToolBox"));
But when I run the code, there are no ToolBoxGUI class buttons on the right. How should I solve this problem?
jPanel1uses a GroupLayout. To be visible, your ToolBoxGUI would have to be added to this GroupLayout. If what you want is to make the ToolBoxGUI the unique component of jPanel1, then remove the code which sets the layout of jPanel1:and replace it with
Or, if you want to replace jPanel1 with the ToolBoxGUI, remove the same code as above, and initialize jPanel1 with