1

i have one strange problem.I add scroolpane to my one of two internal frames,iset both scroobars policy to 'ALLWAYS'.Vertical works normally but horizontal shows scroolbar but not the handle to scroll.Heres is what it looks like

Problem

I think its problem in JDK but i should be wrong. I see some Threads here about this ,but no answer,maybe now someone can know. Any ideas what it can be ?

Heres a code that is about the my scrollpane

JInternalFrame waypointsFrame = new JInternalFrame("Waypoints");
mapInternalFrame.getContentPane().add(waypointsFrame, BorderLayout.EAST);

topNode=new DefaultMutableTreeNode("Top node ");
InitializeTree(topNode);
model=new DefaultTreeModel(topNode);

JTree waypointTree = new JTree(model);
waypointTree.setDropMode(DropMode.INSERT);

waypointTreeRef=waypointTree;
waypointTree.setPreferredSize(new Dimension(180, 400));
waypointTree.setMaximumSize(new Dimension(180, 500));



waypointsFrame.setVisible(true);

JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setViewportView(waypointTree);
waypointsFrame.getContentPane().add(scrollPane, BorderLayout.NORTH);
Ján Srniček
  • 505
  • 1
  • 10
  • 34
  • 1
    Difficult to tell Without any code to look at. It looks like horizontal and vertical scrollbars are messed up. I would expect the vertical one not to display a handle. Could it be that in some place of your code, horizontal and vertical got confused? – Axel Feb 17 '13 at 09:19
  • I dont know what do you mean with "confused" but i cant see any code problem .I add here only a bit of my code,where is parent component(internal frame),and the definition of scrollpane,maybe you shoud see somethink there – Ján Srniček Feb 17 '13 at 09:26
  • What happens if you leave the scroll bar policy as default? – MadProgrammer Feb 17 '13 at 09:37
  • 3
    Don't set the preferred and maximum size of the tree. Let it handle these by itself. – JB Nizet Feb 17 '13 at 09:49
  • I got it,it was in that prefered and maximum size.i set it to default and it works great.Thanks a lot – Ján Srniček Feb 17 '13 at 10:10
  • @MadProgrammer just a reminder: the _policy_ is unrelated to the scrolling _behaviour_ .. – kleopatra Feb 17 '13 at 13:24
  • More on preferred size [here](http://stackoverflow.com/q/7229226/230513). – trashgod Feb 17 '13 at 15:19
  • For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Feb 18 '13 at 22:58
  • @JBNizet Good point. See also [`JTree.setVisibleRowCount(int)`](http://docs.oracle.com/javase/7/docs/api/javax/swing/JTree.html#setVisibleRowCount%28int%29) for the height. I *generally* expand trees before adding them to the GUI, allowing the width to be better determined. – Andrew Thompson Feb 18 '13 at 23:00

0 Answers0