How to keep JTree always fix to location(0,0) for its MotherPanel??

Dear Friends:
I have following code,
AnimalTree.java is a JTree, AnimalTreeCall.java is a MotherPanel to add AnimalTree to it,
after I run it, it is not located at (0,0) location in AnimalTreeCall, after I resize AnimalTreeCall, AnimalTree's location will change with the size change of AnimalTreeCall.
But what I want is that
[1]. never mind how I change the size of AnimalTreeCall, AnimalTree will always fix to the location of (0,0) in AnimalTreeCall Panel,ie. fix to upper left corner;
and
[2]. AnimalTree JTree will occupy all area in AnimalTreeCall, not only part of it
How to do that??
Thanks
1. AnimalTreeCall.java
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import java.awt.GridLayout;
public class AnimalTreeCall {
     private static final long serialVersionUID = 1L;
     private           static JFrame                     frame;
     protected           static AnimalTree     animalTree ;
     private               JSplitPane sp = new JSplitPane();     
     public static void main(String args[]) {
          animalTree = new AnimalTree();
          animalTree.init();
          JScrollPane jp= new JScrollPane();
          animalTree.setPreferredSize(new Dimension(600,600));
         jp.setPreferredSize(new Dimension(600,600));
         AnimalTreeCall tc = new AnimalTreeCall();
          frame = new JFrame("test");
          frame.setBounds(0, 0, 600, 675);
          frame.setPreferredSize(new Dimension(600,600));
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         jp.setViewportView(animalTree);
          frame.add(tc.showGUI(), BorderLayout.NORTH);
          frame.add(jp, BorderLayout.CENTER);
          frame.addWindowListener(new WindowAdapter() {
                 public void windowClosing(WindowEvent e) {
                     System.exit(0);
             frame.pack();
             frame.setVisible(true);
     public JPanel showGUI() {
             JPanel jp = new JPanel();
             jp.setLayout(new GridLayout(0,30));            
             jp.setSize(15,15);
             jp.setBorder(BorderFactory.createLineBorder(Color.white));
                 return jp;
}2. AnimalTree.java
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
public class AnimalTree extends JPanel{
     private static final long serialVersionUID = 1L;
    protected           JTree                               tree;
    protected           DefaultTreeModel                model;
    protected           DefaultMutableTreeNode           rootNode;
     public AnimalTree(){
          super();
     public void init() {
         DefaultMutableTreeNode ProjectNode = getProjectTree();
         model      = new DefaultTreeModel(ProjectNode);
         tree      = new JTree(model);
         tree.setPreferredSize(new Dimension(400,300));
         add(tree, new BorderLayout().CENTER);
  private DefaultMutableTreeNode getProjectTree() {
    rootNode = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode an = new DefaultMutableTreeNode("Animal");
    rootNode.add(an);
    DefaultMutableTreeNode cat = new DefaultMutableTreeNode("Cat");
    an.add(cat);
    DefaultMutableTreeNode t = new DefaultMutableTreeNode("Tiger");
    an.add(t);  
    DefaultMutableTreeNode shark = new DefaultMutableTreeNode("Shark");
    an.add(shark);  
    DefaultMutableTreeNode p = new DefaultMutableTreeNode("Pig");
    an.add(p);  
    DefaultMutableTreeNode dog = new DefaultMutableTreeNode("Dog");
    an.add(dog);  
    DefaultMutableTreeNode bird = new DefaultMutableTreeNode("Bird");
    p.add(bird);
    DefaultMutableTreeNode hawk = new DefaultMutableTreeNode("Hawk");
    p.add(hawk);
    DefaultMutableTreeNode eagle = new DefaultMutableTreeNode("Eagle");
    p.add(eagle);
    DefaultMutableTreeNode sp = new DefaultMutableTreeNode("Sparraw");
    p.add(sp);
    DefaultMutableTreeNode mouse = new DefaultMutableTreeNode("Mouse");
    p.add(mouse);
    return rootNode;
}

Use the appropriate LayoutManager. Start by reading the Swing tutorial. I'm sure you've been given the link to the tutorial many time.
add(tree, new BorderLayout().CENTER);The above statement makes no sense.
I suggest you use a System.out.println(...) to see what the default layout manager for a JPanel is.

Similar Messages

  • How to keep Industry sector and Material Type in Display for Tcode MM01

    How to keep Industry sector and Material Type in Display for Tcode MM01( create material Initial screen)
    Thanks,

    Hi
    Yes, your requirement is possible using screen variant
    1. use tcode SHD0
    2. give transaction as MM01
    3. goto screen variant tab - assign some name - enter program name and screen name
       (from mm01 - F1 help)
    4. goto transaction variant tab - assign some name - assign already defined screen variant name
    5. goto standad variant tab - transaction variant name already fetched automatically - click on active button (it was placed after transaction variant name
    Raju

  • Awesome window manager: How to keep application always on top

    Is it possible to keep media player applications always on top ?
    Following is my current configuration.
    { rule = { class = "Vlc" },
    properties = { floating = true, ontop = true } }
    This is working fine whenever I start application. But problem is, if I go to full screen and come back, ontop flag is unset.
    Is there anyway to fix this ?

    shmibs wrote:
    you could probably do something like
    client.connect_signal("property::fullscreen", function(c)
    if c.class == "mplayer" then
    c.ontop = true
    end
    end)
    i haven't tested this, though, so don't be surprised when it fails
    This is working partially. ie, VLC is keeping ontop propery, but video is not going full screen.

  • How to keep window always on top?

    I use afloat to keep most of the window always on top but it doesn't work for some apps like excel, textwrangler etc...
    How can I make excel, textwrangler etc.. to stay on top even if I focus on some other apps?

    AFAIK, you can't. When you change focus the app assumes you want to use it.

  • How to keep remote always on

    Hi, I can't seem to find an answer.
    What I want to do is keep my iPhone always on with Remote always on, never sleeping.
    How do I acheive this?

    Hello Wjosten
    5 minutes after leaving this post, your suggestion is what I did, it simply occurred to me to never let the phone go to sleep and that solved it.
    Since you took the time to leave this post I marked as solved!
    Thanks a million for being so nice to leave a post.
    One more quick querry if I may, it's related.
    How can I get the screen to dim after a period of time. It would be nice if the iPhone screen could sleep without loosing the connection.
    PS my iPhone is always connected to power (while as a super amazing music remote - one of my favorite apps!), thanks for the gotcha!
    Best Regards

  • Outlook only works when switched to pc site. how to keep it always opens in pc site without having to switch it every time?

    cannot reply to e mail with outlook~hotmail unless it is ib pc site. can that be fixed. This is a Nexus 5 using Adroid 4.4.

    Set as favorite the link pc site

  • How did the Amex App access my location without asking for permission first?

    I just downloaded the Amex App and started using it, put in my info and logged in. Checked balances and things then logged out. After going to my settings I noticed Amex was turned on under Location Sevices and that it had accessed my location earlier. It did not ask me if I allow or not when I was logging in the App earlier. This is the first time that my location was accessed without permission from any app or safari. I realize once you allow the permission it doesn't ask again, but in my case I just downloaded the app and used it the first time. Is this how some apps may do it, without permission?  I thought Apple was big on these kinds of things? 

    My apologies about the post but in the App there was a section where it did ask for permission. It's all good. Thanks

  • How do I save to a networked location in Firefox for Linux?

    I have a a few laptops with 16 and 20 gig hard drives that I'm more or less trying to use as thin clients. All personal files are stored on a Windows 2008 server.
    When users attempt to save files with Firefox, their preferred browser, they report that they are unable to save to a network location as they cant find anything in the save window pertaining to Network or Samba, so they are unable to find the server, and have to save files to the almost full hard drives, then copy the files to the server by dragging and dropping. there has to be a way to save files directly without having to drag and drop the files by hand.

    Firefox may be trying to copy the access permissions from the temp folder that is initially used when the download is started to the destination location on the network drive and fails to do that.
    In that case you will have to copy the files yourself to that drive after you've saved the files locally.

  • Re-sizing, align right while keeping the menu fixed using flash AS2

    contact
    khuon
    mau
    My problem is recreating the align right effect while keeping
    the menu fixed using flash AS2 mostly for re sizing as well as
    different screen sizes.
    While i can do one or the other but both is just not
    happening.
    I have tried all sorts of weird and wonderful things but as
    yet, alas no easy/simple solution :(
    I must admit it has been a long time since i have been here
    but.. I thought if someone could have a quick look and maybe please
    give me a few pointers ??
    Anything at all would be better than what i have now ...
    Thanks for your time

    The link again is I forgot to add http to the link before, but it should have worked.
    http://www.lipowiec.org/test/index.php
    a) used Dreamweaver to create new site selected 1 column, elastic, centered, header, and footer
    b) used spry to add horizontal menu to header
    c) followed instructions from Spry Help
    http://livedocs.adobe.com/en_US/Spry/SDG/index.html?lang=en_US ->
    working with spry widgets -> working with the menu bar widget -> Customize the dimension of menu items as indicated
    To change the dimension of menu items by changing the width properties of the menu item’s li and ul tags.
    Locate the ul.MenuBarVertical li or ul.MenuBarHorizontal li rule.
    Change the width property to a desired width, or change the property to auto to remove a fixed width, and add the property and value white-space: nowrap; to the rule.
    Locate the ul.MenuBarVertical ul or ul.MenuBarHorizontal ul rule.
    Change the width property to a desired width (or change the property to auto to remove a fixed width).
    Locate the ul.MenuBarVertical ul li or ul.MenuBarHorizontal ul li rule.
    Add the following properties to the rule: float: none; and background-color: transparent;.
    Delete the width: 8.2em; property and value.
    Under IE it's broken, under the other browsers it works.
    There need to be more IE HACKS added.

  • I just downloaded a program, but now can not open any applications...? I can't open any files or any programs. How would I go about fixing this?

    hey, writing this from my phone. Please pardon how everything is typed.  Quick question. Just downloaded the pear square on program. But now I can not open any applications. I beloved the message that popped up was something along the lines of 'do not have permission to access" ...so... I don't know whether or not I downloaded a virus or not. I was also obviously wondering how I might go about fixing this? -Thank you for your timeo

    Pear square one program

  • HT203167 I have purchased Forbes magazine thru zinio app. My money was deducted but I am not getting the magazine for download inside zinio app. How can I get this fixed?

    I have purchased Forbes magazine annual subscription
    thru zinio app. My money was deducted but I am not getting the magazine for download inside zinio app. How can I get this fixed?

    This forum is for questions from those managing sites on iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store. You'll be most likely to get help with this issue if you ask in the general iTunes forums.
    Regards.

  • Ssrs 2008 r2 keep objects in fixed locations when report is executing

    In an exisitng SSRS 2008 r2 report there are currently 5  tablixes. Right now in one of the tablixes, I am adding rectangles and textboxes to the one tablix. As I am adding these items to the SSRS 2008 r2 report, new items that I am adding to the report
    do not stay where I placed them originally. In addition, some of the other tablixes are moving around (floating).
    Thus may questions are the following:
    1. In one particular tablix, is there a way to anchor the rectangles and texboxes (keep them from floating)? If so, would you tell me how to keep fixed point locations?
    2. For all the tablixes on the report, is there a way to keep each tablix from flaoting (staying anchored to a fixed location? If so, would you tell me how to keep the various tablixes from floating?

    Hi wendy,
    Just as you said, the location of report items would be changed depends on the data in other items and page size. There are no such property that can directly make an item stayed at a fixed location. While, if the issue is caused by the page size, we can
    change it to an appropriate page size. If the issue is caused by other item data, we can try to use a rectangle to contain those items. Because rectangle is s object container, it can keep objects together on a page and control how object move and push each
    other. For more details, please see the following document:
    http://technet.microsoft.com/library/Cc966445#XSLTsection132121120120
    Hope this helps.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • HT201210 I am trying to update my ipad 2 but it keeps telling me that it isn't eligible for the requested build how can i fix this problem

    I am trying to update my ipad 2 but it keeps telling me that it isn't eligible for the requested build how can i fix this problem

    This device is not eligible for the requested build (Also sometimes displayed as an "error 3194")
    Update to the latest version of iTunes.
    Third-party security software or router security settings can also cause this issue. To resolve this, followTroubleshooting security software issues.
    Downgrading to a previous version of iOS is not supported. If you have installed software to perform unauthorized modifications to your iOS device, that software may have redirected connections to the update server (gs.apple.com) within the Hosts file. Uninstall the unauthorized modification software from the computer.
    Edit out the "gs.apple.com" redirect from your hosts file, and then restart the computer for the host file changes to take affect. For steps to edit the Hosts file and allow iTunes to communicate with the update server, see iTunes: Troubleshooting iTunes Store on your computer, iPhone, iPad, or iPod—follow steps under the heading Blocked by configuration (Mac OS X / Windows) > Rebuild network information > The hosts file may also be blocking the iTunes Store. If you do not uninstall the unauthorized modification software prior to editing the hosts file, that software may automatically modify the hosts file again on restart.
    Avoid using an older or modified .ipsw file. Try moving the current .ipsw file (see Advanced Steps > Rename, move, or delete the iOS software file (.ipsw) below for file locations), or try restoring in a new user to ensure that iTunes downloads a new .ipsw.
    Copied from this website.
    http://support.apple.com/kb/TS3694#error3194

  • Photoshop CS4 always crash (how may I track and fix an APPCRASH) ???

    Hello
    My Photoshop CS4 always crash when happens these conditions:
    1. Open a file picture or create a file. (FILE 1)
    2. Import another file picture... (FILE 2)
    3. Copy FILE 2 in FILE 1
    4. Now FILE 2 appear inside a layer...
    5. Move with the mouse the layer corresponding to the FILE 2
    CRAAAAAAASHHHH
    BOOOOOOOOOOOOOOOOOOM
    Always happens the same, always, always.
    It is so annoying, that don't let me work and I am working right now with Photopaint (think I don't like).
    I would need your help to tell em how may I track and fix an APPCRASH.
    Do we have an application in windows that allow me to detect the causes of an APPCRASH?
    Or is this just because the application is failing?
    These are the data of the application crash:
    Signature of the problem:
    Nombre de evento de problema:    APPCRASH
    Nombre de la aplicación:    Photoshop.exe
    Versión de la aplicación:    11.0.1.0
    Marca de tiempo de la aplicación:    499bf9b5
    Nombre del módulo con errores:    StackHash_fd00
    Versión del módulo con errores:    0.0.0.0
    Marca de tiempo del módulo con errores:    00000000
    Código de excepción:    c0000005
    Desplazamiento de excepción:    65637275
    Versión del sistema operativo:    6.0.6002.2.2.0.256.1
    Id. de configuración regional:    3082
    Información adicional 1:    fd00
    Información adicional 2:    ea6f5fe8924aaa756324d57f87834160
    Información adicional 3:    fd00
    Información adicional 4:    ea6f5fe8924aaa756324d57f87834160
    Additional information about the problem:
    Id. de depósito:    1164041060
    The texts are in Spanish sorry, I'm from Spain.
    May someone help me to track and trace this bug and how to solve it?
    Thanks

    Prior to the subscription models—and of course that includes CS4—the Photoshop license was platform specific, either Windows or Mac, but not both.  Your CS4 Windows serial number ("key") will never work on the Mac version.
    CS4 is out of the loop as far as requesting a platform swap for a nominal fee.  It is no longer supported by Adobe in any way. A platform swap required the destruction of your PC version, so you could not use both the PC and the Mac versions.
    For a time, you could have used CS4 to upgrade to CS6 for about $200, but that time window has closed by now.  Now you would have to own a legitimate version of CS5 in order to be eligible to buy an upgrade to CS6.
    You can of course buy the full version of Photoshop CS6 Extended for $1,000 from the Adobe store:
    Creative Suite 6
    Alternatively, you can subscribe to Photoshop CC and Photoshop CC2014  on a monthly basis without ever owning the software.  If you stop paying monthly, the software ceases to work.
    The cheapest subscription is the Photography plan, which includes both Photoshop and Lightroom for $10 a month.
    These are user forums; you are not addressing Adobe here.  To contact Adobe support directly:
    Click on the link below, and after that click on "Still need Help? Contact us."
    Then on the next page, click Chat
    http://helpx.adobe.com/contact.html?step=PHXS_downloading-installing-setting-up_licensing- activation.
    There is also a phone option. 1 (800) 833-6687

  • How do I set a fixed page size in Muse so that the window always stays the same size

    how do I set a fixed page size in Muse so that the window always stays the same size

    Hi Aish & thanks for responding;
    I would like the window size to stay the same for the entire site and not be
    able to scale to drag & scale it. ie 950 pixels x 500 pixels.
    Thanks,
    JB
    On 12/4/14 3:30 PM, "Aishvarya Raj Rastogi" <[email protected]>

Maybe you are looking for

  • I am unable to install OS Mountain Lion

    I am unable to install OS Mountain Lion, when i try to install it says a recovery disk can not be created, visit apple.com/support/no-recovery, is there a way to fix where i can get Mountain Lion?

  • Battery not recalled? ZZ345

    I have 2 batteries for my Power Book G4 12 inch laptop. I just tried to order a replacement for both of them but one of them was rejected as not matching the list. I think it's the original one because it's marked c. 2003 whereas the matching one is

  • ITunes store seriously messed up

    The iTunes webstore is seriously messed up. Searches for popular artists don't function properly, and the links to their pages and their albums don't work. Try a search for "Strunz & Farah", Grammy-nominated artists who've sold a million records. The

  • Content Server Configuration issue

    Hi Gurus I am working on Content server configuration. Installed Content server (640 build 201 ) on Win 2003 server - Using SAP ECC 5.0 - This is initially our test environment so here we are not using any certificates I am facing issue with TXN (si2

  • HELP! MY IPOD CLASSIC WILL ONLY COME UP AS A HARD DRIVE

    Hi I connect my iPod classic (2007) to my Macbook pro and it shoes as a hard drive and doesn't connect to itunes. I have tried all sorts of things as I'm normally not stuck when it comes to Mac...however I'm stuck! I just want music on the iPod wheth