JScrollPane bar alignment

I posted this to ProjectSwing forum and never got a reply, maybe here someone knows...
I tried all the suggested methods, and yet I still get the vertical scroll bar aligned somewhere in the middle when the JFrame opens, when top alignment would be preferable... Any suggestion on this is more than welcome. My code is structured with nested components like this:
JScrollPane scroll
---JPanel allJPanels
------JPanel a
---------JPanel a_1
---------JLabel a_2
---------JEditorPane a_3
------JPanel b
---------JPanel b_1
---------JLabel b_2
---------JEditorPane b_3
scroll.setViewportView( allJPanels );
Methods attempted:
scroll.getVerticalScrollBar().setValue( scroll.getVerticalScrollBar().getMinimum() );
OR
scroll.getViewport().setViewPosition( new java.awt.Point( 0, 0 ) );
OR
scroll.getVerticalScrollBar().getModel().setValue( 0 );
OR
allJPanels.scrollRectToVisible( new java.awt.Rectangle( 1, 1, allJPanels.getWidth(), allJPanels.getHeight() ) );
Thanks for any suggestion

Strangely the problem was due to how this JFrame was initialised in another JFrame with the usual .pack() and .setVisible(). By implementing Runnable and initialising with new Thread and .start() in the main application JFrame the scroll bar seemed to obey its settings and aligned correctly to the top.

