• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SpringLayout applied to a JPanel

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic