The default getContentPane() method comes withi JFrame [message #1435070] |
Wed, 01 October 2014 01:36 |
Jie Li Messages: 1 Registered: October 2014 |
Junior Member |
|
|
Hello, I am new to the WindowBuilder and I have been struggling with the default getContentPane() method comes with the JFrame.
I first create a class which extends the JFrame. Below is the code from the code view which is actually empty.
import javax.swing.JFrame;
public class StringFrame extends JFrame {
public StringFrame() {
}
However, from the design view, there is a default getContentPane() method. See image below.
I don't know where this getContentPane() method is coming from and I can't delete it (In code view, there is nothing as you can see above). This getContentPane() method prevents me from using my own panel. From example, I have created another class which extends JPanel. See code below
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.SpringLayout;
import javax.swing.JButton;
public class StringPanel extends JPanel {
public StringPanel() {
setBackground(new Color(204, 51, 255));
SpringLayout springLayout = new SpringLayout();
setLayout(springLayout);
JButton btnNewButton = new JButton("New button");
springLayout.putConstraint(SpringLayout.NORTH, btnNewButton, 138, SpringLayout.NORTH, this);
springLayout.putConstraint(SpringLayout.WEST, btnNewButton, 180, SpringLayout.WEST, this);
add(btnNewButton);
}
}
Then I tried to use this panel in the frame I have created. See the code below.
import javax.swing.JFrame;
public class StringFrame extends JFrame {
public StringFrame() {
StringPanel currentPanel=new StringPanel();
this.setContentPane(currentPanel); //I have also triedthis.getContentPane().add(currentPanel);
}
}
However, from the design view, nothing happened.
Can someone help me understand if there is anything wrong with my code above or how can I delete this getContentPane() method? Thanks
-
Attachment: Capture.PNG
(Size: 54.78KB, Downloaded 3906 times) -
Attachment: capture_2.png
(Size: 119.25KB, Downloaded 3492 times)
|
|
|
|
Powered by
FUDForum. Page generated in 0.02984 seconds