Similar Messages

  • JScrollPane's scroll bar alignment

    I tried all the suggested methods, and yet I still get the vertical scroll bar aligned somewhere in the middle when the JFrame opens, when top alignment would be preferable... Any suggestion on this is more than welcome. My code is structured with nested components like this:
    JScrollPane scroll
    ---JPanel allJPanels
    ------JPanel a
    ---------JPanel a_1
    ---------JLabel a_2
    ---------JEditorPane a_3
    ------JPanel b
    ---------JPanel b_1
    ---------JLabel b_2
    ---------JEditorPane b_3
    scroll.setViewportView( allJPanels );
    Methods attempted:
    scroll.getVerticalScrollBar().setValue( scroll.getVerticalScrollBar().getMinimum() );
    OR
    scroll.getViewport().setViewPosition( new java.awt.Point( 0, 0 ) );
    OR
    scroll.getVerticalScrollBar().getModel().setValue( 0 );     
    OR
    allJPanels.scrollRectToVisible( new java.awt.Rectangle( 1, 1, allJPanels.getWidth(), allJPanels.getHeight() ) );
    Thanks for any suggestion

    Could you please explain your exact requirement. If you just want whether you have to show the scrollpane or not then there is a policy in JScrollpane in which you can set the vertical scrollbar policy as required.

  • JScrollPane bars problem Help!!!

    There is some problem with my JScrollPane
    I have added components to the JScrollPane but when components exceeds thee size of the JScrollPane the bars of the JScrollPane are not appearing. Please somebody help me... Just drag the JFrame and increase and decrease its size you will understand my problem. i cant see the remaining components because of no scroll bar.
    Here is a working code...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.*;
    public class test2 extends JFrame implements ActionListener
         JPanel mypanes = new JPanel();     
         //Main Heading 1
         JPanel p1 = new JPanel();     
         JLabel l1 = new JLabel("MEDICINE INFORMATION");
         //Medicine General Information
         JPanel genpane = new JPanel();
         JLabel genl1 = new JLabel("General Information ");     
                   //MGI (1)
                   JPanel genpane1 = new JPanel();
                   JLabel nam = new JLabel("Name:");
                   JTextField gentf1 = new JTextField(14);               
                   JLabel genname = new JLabel("Name:");
                   JTextField gen1tf1 = new JTextField(14);
                   //MGI (2)
                   JPanel genpane2 = new JPanel();
                   JLabel genname1 = new JLabel("Generic Name:");
                   JTextField gen2tf2 = new JTextField(14);
                   //MGI (3)
                   JPanel genpane3 = new JPanel();
                   JLabel genname2 = new JLabel("Manufacturers Name:");
                   JTextField gen3tf3 = new JTextField(14);
                   //MGI (4)
                   JPanel genpane4 = new JPanel();
                   JLabel genname3 = new JLabel("Classification:");
                   JTextField gen4tf4 = new JTextField(14);
                   //MGI (6)
                   JPanel genpane5 = new JPanel();
                   JLabel genname4 = new JLabel("Prescription Required:");
                   JComboBox gen5tf5 = new JComboBox();
                   //Medicine Detailed Information
                   JPanel detpane = new JPanel();
                   JPanel detp2 = new JPanel();
                   JLabel detl1 = new JLabel("Detailed Information");
                   //MDI (1)
                   JPanel detpane1 = new JPanel();
                   //MDI (2)
                   JPanel detpane2 = new JPanel();
                   JLabel detl3 = new JLabel("Common Uses:");
                   //MDI (3)
                   JPanel detpane3 = new JPanel();
                   JTextArea dettf2 = new JTextArea(8,68);
         public test2(String title)
              super(title);
              //Main Heading Panel
              p1.setLayout(new GridLayout(3,3));
              p1.setBackground(Color.white);
              p1.add(new JLabel(""));                    
              p1.add(new JLabel(""));                    
              p1.add(new JLabel(""));                              
              p1.add(new JLabel(""));                    
              l1.setFont(new Font("avant garde bk bt",Font.BOLD,20));
              p1.add(l1);          
              p1.add(new JLabel(""));
              p1.add(new JLabel(""));                    
              p1.add(new JLabel(""));                    
              p1.add(new JLabel(""));     
                   //General Information
              genpane.setLayout(new GridLayout(10,1));
              genl1.setFont(new Font("TimesNewRoman",Font.PLAIN,20));
              genpane.add(genl1);
                   //MGI (1)
                   genpane1.setBackground(Color.white);
                   genpane1.setLayout(new GridLayout(1,5));
                   genpane1.add(new JLabel(""));
                   genpane1.add(new JLabel(""));
                   genpane1.add(new JLabel(""));               
                   genpane1.add(new JLabel(""));     
                   genpane1.add(new JLabel(""));     
                   //MGI (2)
                   genpane2.setBackground(Color.white);
                   genpane2.setLayout(new GridLayout(1,5));
                   genpane2.add(nam);
                   genpane2.add(gentf1);
                   genpane2.add(new JLabel(""));
                   genpane2.add(new JLabel(""));
                   genpane2.add(new JLabel(""));
                   //MGI (3)     
                   genpane3.setBackground(Color.white);
                   genpane3.setLayout(new GridLayout(1,5));
                   genpane3.add(genname1);
                   genpane3.add(gen2tf2);
                   genpane3.add(new JLabel(""));
                   genpane3.add(new JLabel(""));
                   genpane3.add(new JLabel(""));
                   //MGI (4)     
                   genpane4.setBackground(Color.white);
                   genpane4.setLayout(new GridLayout(1,5));
                   genpane4.add(genname2);
                   genpane4.add(gen3tf3);
                   genpane4.add(new JLabel(""));
                   genpane4.add(new JLabel(""));
                   genpane4.add(new JLabel(""));
                   //MGI (5)
                   genpane5.setBackground(Color.white);
                   genpane5.setLayout(new GridLayout(1,5));
                   genpane5.add(genname4);
                   genpane5.add(gen5tf5);
                   genpane5.add(new JLabel(""));
                   genpane5.add(new JLabel(""));
                   genpane5.add(new JLabel(""));               
                   //Medicine Detailed Information               
                   detpane.setLayout(new GridLayout(1,1));
                   detl1.setFont(new Font("TimesNewRoman",Font.PLAIN,20));
                   detpane.add(detl1);                         
                   //MDI(1)
                   detpane1.setBackground(Color.white);
                   detpane1.setLayout(new GridLayout(1,5));
                   detpane1.add(new JLabel(""));
                   detpane1.add(new JLabel(""));
                   detpane1.add(new JLabel(""));
                   detpane1.add(new JLabel(""));
                   detpane1.add(new JLabel(""));
                   //MDI(2)
                   detpane2.setBackground(Color.white);
                   detpane2.setLayout(new GridLayout(1,1));               
                   detpane2.add(detl3);
                   //MDI(3)
                   detpane3.setLayout(new GridLayout(1,1));
                   detpane3.add(dettf2);
                   //Adding Heading 2
                   detp2.setBackground(Color.white);
                   detp2.setLayout(new GridLayout(1,1));     
                   detp2.add(new JLabel(""));               
                   //Adding Panels to the Main JPanel i-e genpane
                   genpane.add(genpane1);
                   genpane.add(genpane2);
                   genpane.add(genpane3);
                   genpane.add(genpane4);
                   genpane.add(genpane5);
                   genpane.add(detp2);
                   genpane.add(detpane);
                   genpane.add(detpane1);                                        
                   genpane.add(detpane2);
                   gen5tf5.addItem("Yes");
                   gen5tf5.addItem("No");                    
                   JScrollPane spp = new JScrollPane(genpane);
                   spp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                   spp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
         mypanes.setBackground(Color.white);
         mypanes.add(p1);
         mypanes.add(spp);
         setContentPane(mypanes);
         public void actionPerformed(ActionEvent ae)
         public static void main(String args[])
              test2 t = new test2("Title");
              t.setSize(800,300);
              t.setVisible(true);

    When you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read.

  • Navigation Bar Alignment Issues

    I put in a script for a navigation bar at my site. You can
    see it at: www.bonedoc.net/nindex2.html
    However, the drop down submenu for "Services" is not aligning
    up correctly. I've been over the code for the page and the css for
    an hour now and can't figure it out.
    Can anyone see what I'm missing please?
    Thanks in advance.

    Hello,
    Your service submenu div is inside the ourphysicians div.
    The positioned ourphysicians div has a class of "submenu",
    which has
    top:23px,.
    The service submenu div also with a class oif "submenu" , so
    it also has
    position top:23px.
    The problem is that it's 23px from the top of the
    ourphysicians div which it
    is in, and that div is already 23px from the top of the
    navbar.
    Positioned divs take their position from their positioned
    parent.
    You can quickly test this by changing the top value to 0 in
    the
    services_submenu CSS:
    #services_submenu { top: 0px; left: 222px; visibility:
    hidden; }
    It aligns correctly now, as it is positioned inside the very
    top of the
    ourphysicians div, so now it, too, is 23px from the top of
    the navbar.
    Just remove the service div from inside the ourphysicians div
    in the code,
    or give it a 0 top position so it's aligned at the top of the
    ourphysicians
    div it is inside.
    Take care,
    Tim
    "MCInteractive" <[email protected]> wrote in
    message
    news:gh4vuk$jku$[email protected]..
    >I put in a script for a navigation bar at my site. You
    can see it at:
    > www.bonedoc.net/nindex2.html
    >
    > However, the drop down submenu for "Services" is not
    aligning up
    > correctly.
    > I've been over the code for the page and the css for an
    hour now and can't
    > figure it out.
    >
    > Can anyone see what I'm missing please?
    >
    > Thanks in advance.
    >
    >

  • JScrollPane bars do not show

    Hi,
    I add the Panel that contains a large image to a scroll pane. However, the image is large, and the scroll bars do not show.
        JScrollPane ScrollPaneScroller = new JScrollPane();
        this.getContentPane().add(ScrollPaneScroller, BorderLayout.CENTER);
        ScrollPaneScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        ScrollPaneScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        ScrollPaneScroller.getViewport().add(PanelwithImage, null);
        PanelwithImage.setCenter(this.getWidth(), this.getHeight());Also, how to display the center of the image?

    Aw h&#101;ll...
    import java.awt.Dimension;
    import java.awt.Image;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class BigDukeImage {
      public static final String IMAGE_PATH = "http://"
          + "duke.kenai.com/nyanya/NyaNya.jpg";
      private static final Dimension SCROLLPANE_SIZE = new Dimension(900, 700);
      private static void createAndShowUI() {
        Image image = null;
        try {
          URL url = new URL(IMAGE_PATH);
          image = ImageIO.read(url);
          JLabel label = new JLabel(new ImageIcon(image));
          JScrollPane scrollpane = new JScrollPane(label);
          scrollpane.setPreferredSize(SCROLLPANE_SIZE);
          JFrame frame = new JFrame("Big Duke Image");
          frame.getContentPane().add(scrollpane);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
          JScrollBar vertSBar = scrollpane.getVerticalScrollBar();
          JScrollBar horzSBar = scrollpane.getHorizontalScrollBar();
          vertSBar.setValue(
              (vertSBar.getMaximum() - vertSBar.getVisibleAmount()) / 2);
          horzSBar.setValue(
              (horzSBar.getMaximum() - horzSBar.getVisibleAmount()) / 2);
        } catch (IOException e) {
          e.printStackTrace();
      public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
            createAndShowUI();
    }

  • JScrollPane bars to arbitrary size?

    panel.add( scrollPane, BorderLayout.CENTER );
    In my app, my panel has no components added to it besides the scrollpane above, BUT the public void paint(..) has painted a huge graphic of 8000 pixels horizontally..
    How do you set the horizontal bar of the scroll pane to be 8000 pixels?
    Thanks.

    http://forum.java.sun.com/thread.jsp?forum=1&thread=1968

  • Possible to replace jscrollpane bar with something else?

    hi,
    is it possible to change the scrollbar in a jscrollpane? i wanted to replace it with an image, is this possible? i just want to change it's look, i've see some skins but not exactly what i wanted, and i'm not sure how to make my own skin. if it's possible can someone tell me how, or point me to a place that shows how to create look and feel skins for java applications?
    Thank you.

    In JScrollPane, the calls setHorizontalScrollBar(JScrollBar horizontalScrollBar) and setVerticalScrollBar(JScrollBar verticalScrollBar) take a JScrollBar as a parameter. This means it would be much easier to use an object that extended JScrollBar.
    Here's a search of the forums for "extends jscrollbar"
    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2B%22extends+jscrollbar%22&col=javaforums

  • Responsive Navigation Bar (Alignment)

    I have my first responsive navigation bar on my page, and can not find the rule to move the (parent?) main menu item headings to the left. (I tried a couple things, some help, some didn't). I would like to move the 'Products' tab (with the others) to the left to line up with the blue border line. I need to also ensure that the subcontent displays starting same position also, and not far left of the main title/heading . (Essentially all text content left and text subcontent left lined up with the border (horz rule) line. Any help would be greatly appreciated.
    Here is site for my code: http://www.dothopper.com/
    Also two great sites I found:
    http://jquery-plugins.net/
    Great sripts/plugins
    http://tympanus.net/codrops/category/blueprints/
    Great, EASY, Quality concepts, plugins, components, layouts. Great Responsive Navigation !!

    No Notepad.  Plain vanilla is just a basic HTML page with no stylesheets attached to it other than the one you're trouble shooting.  When I looked at your page earlier, I remember seeing about 15 CSS files (some jQuery related).
    Division-itis is never a good thing.   Use HTML selectors alone or with classes. 
    /**This is applied to all h2 elements, regardless of where they appear**/
    h2 {font-size:18px}
    /**this is applied to all h2 elements that are inside the header only**/
    header h2 {margin-left: 45px }
    /**re-usable classes**/
    .red {color: #F00}
    HTML:
         <h2 class="red">This is a red, 18px heading 2</h2>
         <header>
              <h2>This is an 18px heading 2 with a margin-left of 45px</h2>
         </header>
    This article is a must read:
    http://phrogz.net/css/HowToDevelopWithCSS.html
    Nancy O.

  • JScrollPane, JPanel & Scrollable interface

    Hello,
    I recently did a little programming with a JPanel and mistakenly implemented the Scrollable interface with a JPanel when I did not need to. In the process I discovered something that has sparked my curiosity. I added a group of JLabels in a GridLayout to this Scrollable JPanel. I also set the horizontalalignment of the JLabels in the panel. When this was set the JPanel by itself rendered the Labels according to the alignment I had set. However when I put the panel in a JScrollPane, The alignment of the Labels was not rendered as I expected. The elements in the JPanel were always flush to the left, no matter what alignment I had constructed the label with.
    Does anyone know why if you descended from a JPanel and implemented the Scrollable interface with that object, when you pass the object into a JScrollPane why you would lose the alignments of the JLabels in that Scrollable JPanel?
    This is not pivotal information to me, but I am curious. If anyone knows the answer to this please let me know.
    Thanks,
    Dan Hughes

    Dan,
    I have no idea why this happens. I do know however that it is a great source of insanity when you really need to get a JScrollPane to behave itself. If ever you need to make a JPanel the client of a JScrollPane use null layout and absolute positioning, also setPreferredSize of the JPanel before adding components. When all components are added to the JPanel make the JPanel the client of a JScrollPane. Also at the very end of your code you will need this code to make the layout the scrollBars behave:
    SwingUtilities.invokeLater(new Runnable()
    public void run()
    getViewport().setViewPosition(new Point(0,0));
    JScrollPAINS were not named PAINS for no reason. This information probably seems mostly irrelevant, but if you are curious, or intend on programming in future with JScrollPane it is probably wise to keep this near by.

  • Can I move the task bar from the bottom of the screen to the RH side?  How?

    The task bar aligns across the bottom of my screen, but I'd like to move it to display vertically on the LH side of the screen.  Is this possible?  If so, how do I go about it?

    You're quite welcome. Thanks for marking question as answered.
    Drop back anytime
    Stedman

  • Help - trouble applying JScrollPane

    Hello all,
    With the code following my question I have trouble getting a scrollbar. What I get is a frame with an iteration of radiobuttons and a label (exactly what I want), but the iteration drops out of my frame without a functional scrollbar (the scrollbar drops out of the frame too). Could anyone help me out?
    BTW tempData is a Hashtable filled with Objects.
    final JFrame venster = new JFrame("yada");
    venster.getContentPane().setLayout(new BorderLayout());
    venster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p4 = new JPanel();
    p4.setLayout(new GridLayout(0, 2, 50, 5));
    JScrollPane bar = new JScrollPane(p4);
    int counter = 0;
    final String [] namen = new String[tempData.size()];
    final JRadioButton [] r1 = new JRadioButton[tempData.size()];
    final JRadioButton [] r2 = new JRadioButton[tempData.size()];
    final JRadioButton [] r3 = new JRadioButton[tempData.size()];
    final JPanel [] panels = new JPanel[tempData.size()];
    final JLabel [] vnaam = new JLabel[tempData.size()];
    for(int i = 0; i < tempData.size();i++) {
    r1[i] = new JRadioButton();
    r2[i] = new JRadioButton();
    r3[i] = new JRadioButton();
    panels[i] = new JPanel();
    for(Enumeration enu = tempData.keys(); enu.hasMoreElements();) {
    namen[counter] = ((String)enu.nextElement());
    Vak v = ((Vak)tempData.get(namen[counter]));
    vnaam[counter] = new JLabel(v.getNaam());
    ButtonGroup b = new ButtonGroup();
    r1[counter].setSelected(true);
    b.add(r1[counter]);
    b.add(r2[counter]);
    b.add(r3[counter]);
    panels[counter].add(r1[counter]);
    panels[counter].add(r2[counter]);
    panels[counter].add(r3[counter]);
    p4.add(panels[counter]);
    p4.add(vnaam[counter]);
    counter++;     
    venster.getContentPane().add(bar, BorderLayout.NORTH);
    venster.pack();
    venster.setSize(900,600);
    venster.show();

    How to use scroll panes

  • Making a Directory Structure with JTree.

    Hello,
    Can anyone boss here help me to code to make a
    File System Directory structure through JTree?
    The outlook should be like the Windows Explorer...
    From : [email protected]

    * HarishTree.java
    * Created on September 7, 2004, 2:56 PM
    * @author 120002314
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    import java.io.File;
    import java.awt.event.ActionListener;
    import javax.swing.JToolBar;
    import java.lang.System;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import javax.swing.filechooser.FileSystemView;
    public class HarishTree {
    public static void createAndShowGUI() {
    //creating a tree with drives in the toolbar
    TreeBar bar = new TreeBar();
    JScrollPane scrollpane = new JScrollPane(bar.tree);
    JToolBar toolbar = bar.CreatingTreeBar();
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(toolbar);
    // Display it all in a window and make the window appear
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("FileExplorer");
    frame.getContentPane().add(scrollpane, "Center");
    frame.getContentPane().add(panel,BorderLayout.NORTH);
    frame.setSize(400,600);
    frame.setVisible(true);
    frame.setResizable(false);
    public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    java.lang.System.gc();
    * The methods in this class allow the JTree component to traverse
    * the file system tree and display the files and directories.
    class FileTreeModel implements TreeModel {
    // We specify the root directory when we create the model.
    protected JFile root;
    public FileTreeModel(){}
    public FileTreeModel(JFile root) { this.root = root; }
    // The model knows how to return the root object of the tree
    public Object getRoot() { return root; }
    // Tell JTree whether an object in the tree is a leaf
    public boolean isLeaf(Object node) {  return ((JFile)node).isFile(); }
    // Tell JTree how many children a node has
    public int getChildCount(Object parent) {
    String[] children = ((JFile)parent).list();
    if (children == null) return 0;
    return children.length;
    // Fetch any numbered child of a node for the JTree.
    // Our model returns File objects for all nodes in the tree. The
    // JTree displays these by calling the File.toString() method.
    public Object getChild(Object parent, int index) {
    String[] children = ((JFile)parent).list();
    if ((children == null) || (index >= children.length)) return null;
    return new JFile((JFile)parent,children[index]);
    // Figure out a child's position in its parent node.
    public int getIndexOfChild(Object parent, Object child) {
    String[] children = ((File)parent).list();
    if (children == null) return -1;
    String childname = ((File)child).getName();
    for(int i = 0; i < children.length; i++) {
    if (childname.equals(children)) return i;
    return -1;
    // This method is invoked by the JTree only for editable trees.
    // This TreeModel does not allow editing, so we do not implement
    // this method. The JTree editable property is false by default.
    public void valueForPathChanged(TreePath path, Object newvalue) {}
    // Since this is not an editable tree model, we never fire any events,
    // so we don't actually have to keep track of interested listeners
    public void addTreeModelListener(TreeModelListener l) {}
    public void removeTreeModelListener(TreeModelListener l) {}
    class TreeBar implements ActionListener{
    public JTree tree = new JTree();
    public File[] roots = File.listRoots();
    JToolBar toolbar = new JToolBar();
    public TreeBar(){
    FileTreeModel model = new FileTreeModel(new JFile(System.getProperty("user.home")));
    tree.setModel(model);
    tree.setCellRenderer(new MyRenderer());
    public JToolBar CreatingTreeBar(){
    for(int i=0;i<roots.length;i++){
    JButton button = new JButton(roots[i].getPath(),new MyRenderer().inicon);
    button.addActionListener(this);
    button.setActionCommand(roots[i].getPath());
    toolbar.add(button);
    toolbar.setFloatable(false);
    toolbar.setRollover(true);
    return(toolbar);
    public void actionPerformed(java.awt.event.ActionEvent e) {
    FileTreeModel model = new FileTreeModel(new JFile(e.getActionCommand()));
    tree.setModel(model);
    class MyRenderer extends DefaultTreeCellRenderer {
    ImageIcon inicon = createImageIcon("1.gif");
    ImageIcon exicon = createImageIcon("2.gif");
    ImageIcon leaficon = createImageIcon("3.gif");
    public ImageIcon createImageIcon(String path) {
    java.net.URL imgURL = TreeIconDemo2.class.getResource(path);
    if (imgURL != null) {
    return new ImageIcon(imgURL);
    } else {
    System.err.println("Couldn't find file: " + path);
    return null;
    public Component getTreeCellRendererComponent(
    JTree tree,
    Object value,
    boolean sel,
    boolean expanded,
    boolean leaf,
    int row,
    boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    if (leaf){
    setIcon(leaficon);
    }else
    if(expanded)
    setIcon(exicon);
    else
    setIcon(inicon);
    return this;
    class JFile extends File{
    public JFile(String path){
    super(path);
    public JFile(File parent,String child){
    super(parent,child);
    public String toString(){
    FileSystem fs = new FileSystem();
    if(fs.isFileSystemRoot(this))
    return(this.getPath());
    else
    return(fs.getSystemDisplayName(this));
    class FileSystem extends FileSystemView{
    public File createNewFolder(File containingDir) throws java.io.IOException {
    return(this.createFileObject(containingDir,"harish"));

  • JScrollPane size problems with horizontal bar

    Hello,
    I have made a panel with some lines of text (JLabels). The panel is contained inside a JScrollPane. When it gets a horizontal scrollbar, the bar hides the bottom-most line of text and you get a vertical scrollbar too.
    How do I get the JScrollPane to add the height of the horizontal scrollbar to its own height if it still fits inside its own maximum height? It is ridiculous when you have like 3 lines of text inside it and you have to scroll it to see the bottom line.
    Thanks,

    Thanks, that solved the problem good enuff for me here. Now I also got another similar problem, at http://forum.java.sun.com/thread.jsp?forum=57&thread=206828. Got any ideas on that :) ?

  • Horizontal scroll bar at top in JScrollPane

    Hi,
    How can i get the horizontal scroll bar to be on the top instead of bottom
    here is my code
    TableModel tableModel = new TableModel(totalData,
    columnHeader);
    JTable table = new JTable(tableModel);
    JScrollPane scrollPane = new JScrollPane(table);
    Ashish

    Hi Ash
    I dont know whether this is feasible please sorry if i am wrong.
    Create a JPanel and add scroll bar to the left and top.
    I have posted a Q in the subject JDialog Esc Key. please answer the Q for me.
    Lakshmi.

  • Spry bar text alignment

    I need help with aligning text in main spry bar menu. Using DW 5.5, I have a 7 bank bar and 2 have 2 lines, remainder have 1. I need to BOTTOM align everything. I've look through forums, help menus, and u-tube and can not find this answer.
    I would also like to not have fixed widths, but widths varied per text length, but when I do that, obviously the 2 lined text banks turn into one line.

    To give you an idea of what I would do, have a look at the following by copying and pasting into a new document.
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Therapy To Go Home Page</title>
    <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet">
    <style>
        margin: 0;
        padding: 0;
    html {
        background: #FFF;
        height: 100%;
        color: #000;
        font: 100% Verdana, Geneva, sans-serif;
    body {
        background: #FFC;
        width: 800px;
        margin: auto;
        font-size: 0.85em;
    #header {
        height: 148px;
        background: #C2A4FF;
    #nav {
        background: #EEE;
        height: 3.6em;
    #aside {
        width: 197px;
        float: left;
        padding: 20px;
    #article {
        margin-left: 240px;
        padding: 20px;
        background: #C2A4FF;
    ul.MenuBarHorizontal li {
        font-size: 1.05em;
        width: auto;
        text-align: center;
    ul.MenuBarHorizontal a {
        background-color: #EEE;
        padding: 0.5em 1.1em;
        color: #333;
    </style>
    </head>
    <body>
    <div id="header">
    </div>
    <div id="nav">
      <ul id="MenuBar1" class="MenuBarHorizontal">
        <li><a href="#"><br>Home</a>    </li>
        <li><a href="#"><br>Services</a></li>
        <li><a href="#">Benefits &amp;<br>Contraindications</a></li>
        <li><a href="#">Common  <br>Q&amp;A</a></li>
        <li><a href="#"><br>Pricing/Hours</a></li>
        <li><a href="#">Contact/About<br>Melanie</a></li>
        <li><a href="#"><br>Resources</a></li>
      </ul>
    </div>
    <div id="aside">
    <h2>This is the sidebar</h2>
    </div>
    <div id="article">
    <h1>This is the main article</h1>
      <p>Consectetur adipisicing elit, in reprehenderit in voluptate excepteur sint occaecat. Ullamco laboris nisi ut enim ad minim veniam, velit esse cillum dolore. Mollit anim id est laborum. Sed do eiusmod tempor incididunt qui officia deserunt cupidatat non proident.</p>
      <p>Quis nostrud exercitation in reprehenderit in voluptate lorem ipsum dolor sit amet. Ut aliquip ex ea commodo consequat. Velit esse cillum dolore mollit anim id est laborum. Consectetur adipisicing elit.</p>
      <p>Ut enim ad minim veniam, ullamco laboris nisi duis aute irure dolor. Eu fugiat nulla pariatur. Qui officia deserunt in reprehenderit in voluptate cupidatat non proident.</p>
    </div>
    <script>
    var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1");
    </script>
    </body>
    </html>
    Gramps

Maybe you are looking for