Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default floating toolbar problem

    I have a window with a large text box. Between the right side of the text box and the right edge of the main form is a vertically oriented toolbar. I have the toolbar floatable. It works fine until I want to put it back into the form in its original place. I can pull it out and float it all over the screen. When I click the red button or try to position it back into the form, it always goes all the way to the left side of the form. I can't get it to go back to its original location on the right side of the form. What's more is that the status bar I have along the bottom of the form underneath the text box (which is really a label component) immediately repositions itself at the top of the form as soon as I pull the floating toolbar out. I see all this happen not only after building and running it but with the "Preview Design" button in the ide as well. I'm using netbeans 6.9.1. What am I doing wrong?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,569
    Rep Power
    12

    Default

    It is bound to be something in your code. So using NB is making it hard for you as the GUI designer will be generating screeds of code within which you have to find the problem.

    The API docs for JToolBar say For drag-out to work correctly, it is recommended that you add JToolBar instances to one of the four "sides" of a container whose layout manager is a BorderLayout, and do not add children to any of the other four "sides" (emph added). This suggests only having one (draggable) toolbar.

    I don't use NB much, but I had a look at what happens when you create a "new JFrame form" and add toolbars to the bottom and right. (either of the form or of a panel placed within it). The behaviour is just as you describe: when you drag out the right hand toolbar the one at the bottom jumps to the top. Looking at the "Do NOT modify this" code it appears that a GroupLayout rather than a BorderLayout is being used.

    Is the status toolbar supposed to be draggable? If not I would suggest using a BorderLayout (NB must allow for this!) and using a single draggable right hand toolbar as described in Oracle's Tutorial section on How To Use Tool Bars.

  3. #3
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    Thanks for that information. I will check into your suggestions and post again when I have results. Thanks a heap.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,569
    Rep Power
    12

    Default

    Quote Originally Posted by self
    I would suggest using a BorderLayout (NB must allow for this!)
    It does! Right click on the panel (container of the toolbars) and select Layout->Set Layout... Chose BorderLayout. Arrange your stuff (being careful that the "Inspector" reports that the right things are inside the right things - component/toolbar/panel etc). Now you have two draggable toolbars.

    -----

    Things are OK until you drag the right hand toolbar out, then move the lower toolbar to the right hand position and then close the undocked toolbar. This results in just the confusion (two toolbars in one location) that the API docs were getting at. I'm sure there is some way to support the sort of "compound" toolbars that are common in apps nowadays.

  5. #5
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    Changing to border layout made things worse for me as it rearranged my entire layout and I couldn't get it back where I wanted it. When I tried absolute layout, it resulted in the status bar remaining where it supposed to be (on the bottom) but the tool bar still refuses to go back to the right side of the screen. Any other suggestions before I pull my hair out?

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default

    Any other suggestions before I pull my hair out?
    Yes. Learn to code your GUIs yourself. It's much less trouble than learning the visual designer.
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    db

  7. #7
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    That may be an option next time but doesn't help for this project. I'm not about to start over.

Similar Threads

  1. floating point errors
    By mikele83 in forum New To Java
    Replies: 8
    Last Post: 04-24-2011, 04:52 PM
  2. Displaying floating point value
    By NuxlyStardust in forum New To Java
    Replies: 11
    Last Post: 04-14-2011, 07:40 PM
  3. Floating point inaccuracy
    By Aga in forum Advanced Java
    Replies: 6
    Last Post: 02-04-2011, 06:07 AM
  4. if it is floating point number
    By Stephen Douglas in forum New To Java
    Replies: 26
    Last Post: 07-06-2010, 10:17 AM
  5. a navigation bar that has floating images
    By shayz in forum Advanced Java
    Replies: 3
    Last Post: 02-07-2009, 02:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •