aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SpringLayout applied to a JPanel" Watch "SpringLayout applied to a JPanel" New topic
Author

SpringLayout applied to a JPanel

Austin Henggi
Greenhorn

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");
CreateNodes(top);
JTree tree = new JTree(top);
tree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
JScrollPane treeView = new JScrollPane(tree);
treeView.setHorizontalScrollBarPolicy(
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
treeView.setVerticalScrollBarPolicy(
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
treeView.setBounds(100,100, 50,50);
JPanel treePanel = new JPanel();
treePanel.add(treeView);
frame.setLayout(layout);
treePanel.setBounds(100,100,50,50);
frame.getContentPane().add(treePanel);
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: http://aspose.com/file-tools
 
subject: SpringLayout applied to a JPanel