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

Similar Messages

  • 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

  • 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.

  • Restrict Movement by Material Type

    Hi:
    I want to restrict movements in transaction MIGO by material type. IS it possible?
    e.g. I created a role Z:STORES_CLERK and Z:FINISHED_PROD_CLERK.
    I want to restrict the role Z:STORES_CLERK to perform movements for only material types NLAG, HIBE etc and want to restrict role Z:FINISHED_PROD_CLERK. for material type "FERT"Is it possble??

    Hi ,
    It is not possible to restrict movemment type by material type.You can restrict by tcode.
    Regards,
    Nitin Amritkar

  • 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 dialog box

    hi,
    I have an internal frame when the user clicks a button a dialog box should pop up , how shall i restrict the movement of dialog box within the parent..(Desktoppane) i have used custom dialog box coz i need to capture the button click event.
    Thanks in advance

    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

  • 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.

  • 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.

  • I updated my ipad into ios 7 but when i want to connect to a network an error cames that says unable to join this network!And another thing is the button of the restriction code is on(my parents did nothing it's sunddenly like this) ! what shoould I do?

    the thing is my restriction code is suddenly on and i think its because of i updated my ipad into ios 7 !!!!
    i asked my parents if they set this thing but they told my they didnt !
    now i cant join to network ! is it because of restriction code on ? because before i update my ipad it worked correctly and join to all of the networks !
    please help me ! this disaster started when i updated my ipad !
    please help me !
    how can i remove or turn off the restriction code but i dont want to reset my ipad !!!!!
    pleeeeeeeeeeeeeeeeeeeeeeeaaaaaaaaaaaaaaaaaaaaase help me !
    thanks for your consern !
    MahtaB

    SadisticIron wrote:
    i just baught my first iphone and it is a jalbroken
    Buzz! Thank you for playing!
    Discussing jailbroken devices is forbidden here by the Terms of Service.
    You can not get help here.

  • 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.

  • Accessing a Movie Clip in a parent Scene.

    Setup:
    *Scene 1:
      - MovieClip1
      *Inside MovieClip1:
       - Actions:
         stop();
         next_btn.addEventListener(MouseEvent.CLICK, onNextButtonClicked);
         previous_btn.addEventListener(MouseEvent.CLICK, onPreviousButtonClicked);
         function onNextButtonClicked(e:MouseEvent):void {
         if (currentFrame == totalFrames) {
         gotoAndStop(1);
         } else {
         nextFrame();
         function onPreviousButtonClicked(e:MouseEvent):void {
         if (currentFrame == 1) {
         gotoAndStop(totalFrames);
         } else {
         prevFrame();
        (THIS CODE IS FOR MY NEXT AND PREV BUTTON TO CYCLE THROUGH MY PIECES OF WORK)
       Then I have...
      - Pieces of work Layer:
        This includes each piece on a single frame, with a label name. (5 total frames on this layer)
        Then I have....
        - Next and Prev buttons on a layer
        And Finally....
       - The last layer in this scene has a background frame.
    ***** Now inside each frame containing each piece of work there is:
           1st Layer = Actions
           Containing this code: stop();
           2nd Layer = This is the movie Clip that Fades my pieces of work in.
       ****** Inside this movie Clip of the piece of work fading in will contain:
               1st Layer = Actions
               Containing this code:
    stop();
    function openLabel(event:MouseEvent):void {
    switch (event.currentTarget) {
    case identity_cplogo_btn :
    gotoAndPlay("cplogo_lv");
    break;
    identity_cplogo_btn.addEventListener(MouseEvent.CLICK, openLabel);
    2nd Layer = 1st frame blank, then frame 2-10 contains a movieclip with a label of cplogo_lv. This movie clip is the clip that has a large view of the image popup and darken the background. (Like a lightbox effect)
    3rd layer = the logo which is a BUTTON. THis is located on the first frame and is called "identity_cplogo_btn." So when this is clicked it opens the large view.
    *****Now....
    When I click inside the movieclip that is the lightbox effect and go inside of it there is.....
    1st Layer = Actions with the code of:
    stop();
    function openLabel(event:MouseEvent):void {
    switch (event.currentTarget) {
    case lv_close_btn :
    gotoAndPlay("return");
    lv_close_btn.addEventListener(MouseEvent.CLICK, openLabel);
    ****After the actions keyframe, which is locate on frame 10, there is a label called "return" from frame 11-24. It is a blank label meaning there is nothing on it but the label name.
    2nd Layer = the "Close" button which appears when the large view is opened and is located on frame 10 right underneath the action code.
    3rd Layer = This contains the Large view of the logo, which I have made a movie clip for making it fade in then I paste reverse frames after right underneath the "return" label making it fade out.
    4th Layer = Contains the Dark background that pops up which also fades in then underneath the "return" label it has its' reverse frames which are making it fade out.
    SO... I have the code making it so that when the "Close" button is clicked it is going to the "return" label which is making everything fade out.
    ***************************** NOW WHAT I NEED TO FIGURE OUT *************************************
    I need to know the code to be in the last movie clip I just explained and when I click the close button and it plays everything underneath the "return" label, THEN i need it to access the movie clip with the logo fading in so that it appears to go back to BEFORE clicking on the logo and expanding the view.
    I understand that this code will be places right after the "return" label so that when the return phase plays it will then play the code making it go to this movie clip then it will stop.
    I have tried
    MovieClip(parent.parent).gotoAndPlay("return_2");
    stop();
    And giving the movieclip that has the logo fading in the "return_2" label name. THis allows it to go to that movie clip, however, it doesnt play it is just blank on the screen.
    I also have tried accessing the movie clip after giving it an instance name, but it was doing the same thing.
    Help PLEASE!

    I actually tried a post earlier that was simplified, but I think the setup of scenes might be important....anyways, here it is.
    Setup:
    Scene 1 > MovieClip1 > MovieClip2 > MovieClip3 > MovieClip4
    Explanation:
    I am in MovieClip4, in which I have a "Close_btn" that when clicked, it takes you to label "return" (still inside MovieClip4), which then plays the movie clips in the layers below label "return." What I want it to do is....Once label "return" plays, I need the code to make it go into "MovieClip2" and play a movie clip with the "Instance" Name of "Logo_1."
    I have tried this by setting a label name above the movie clip and referencing the label, however, it does access that movie clip, but it doesnt play it...It is just blank.
    Hope this is understandable.

  • Modal JDialog messing parent layout

    Hello!
    Why does a modal JDialog mess up the parent frame layout? Actually only one panel inside it and a few components but still. When setVisible(true) is called on the dialog, the parent layout gets screwed. And when the dialog is closed it stays screwed until something makes the panel/frame re-validate itself (like resize or call to validate()). Any ideas what might be causing this?
    The dialog is modal and the frame is set as the parent for the dialog.
    Thanks,
    -teka

    Well it's possible that I am. The code is a bit complex with lots of classes etc. (and not made by me originally). Didn't find any AWT components when I browsed through the code but maybe I missed something. Does mixing AWT and Swing cause layout problems like that?
    -teka

  • Move child movie clip from one parent object to another

    Hi everyone,
    I am somewhat new to AS3, and I'm having a hard time working out the most appropriate way to move a child movieclip between parent objects.
    I'm creating a board-game type game wherein I've dynamically created an array of 'Square' movieclips, with no visual elements, which are arranged in a 10x10 rectangle on the stage. I then dynamically add the appropriate types of piece movieclips to the various squares with the addChild() method. In general, a square should only have one child piece at a time.
    All of this works well for setting up the play area, but now I'm having an issue with moving a piece from one square to another. I want to have the user click a square with a piece on it, then click the destination square to move the piece. I have the logic for determining where a user can move any given piece to, but I don't know how to actually move the piece.
    The pieces are all different class objects that extend both a base class I call Piece as well as the MovieClip class. The main issue is that when dynamically adding the various pieces to the squares, I don't provide them a unique name to access them later. I don't bother with unique names because I have no way of knowing which piece instance will be in a given square, so using getChildByName(name:String) isn't very useful.
    So I can think of two routes that I can take: Making a getter/setter for the Square class that manages a private Piece property (as well as the adding and removing of the child piece to/from the parent square), or using getChildAt(index:int) to try to access the child piece.
    I want to go with the first route as it seems to be the most maintainable to me. My problem is that I can't work out how to manage empty squares in this scenario. My instinct is to null to private _piece property of one square once I've moved the child piece instance to another square... but I'm fairly certain that the private property is a reference type, and nulling it out will null the actual piece object even after it's changed parents.
    I'm sorry for the long description. I'm hoping that my lack of experience with as3 it what's causing my trouble, and that someone more well versed will know of the best way to handle this. Maybe I'm overthinking everything.
    If something isn't clear, please feel free to ask me for clarification. I would appeciate any help that anyone may be able to offer.
    Thanks!
    - Scott

    for a square with a child, you can use:
    whateversquare.getChildAt(0);  // to reference whateversquare's only child.  although, if there are graphics in whateversquare, you may need to use getChildAt(1)
    or, if you want to use a square class getter/setter, what's the problem?  an empty square will return null.

  • Watch movies through tv using AV component -infos

    hey guys i would like to know if i could watch movies through my tv with my ipod touch 4g using the component AV cable. As i read some posts around internet there seem to be some problems either with the compability of the tv or the ios version. is it true?any infos around the subject gladly accepted. and finally i heard that movies purchased from itunes arent "supported" from the cable and cant be shown.True?and what about these that are transfered through pc (via itunes)? thnx in regard!

    Apple says no here for both composite and component for 4G:
    iPhone, iPad, iPod: TV out support
    This say VGA or Digital A/D (HDMI) only for 4G
    iOS: About Apple Digital AV Adapters
    . Note the 4G only outputs TV out for apps that specifically support TV out

Maybe you are looking for