Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » The default getContentPane() method comes withi JFrame(JFrame)
The default getContentPane() method comes withi JFrame [message #1435070] Wed, 01 October 2014 01:36 Go to next message
Jie Li is currently offline Jie LiFriend
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.
index.php/fa/19326/0/
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.
index.php/fa/19327/0/
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 1813 times)
  • Attachment: capture_2.png
    (Size: 119.25KB, Downloaded 1791 times)
Re: The default getContentPane() method comes withi JFrame [message #1436258 is a reply to message #1435070] Thu, 02 October 2014 16:24 Go to previous message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
Adding your custom panel to the content panel should work fine.
Previous Topic:Eclipse font colors changing after WindowBuilder installation
Next Topic:Download vs update site
Goto Forum:
  


Current Time: Fri Sep 21 11:26:17 GMT 2018

Powered by FUDForum. Page generated in 0.01641 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top