Parent Component

I am trying to find a way to standardize the positions of all my components on my frame so that if I change the size of my frame, the position of eveyrthing will be ok in relation to eachother.
As it is, I am using a very inefficient method of passing the JFrame int dimensions to each component, and then each of those components pass those ints to their children, etc etc.
I know there must be a way to get the dimensions of the highest level component, but I can't find it.
Is anyone familiar with this?
Thanks
Jeremy

You can call the Component method getParent on a component to get a reference to its parent Container. You can use this as many times as you need to move up the component hierarchy in search of a target component, eg, a JScrollPane. And, of course, you can call getBounds on any of these components along the way. To get a reference to a top-level container you can use the JComponent method getTopLevelAncestor or the SwingUtilities method windowForComponent.
To investigate a containers children there are a number of Container methods including getComponents.
You can navigate just about anywhere with these simple methods and a little ingenuity.

Similar Messages

  • Calling a method in Parent component from Title Window

    Hi all,
    I have a parent component that opens up a Title window when I
    click a button. Now I want to call a method in that parent
    component from the Title window. How do I do this in Flex? Could
    anyone give me a hint please.
    Thank you in advance for the help

    "happybrowndog" <[email protected]> wrote in
    message
    news:gctmql$4t5$[email protected]..
    > That's goddamned ridiculous. What were Flex developers
    thinking that you
    > have
    > to write a custom event to call back to a parent
    component?? Other GUI
    > libraries such as WxWidgets, Fox, Qt, Delphi, MFC,
    WinForms, etc., all
    > allow
    > you to either call via a reference to the parent object
    or submit a
    > callback
    > function into the child object. That's just basic OO
    programming. Flex
    > is
    > looking more and more ridiculous and more like Swing -
    tons of unnecessary
    > coding to do simple things.
    You absolutely _do_ have the capability to pass in a
    reference to the parent
    component, or to create a "hard" reference to
    Application.application. But
    these are not recommended practices, because anything you
    create this way is
    then tied to an environment that implements those properties
    and methods.
    Q (3): I want to run a function in my main application from
    inside my
    custom component. But when I try to refer to myFunction() in
    that
    component, I get a compile time error Call to a possibly
    undefined function
    myFunction. How can I fix this?
    A: Your component has its own scope, so it doesn't know
    anything
    about the functions in the main file. You can get around this
    by directly
    referencing the main application scope like this:
    Application.application.myFunction(). However, this makes
    your component
    tightly coupled, which is a quick way of saying that your
    component is only
    usable in an application that has a myFunction() function in
    it. You're
    better off dispatching an event from your component and
    letting the
    application decide how to handle it. For more information,
    check out the
    following resources:
    http://www.adobe.com/devnet/flex/articles/loose_coupling.html
    http://www.adobe.com/devnet/flex/articles/graduating_pt1.html
    From
    http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf

  • Is it possible to call a function in a parent component from a child component in Flex 3?

    This is probably a very basic question but have been wondering this for a while.
    I need to call a function located in a parent component and make the call from its child component in Flex 3. Is there a way to access functions in a parent component from the child component? I know I can dispatch an event in the child and add a listener in the parent to call the function, but just wanted to know if could also directly call a parent function from a child (similar to how you can call a function in the main mxml file using Application.application). Thanks

    There are no performance issues, but it is ok if you are using the child component in only one class. Suppose if you want to use the same component as a child to some bunch of parents then i would do like the following
    public interface IParentImplementation{
         function callParentMethod();
    and the parent class should implement this 'IParentImplementation'
    usually like the following line
    public class parentClass extends Canvas implements IParentImplementation{
              public function callParentMethod():void{
         //code
    in the child  you should do something like this.
    (this.parent as IParentImplementation).callParentMethod();
    Here using the Interfaces, we re decoupling the parent and the child
    If this post answers your question or helps, please mark it as such.

  • Component initialization when used by parent component

    Hi everybody
    I have 'parent' and 'child' components.
    View V1 belongs to child and, upon receiving an inplug, performs a specific view controller method InitView performing activities such as executing controller methods to populate its context depending on the plug parameters.
    V1 belongs to Window W1 as default view.
    child is used in parent component and the child W1 interface view is used in a navigation step in parent.
    Parent view V2 should fire an outbound plug towards the W1 interface view which should handle the related inbound plug calling V1's InitView method.
    In order to achieve this, I assume I should declare V1 view controller as required controller in W1 interface view controller. However this is not possibile afaik.
    Any suggestion? Should I move the InitView method within the child component/custom controller?
    Thanks
    Vincenzo

    Hi,
    how does the page source look ?
    Frank

  • Get parent component

    Hi all,
    Is there any method to get parent component (container) of a jcomponent?

    Did you think to look at the API? Some method names are obvious. Other are not. The least you can do is try. All you had to do was find any method with the word "parent" in it.

  • Restrict Movement of JDialog in Parent Component

    I have created a non-modal JDialog. I would like to restrict the movement of the JDialog so that it cannot be moved outside the bounds of its parent component. Help is appreciated!
    lissa7613

    You could use a JDesktopPane with JInternalFrames, this is their default behaviour. Read this section from the Swing tutorial on "How to Use Internal Frames":
    http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html
    Otherwise, you would have to add a ComponentListener to the JDialog. Whenever the JDialog is moved, you would check its location and if it is outside the bounds of the parent frame then you would reset its location. Here is a tutorial on "Using a Component Listener":
    http://java.sun.com/docs/books/tutorial/uiswing/events/componentlistener.html

  • How do you access parent component from a child in Flex 4?

    Suppose I have a Component A (as a Spark Group) that generates an event, eventX.  Inside Component A, I add Component B (also a Spark Group) that wants to add itself as an event listener for eventX.  How do I access Component A from Component B to register for the event?
    For reference, this relationship should be similar to the MVC pattern where Component B is the view, and Component A is the model and controller.
    If I were implementing this in ActionScript, I'd have no problem coding this.  However, I am using flex, and am still trying to figure out how the FLEX API works.

    GordonSmith wrote:
    B could "reach up" to A using the parentDocument property. Or you could set a reference-to-A onto B.
    Gordon Smith
    Adobe Flex SDK Team
    B could "reach up" to A using the parentDocument property
    Would you mind explaining that?
    set a reference-to-A onto B.
    That is something I am trying to avoid.  I do not want to create tightly coupled code.
    Here is a generic form of the code I am using.  Feel free to tell me what I'm doing wrong in your explanation of how B can "reach up" to A.  Thanks!
    Component A
    <?xml version="1.0" encoding="utf-8"?>
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx" width="837" height="733"
                     creationComplete="componentA_creationCompleteHandler(event)"
                     xmlns:components="components.*">
         <fx:Script>
              <![CDATA[
                   import mx.events.FlexEvent;
                   public static const STATE_CHANGED:String = "stateChanged";
                   private var currentModelState:String;
                   protected function componentA_creationCompleteHandler(event:FlexEvent):void
                        changeModelState("second");
                   public function changeModelState(newState:String):void
                        if (newState != currentModelState)
                             currentModelState = newState;
                        dispatchEvent(new Event(IP_Dragon.STATE_CHANGED));
                   public function getModelState():String
                        return currentModelState;
              ]]>
         </fx:Script>
         <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
         </fx:Declarations>
         <components:Component_B id="b" x="0" y="0"/>
    </s:Group>
    Component B
    <?xml version="1.0" encoding="utf-8"?>
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:components="components.*"
               width="837" height="733" contentBackgroundAlpha="0.0" currentState="first"
               creationComplete="componentB_creationCompleteHandler(event)">
         <fx:Script>
              <![CDATA[
                   import mx.events.FlexEvent;
                   protected function componentB_creationCompleteHandler(event:FlexEvent):void
                        currentState = parent.getModelState;
                        parent.addEventListener(Component_A.STATE_CHANGED, modelStateListener);
                   private function modelStateListener (e:Event):void
                        currentState = parent.getModelState();
              ]]>
         </fx:Script>
         <s:states>
              <s:State name="first"/>
              <s:State name="second"/>
              <s:State name="third"/>
         </s:states>
         <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
         </fx:Declarations>
         <components:Component_C includeIn="first" x="220" y="275"/>
         <components:Component_D includeIn="second" x="2" y="0"/>
         <components:Component_E includeIn="third" x="0" y="8"/>
    </s:Group>
    For the record, I know this code does not work.  It has to do with the parent calls in Component B.  Comment out those lines, and the code will compile.

  • Drag and Drop, dropping to a parent component.

    I've been searching high and low for a solution to a problem without any success. I'm hoping someone here might have a suggestion.
    I have an application (written using Java 5.0) which allows dragging and dropping custom components between JPanels. My components themselves are JPanels with other components in them such as JTextFields. I've written custom TransferHandlers for my components and all works well. If I drag one of my components and drop it on the receiving panel, it works. If I drag and drop on an existing one of my components, the drop works since the components themselves don't support dropping (the drop is accepted by the parent JPanel).
    My problem occurs when I inadvertently do a drop onto a text component within one of my components. In this case the drop is rejected since the text component doesn't accept my Transferable. What I would like to happen is have the drop passed up to a containing panel that does accept the Transferable.
    I can't disable drop on the text components as I'd like them to still accept string drops.
    Is there another solution that will allow a parent (or more generally an ancestor) of a component to accept a drop rejected by a child component?

    "bmilesp" <[email protected]> wrote in
    message
    news:gnd5c7$jas$[email protected]..
    > hello,
    >
    > I've been searching on how to add drag and drop
    functionality to an hbox.
    > You're probably thinking "just use a tilelist", and
    that's what i'm
    > currently
    > using, but the tilelist cannot align items to the
    center, which is crucial
    > in
    > my application (if you need me to explain further i
    will, but i don't
    > think
    > it's relevant here).
    Sure it can.
    > So i need drag and drop on an Hbox. The repeater is
    necessary because the
    > hbox
    > may need to be populated with items initially, which can
    later be dragged
    > and
    > dropped either in itself (to re-arrange items) or into
    another hbox of
    > this
    > kind. For the past few hours I've been trying to find
    anything that can
    > even
    > hint at this type of functionality (i've been searching
    and experimenting
    > for
    > hours). If anyone can point me in the right direction,
    i'd appreciate it.
    > Thank
    > you very much. -b
    http://www.quilix.com/node/3

  • Parent Component function call

    Hello,
    I have a basic question regarding calling functions. How can
    I refer a function in the outer component from the inner component.
    Thanks
    Anil.

    You can call a parent's function by using the parent property
    of your custom component. The parent property is the reference to
    the component's parent.
    You can also use an event on the child and have the parent
    react to that event, it is a better practice.

  • File Selection - parent component

    I am trying to select a file on the client to be displayed.
    I have a JFileChooser that seems to work for the file selection, but when using the
    .showOpenDIalog() method, it is wanting a parent frame component as an arguement.
    If I use .showOpenDialog( null ), the dialog works, but is displayed behind the browser.
    How do I get a component that refers to the browser so I can use .showOpenDialog( component )
    and have the dialog open on top of the browser?
    I think it is something in the facesContext stuff, but just not shure what to use.
    Thanks.

    This doesn't actually work at all. The file chooser is being displayed on the server, which in your development area is the same as the client. Try it from a different machine and you will see what I mean.

  • Having picked up a mouse event, pass it to parent component.

    This is further to my table cell hover, which is otherwise working.
    I track the mouse accross the table using an invisible child component, and when the mouse leaves it, move the child onto the new cell position.
    The problem is that, while the mouse is over the invisible component, that component is grabbing all the mouse events. My table also wants to detect mouse events (though it's interested in clicks).
    The obvious thing is, after they've been dealt with and the child component level, to transfer the events to the table (having mapped the mouse coordinates). However all the processEvents methods in components like JTable are protected.
    I suppose I could extend JTable and add a method to get arround protected, but that's nasty, especially since a lot of my JTables are already subclassed.

    I had to do just this. I have JLabel's in a JPanel. The JPanel is in a LayeredPane. When I mouse over the JLabels, they grab the mouse events... which I don't want. I want the LayeredPane to get it.
    So in the JLabel, I do:
          * Don't send to parent what you don't have to. Things like tooltips will
          * be broken if this is not handled carefully...
         public void mouseClicked(MouseEvent e) { }
         public void mouseMoved(MouseEvent e) { }
         public void mouseEntered(MouseEvent e) { }
         public void mouseExited(MouseEvent e) { }
         public void mouseReleased(MouseEvent e) { machine.dispatchToParent(e);}
         public void mouseDragged(MouseEvent e) { machine.dispatchToParent(e);}
         public void mousePressed(MouseEvent e) { machine.dispatchToParent(e);}(the "machine" above is a JPanel). Now in the JPanel, aka "machine", I do:
    Point point; int comp_x, comp_y; // for component with respect to this machine
    public void dispatchToParent(MouseEvent e) {
         point=((JComponent)e.getSource()).getLocation();
         //System.out.println("Dispatching: " + e.getX() + " " + e.getY());
         //System.out.println("Component position: " + ((JComponent)(e.getSource())).getLocation());
         if (e.getButton() > 0) MsgIFrame.println("ME at: " + comp_x + "," + comp_y + " button: " + e.getButton() );
         if (e.getButton() > 1) {
              popup(e);
              return;
         comp_x=(int)point.getX(); comp_y=(int)point.getY();
         comp_x+=this.getX(); comp_y+=this.getY();
         e.translatePoint(comp_x, comp_y);
         room.getLayeredPane().dispatchEvent(e);
    }Above, the "room" is a JInternalFrame with a LayeredPane inside it, as you can see. I do a little translating so the LayeredPane gets the event in its coordinate space, not those of its Components.

  • How preferred size of JAVA GUI is calculated when the parent component is invisible?

    Hi
    Suppose a Panel has a tabbed pane with two tabs inside it.  If I do setVisible(false) for 2nd tab but not for its child components,
    Will the size of child component's of 2nd tab be considered to calculate the preferred size of the TopPanel ?
    Similarly,  If a Panel has a sub-panel and sub-panel has few child components. If sub-panel is invisible but its child components are visible, they will not be shown on the screen.
    In this case, Will the sizes of sub-panel's child components be considered for calculating the preferred size of the outer panel ?
    Please let me know
    Thanks in advance.

    Are you talking about Java or another language?
    However, when I run this report, JVM tries to allocate these 10 MB objects, but causes an Allocation Failure (AF). Java does get such an error. It can get an OutOfMemoryError.
    At this point, the unusable heap size due to fragmentation is ~100 MB. Again Java doesn't get unusable heap space as the GC will repack the memory to remove fragmentation.
    - is 10 MB object size okay? Is it normal to have object size of 10 MB?In Java it is normal.
    - How can I reduce the fragmentation in the memory?Use Java.

  • Child component values submitted when parent component not rendered

    This pertains to the standard JSF components, but may carry over into Sun JSC.
    I have a column in a dataTable that contains a checkbox. The rendered attribute on that column is tied to a backing bean property. The column is/is not displayed as appropriate per the value of that property - great.
    Here's the rub: When that column is not rendered and the form is submitted the values for the checkboxes are still being submitted and my data model is being updated for those non-rendered components. Seems like this shouldn't happen, but the real problem is that the values submitted for those checkboxes are always 'false'. Seems like JSF is out of sync in this case in what it does between when the form is loaded and when it is submitted (perhaps it is not loading the values from the data model yet it is updating them on the submit - with garbage).
    To get this to work as I expected I had to set the rendered attribute on the checkbox components to match the rendered attribute on the column that contains them.
    Is there a bug here?

    This pertains to the standard JSF components, but may carry over into Sun JSC.
    I have a column in a dataTable that contains a checkbox. The rendered attribute on that column is tied to a backing bean property. The column is/is not displayed as appropriate per the value of that property - great.
    Here's the rub: When that column is not rendered and the form is submitted the values for the checkboxes are still being submitted and my data model is being updated for those non-rendered components. Seems like this shouldn't happen, but the real problem is that the values submitted for those checkboxes are always 'false'. Seems like JSF is out of sync in this case in what it does between when the form is loaded and when it is submitted (perhaps it is not loading the values from the data model yet it is updating them on the submit - with garbage).
    To get this to work as I expected I had to set the rendered attribute on the checkbox components to match the rendered attribute on the column that contains them.
    Is there a bug here?

  • Not able pass the data from component to other component.

    Hello All
    I am not able pass the data from component to other component.
    I have done like this.
    1 Main Component (Parent component ) having below  two child components.Embeded as used components.
    2)     Search Component  and Details Component
    3)     In the Search Component having buttons,  Say : Button u201CXu201D on click of button I am navigating to Details component view through FPM.
    4)     When I am clicking above button u201CXu201D raising the event to call the parent   business logic method, there I am getting  Structure with values and binded this structure to the node and Mapped this node to the Details component  interface node. FYI : I kept the debugging point Structure is having data , I had set static attributes table to node instance.
    5)     In the Details component node data is not coming mean empty.
    Thanks in Advance.
    Br-
    CW
    Edited by: CarlinWilliams on Jul 4, 2011 9:21 AM

    Hi,
    When you use input Ext. check that the parent component should not be used as used component in child component.
    Only in the parent component the child components should be used as used components and the usage has to be created for the
    Child Components and the binding of the Node should be done from comp. controller of parent component to child node
    by which you will be able to see double arrow against the node.This should work
    Thanks,
    Shailaja Ainala.

  • No component usage created in enhanced web dynpro component

    Hi experts,
    I am facing the following problem:
    I'd like to enhance a web dynpro component in order to add a popup window. The popup is triggered by the process_event method. So far everything works just fine.
    But the popup needs to know some context attributes from the main component, and I cannot create a component usage in order to set the context mapping.
    Does anybody know how to solve this issue?
    Thanks and regards
    Jan Phillip Höft

    Hi!
    Thanks for your answers first of all.
    I need the popup to be a stand alone web dynpro component, so I guess the assistant class doesn't do the trick because I can not access it in the popup component.
    The popup is called when the business object is saved. So that the user is asked to notify other users that the document has changed. In this popup the user should fill in the message and click a button to send it and close the popup.
    So I tried the OBN approach as well but with two problems :
    1. I cannot close the popup component by coding (button click) because it has no direct parent component
    2. The save event is not run through properly so the document stays locked by the user. But I didn't look into this yet.
    So it would be perfect to have an embedded popup component which is based on a stand alone web dynpro application so it can be closed properly but it need at least access to the guid of the main component.
    Anybody got an idea for this?
    Thanks and regards
    Jan Phillip Höft

Maybe you are looking for

  • Problems copying and trashing files

    OK - here's what I assume are two seperate issues, or they may be related. (I'm running 10.3.9 on an iBook G4 and attempting to move files to a USB external). I have a DVD of jpg photos I was attempted to copy onto an external hard drive. About half

  • Inspection for every 10th piece or lot

    Hi Experts We have good supplier and good manufacturing processes at the client site. They do not want to inspect every other piece, They want to inspection every 10th piece or lot for purchased parts and also for produced materials in shop floor. Pl

  • OData and SAP NetWeaver

    Hello experts. Can you tell me whether SAP NetWeaver Gateway 7.0 works with oData? And what do I need to start work? Thanks in advance!

  • Preview is different web browser

    anyone have encounter when you want to preview your work and somehow it is different in the web broswer.... Example image are in different location

  • Pop-up in new Satellite L855 - Windows is not genuine

    Sorry for my English. on February 8, 2013 I bought my Toshiba L855 laptop with Windows 7 Home Premium preinstalled. For about 10 days I get a pop-up that says Windows is not genuine. Windows is activated. I checked the license key with the software *