File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes SpringLayout applied to a JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SpringLayout applied to a JPanel" Watch "SpringLayout applied to a JPanel" New topic

SpringLayout applied to a JPanel

Austin Henggi

Joined: Jul 08, 2005
Posts: 10
I have a JTree which is inside a JScrollPane which is inside a JPanel that I want to put inside of a JFrame. The tree appears in the center of my frame as it should before I apply my layout. I create a springlayout and then set the layout to my FRAME. I then set up springs to add constraints on where I want my panel to appear, but no matter what I do, the panel always appears in the top right-hand corner of my screen. I am not sure why. My code is below, any suggestions?

public SimpleTree(JFrame frame, SpringLayout layout)
DefaultMutableTreeNode top =
new DefaultMutableTreeNode("The World");
JTree tree = new JTree(top);
JScrollPane treeView = new JScrollPane(tree);
treeView.setBounds(100,100, 50,50);
JPanel treePanel = new JPanel();
Spring s = Spring.constant(200,300,800);
layout.putConstraint(SpringLayout.EAST, frame, s, SpringLayout.EAST, treePanel);
layout.putConstraint(SpringLayout.WEST, frame, s, SpringLayout.WEST, treePanel);
layout.putConstraint(SpringLayout.NORTH, frame, s, SpringLayout.NORTH, treePanel);
layout.putConstraint(SpringLayout.SOUTH, frame, s, SpringLayout.SOUTH, treePanel);
I agree. Here's the link:
subject: SpringLayout applied to a JPanel
It's not a secret anymore!