Action Events from sub-components?

I have a main Swing GUI JFrame, in this frame I have a JLayeredPane (should have named it JLayeredPain). I have a button to switch the layers (only 2 layers, one is a text area, one is a new class which I wrote) On startup the Textarea shows. I click "Switch" and the new class object ( extends JPanel) shows in the JLayeredPane. In the new object I have a JButton "Back". I would like "Back" to cause the main GUI to switch the layers back to the TextArea. I need to somehow pass the ActionEvent from the secondary class From the "Back" button to the Main GUI to call jLayer.moveToFront(TextArea). Hmmm, but I don't know how to do this... Any thoughts would be helpful.

Use JTabbedPane instead. JLayeredPane is only useful if you have to stack a bunch of transparent layers like Adobe Illustrator does.
JLayeredPane isn't real good at dynamically changing event listeners. In theory, JLayeredPane should direct events to the topmost layer. In practice, I could never get it to direct events to anything other than the first added component that had any listeners. Changing the order of the layers had no effect. In the end, I added an extra transparent JPanel on top with listeners to trap the events and perform the corresponding action on the correct layer. I'll be this is exactly how Adobe Illustrator is implemented.

Similar Messages

  • Coalescing events from multiple components in a JPanel

    Hi,
    I've got a JPanel based form with several components (mostly JTextField) and I'd like to be able to have component events bubble up to the parent JPanel. By comparison to MFC, if I have a dialog box with several controls all of the control events will continue to percolate upwards until they are handled. Is there any such possibility with Swing?
    Ideally I would like it if all component events were routed to a single listener in the parent JPanel, all I really need to do (initially) is set a boolean to note that a change may have been made. Do I have to explicitly set a handler for each component or is there way to automagically have the parent to catch the events from its child components?
    Thanks!
    jam

    Thanks jvaudry, this is kinda what I suspected. It seems somewhat cumbersome to have to set up a listener for each of the many JTextField's in my form but definitely wrapping all of that up in a class is a good way to go. I'm pretty new to Swing and usually when something seems harder than it should it's a sure sign that I just don't know how to do it right :)
    I may try an altogether different approach just for curiousity's sake. I'm thinking of adding a method to the parent JPanel that will iterate all of its text fields and create a checksum of their combined contents. The idea is that I will compute the checksum once after populating the form and then later to see if any of the fields have changed. A simple notion that may not turn out to be so simple once I get to coding, but it's worth a try.
    Thanks!
    jam

  • Missing Action Event from Custom Component

    Hi JSF Gurus,
    I have two custom components, both extends UICommand and have their
    own renderers. I use them on two seperate pages, say component1 on
    page1 and component2 on page2. And page2 is include inside page2.
    I registered an action listener on component2. When the composite page
    is rendered, I clicked on component2. However, the registered action
    listener was not invoked. Inside the debugging (I'm using IntelliJ
    IDEA 5.0) I set a breakpoint inside the decode method of Renderer2
    (renderer for component2). I do see the componen2 actually as an
    actionLister method binding being set to correct value. I do queue the
    new action event to component2 at the end of the decode method. But
    the action listerner never invoke.
    Any idea what did I miss?
    Thanks,
    Edmond

    Hi Yuki,
    Yeah, after I turn on detail JSF debugging as instructed by the book Core JavaServer Faces, I figured out I had a validation error. That solves the mystery.
    Thanks,
    Edmond

  • Generate action events from objects

    Is there a way to have an object generate an event for a component just as if that component had received the event from the user?
    i.e. I have a JPanel that has a MouseListener added to it. Can I have a separate object (or actually just having the JPanel do it itself would be fine) create a MouseEvent and fire it to the MouseListener so that the code in the MouseAdapter's MouseClicked method gets run?
    Thanks,
    Matt

    I think Component.dispatchEvent() is what you are looking for.

  • Action event from jComboBox1 to setModel for jComboBox2

    I am an extreme newbie. Sorry if the answer to this is obvious. I have 1 combo box(paperType) that has 2 items. Depending on which item is selected on jComboBox1, i want it to set the model for jComboBox2(weightBox). Using NetBeans IDE 6.5.1 - it is telling me that "_setModel(javax.swing.ComboBoxModel) in javax.swing.JComboBox cannot be applied to (java.lang.String[]_)". Here is the code I am trying to use:
    private void paperTypeActionPerformed(java.awt.event.ActionEvent evt) {                                         
    final String papType = (String)paperType.getSelectedItem();
    {String[]texwgtString = { "50", "60", "70", "80", "100" };
    {String[] covwgtString = {"65", "80", "100", "120"};
    if(papType == "Text/Book"){
    weightBox.setModel(texwgtString) ;
    else weightBox.setModel(covwgtString);
    What am I doing wrong? Again, I am still way new at this.
    Thanks, Dave

    To post code, use the code tags -- [code]Your Code[/code] will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
    Read the API for JComboBox. What is the Type of the parameter to setModel? And what is the Type of your variable reference texwgtString?
    Apart from that, you also have misplaced braces in the code you posted.
    db

  • Can JSF get Action Events from Applet  or  td

    following is a example of click different part of Command to get different effect.
    I wish get same effect as click on applet; In fact , I wish get the clicked point value (x and y ) relative to Component.
    Is this possible?
    Please help me to realization it. thanks!
    <html>
       <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
       <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
       <f:view>
          <head>                 
             <link href="styles.css" rel="stylesheet" type="text/css"/>
             <f:loadBundle basename="com.corejsf.messages" var="msgs"/>
             <title>
                <h:outputText value="#{msgs.indexWindowTitle}"/>
             </title>
          </head>
          <body>
             <h:form>
                <h:commandButton image="mountrushmore.jpg"
                   actionListener="#{rushmore.listen}"
                   action="#{rushmore.act}"/>
             </h:form>
          </body>
       </f:view>
    </html>
    package com.corejsf;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.util.Map;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;
    public class Rushmore {
       private String outcome = null;
       private Rectangle washingtonRect = new Rectangle(70, 30, 40, 40);
       private Rectangle jeffersonRect = new Rectangle(115, 45, 40, 40);
       private Rectangle rooseveltRect = new Rectangle(135, 65, 40, 40);
       private Rectangle lincolnRect = new Rectangle(175, 62, 40, 40);
       public void listen(ActionEvent e) {
          FacesContext context = FacesContext.getCurrentInstance();
          String clientId = e.getComponent().getClientId(context);
          Map requestParams = context.getExternalContext().getRequestParameterMap();
          int x = new Integer((String) requestParams.get(clientId + ".x"))
                .intValue();
          int y = new Integer((String) requestParams.get(clientId + ".y"))
                .intValue();
          outcome = null;
          if (washingtonRect.contains(new Point(x, y)))
             outcome = "washington";
          if (jeffersonRect.contains(new Point(x, y)))
             outcome = "jefferson";
          if (rooseveltRect.contains(new Point(x, y)))
             outcome = "roosevelt";
          if (lincolnRect.contains(new Point(x, y)))
             outcome = "lincoln";
       public String act() {
          return outcome;
    }

    final JList list = new JList(dataModel);
    MouseListener mouseListener = new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
             if (e.getClickCount() == 2) {
                 int index = list.locationToIndex(e.getPoint());
                 System.out.println("Double clicked on Item " + index);
    list.addMouseListener(mouseListener);

  • Firing an action event

    Hi,
    is it possible somehow fire an action event from one managed bean method to an action listener which is in another managed bean?

    Hi,
    action events are bound to a component. A good article on events is written by Hans Bergsten.
    http://www.onjava.com/lpt/a/5066
    In your case, wouldn't it be easier to create a handle from one managed bean to the other in providing the reference to the second as a managed property?
    Frank

  • Is there a way to trigger button's action listeners from key events?

    I rarely do GUI programming, especially not in Java. But now I am working on a GUI app and would like to get some help.
    Say I have a simple GUI consists of a JFrame, and a bunch of buttons on its JToolBar. The buttons on the JToolBar are for navigation of a set of documents, first, prev, next, last etc. All buttons are assigned action command strings, and their all trigger the same instance of action listener. inside of the action listener, it does the correct navigation based on the action command from the event.
    but some users want to be able to use the keyboard to do the navigation, because they think clicking the buttons are too slow.
    So is there a graceful way to receive the different key press events and trigger corresponding navigation actions (hopefully it reuses the code that is already there, e.g. the action listener)? thanks.
    -- Jim

    but some users want to be able to use the keyboard to do the navigation, because they think clicking the buttons are too slow. That is always the case in any GUI. Any application should be designed to use either the mouse or the keyboard.
    All buttons are assigned action command strings,That is not the way the GUI should be designed.
    Instead you should be creating Actions. Then you can add the Action to a button and you can associate the Action with a KeyStroke which is called "Key Binding". This is the way all Swing components work. You can read the [url http://download.oracle.com/javase/tutorial/uiswing/TOC.html]Swing tutorial for more information and examples. Start with the section on:
    a) How to Use Actions
    b) How to Use Key Bindings

  • How can i set action on UITaBar and get event from that

    Hi All,
    I m doing one apps in which i have to add three UITabBarItem and this is UITabBarSystemItem.
    Now i cannot understand that how can i set action and get event from the?
    And how can i set various views on three tab bar item.
    I have to use UITabBar means i have to use UINavigationController+UITabBar
    My code id
    tabBar =[[UITabBar alloc] initWithFrame:CGRectMake(0,370,320,50)];
    tabBar.backgroundColor =[UIColor blackColor];
    UITabBarItem *search =[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0];
    UITabBarItem *recents =[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemRecents tag:1];
    UITabBarItem *favorites =[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorit es tag:2];
    tabBar.items =[[NSArray arrayWithObjects:search,recents,favorites, nil] retain];
    tabBar.selectedItem = search;
    [myView addSubview:tabBar];
    [tabBar release];
    I add a action:
    UITabBarItem *search =[[UITabBarItem alloc] InitWithTabBarSystemItem:UITabBarSystemItemSearch tag:0 action:@selector(select:)];
    So it error: Warning -no'InitWithTabBarSystemItem:tag:action:' method fount
    So any can help me regarding it?

    Thanks RickMaddy very much.
    I read and do with sample at the View Controller Programming Guide . But when run it only view TabBar with title but haven't got any TabBarItem on it. I searched a few example about TabBar and i did, but i want do a form with a button then press on button it view a form with 2 TabBarItem on TabBar and press each TabBarItem will show correlative form page 1, page 2.
    UITabBarController *tabBarControl = [[[UITabBarController alloc] initWithNibName:nil bundle:nil] autorelease];
    tabBarControl.title = @"Tab bar";
    ViewControl1 *view1 = [[[ViewControl1 alloc] initWithNibName:@"ViewControl1" bundle:nil] autorelease];
    ViewControl1 *view2 = [[[ViewControl1 alloc] initWithNibName:@"ViewControl2" bundle:nil] autorelease];
    tabBarControl.viewControllers = [NSArray arrayWithObjects:view1,view2,nil];
    [self.navigationController pushViewController:tabBarControl animated:YES];

  • Temparally remove rows from a ADF table by action event of a jsf page.

    Hello Developers,
    I needed to temporally remove rows of a ADF table when execute action event of corresponding page.
    So in this case my task can describe by following steps,
    (1). I created a ADF table using <af:table> on a jsf page.
    (2). The data populated using a VO.
    (3). Several radio buttons added to the page for temporally remove rows from the table.
    This means one radio button check, it responsible to temporally remove rows which contain empty cell values of a identified column.
    If I check another radio button it should temporally remove identified data included rows but above removed (empty cell included rows) rows should appear in this event
    My ultimate target is temporally remove rows of a table & re call again removed rows another event without again & again query from BC.
    Pleas advice me to archive this task very sealy?
    (Are there have a way to do this using EL or coding in Manage bean ?)
    Thanks in advance..!

    Hi,
    the DCIterator gives you an option to iterate over the fetched rows (the ones you see in the table). You can try call removeAndRetain() on these rows. This will not remove or delete rows but allows you to insert these rows back to the collection.
    JavaDocs:
    * Removes the row from the collection and then retain it for insertion
    * into another location.
    * <p>
    * This method differs from <code>{@link #remove()}</code> in that
    * it just removes the row from the collection. It does not
    * remove the underlying Entity row(s) or database row(s).
    * <p>
    * This method also differs from <code>{@link #removeFromCollection()}</code>
    * in that after the row is removed from the collection, it can be inserted
    * back into the collection at another location.
    void removeAndRetain();
    Frank

  • How to Call action Listener from Mouse Listener event

    One class (class 1)implements mouse listener and responds to a mouse events.
    As part of that response it needs to call a variable set method in another class (class 2)and also have that setMethod call it's own ActionPerformed.
    Seems the problem is I don't have aaction event to pass
    I only have a mouse event. As follows:
    class 1
    public void mousePressed(MouseEvent e) {
    int y1=Math.abs(e.getY()-y);
    this.sourceReference.setVar(y1);
    repaint();
    class 2
    int var;
    public void setVar(int y)
    var=y;
    this.ActionPerformed(?? ); //This is what I want to do
    Same question slightly different.
    From class 1 I scould first call the setVar method
    and then issue a call to class 2's ActionPerformed.
    But again I don't seem to have the proper action event e to pass it.
    Thanks

    Do you need any information from an ActionEvent that you'd be calling from the MouseEvent (ie the action command, or somethig) or can you just have the actionPerformed method just call a different method that doesn't need an ActionEvent?
    public void actionPerformed(ActionEvent e) {
    this.doActionStuff();
    public void doActionStuff() {
    // does what you want the action event to do
    Then from the mousePressed method you can just call the doActionStuff method.
    I'm not sure if this helps or not, hope it does.
    Scott

  • Events from main application to components

    Could someone please tell me if it's possible to broadcast an
    event from the main application to components that have been
    declared inside the main application?

    For the number of rows in the DataGrid just look at the length of the dataProvider.
    For passing data between popups and app, the gold standard is to use custom events, and add the event listener to systemManager.
    Here are some tutorials on custom events I created:
    http://chikaradev.com/learning/flex3/customevents/StudentsTutoringCustomEvents1.pdf
    http://chikaradev.com/learning/flex3/customevents/CustomEventSimple/CustomEventSimple.html
    http://chikaradev.com/learning/flex3/customevents/CustomEvents1/index.html
    If this post answers your question or helps, please mark it as such.
    Greg Lafrance - Flex 2 and 3 ACE certified
    www.ChikaraDev.com
    Flex Training and Support Services

  • What is the correct procedure to connect and collect events from IPS through SDEE

    What is the correct procedure to connect and collect events from IPS through SDEE?
    We are a 3rd party application, that needs to collect and analyze the IPS events for a client.
    Currently the approach we are following is
    1) get a SubscriptionId using the URL below
    https://IP_Of_IPS/cgi-bin/sdee-server?action=open&events=evIdsAlert&force=yes
    This gets us a subscriptionId which is used in step 2
    2) Collect events from the url below
    https://IP_Of_IPS/cgi-bin/sdee-server?confirm=yes&action=get&subscriptionId=sub-sample&startTime=1362699903575432000
    a few more notes here are
    - starttime is current time in nanoseconds
    the peculiar problem here is that, even though we specify todays date, SDEE returns us the events from mid Feb (today is march 7)
    we did try a few combinations, but are out of ideas.
    any help or direction would be appreciated

    This is more an application issue than an IPS issue.
    Have you compared your app against other apps [IME]?

  • Bubbling exceptions up from sub packages

    Hi.  We run 2012 std.  We r trying 2 get our heads around the options we would have customizing capture of exceptions that bubble up (if that is possible) to our master pkg from sub pkgs.  This question is independent of ssis's sys logging.
    My recollection is that ssis tells us a lot (maybe too much repetition) about exceptions.  Our goal is to customize how we deal with exceptions at lower levels in the master pkg itself (perhaps in the .net service that calls the mstr if that can be
    bubbled up) so that we aren't incorporating the same custom logging at every level of the ssis call "tree/structure".
    We capture some exceptions already in vars by incorporating try catch blocks in our c# scripts.  But haven't addressed yet how those might be bubbled up.  It is hoped that whatever we do with these can mimic what we do with exceptions thrown by
    other ssis components where there is no c# code to catch the exception.
    Can the community get us started?

    this is what I'm concluding from what I see and what the community has said thus far:
    If our goal is a tool that can answer most inquiries about what our etl has done,
    1)   forget about dbo.sysssislogs .  It doesn't record exceptions.  Traceability may be present but at what cost?  It is susceptible to different approaches used by different programmers working on different pkgs.  Its
    not a question of if but rather when it will be truncated and thus be out of sync with supporting custom log tables.  It is probably going to behave differently from release to release of ssiis.
    2)  keep that flat file ssis log around.  I'm not sure what its formal name is but we often append a datestamp to a file name we give it when running pkgs from the command line.  As much of a challenge as it is to read that
    file, it seems more informative and friendly to me than dbo.sysssislog.  And kills two birds with one stone in the event that custom logging cant make a connection to the db where custom logging takes place.
    3)   get serious about ssis component naming conventions.   How informative is "For Each Loop" when trying to make heads or tails of what a log is trying to tell you.
    4)  don't allow parallel processing (neither in cf not df) until ssis gets better at the whole var locking unlocking race condition thing.  Handle locking yourself.  Incorporate multiple pkgs if both parallel processing and
    useful logging r important.
    5)  bake record counts, start times and end times into your logging solution.  Reject counts as well if applicable.         
    6) use pre, post and error handlers to do the logging with a std toolbox item if possible thus leaving pkgs more readable.  Record parent child component traceability info that is exposed in these handlers thru system vars.  Supplement latter with exceptions
    caught in c# scripts.  Use views and indexes for the dashboards that will need to look at this stuff from different perspectives and permissions after the fact.  Prepare for repetition where errors bubbled up thru parent ssis components.
    7)  get an answer on guids when ssis components r copied from place to place.  If a new guid isn't created, find a way (I think there is a tool for this), to generate a new guid for the new component.  I think a component guid column
    would be germane to a custom logging tool.  Similarly watch out for changing a component's guid once logging has begun. 

  • How to add to viewPlatformBehavior an Action Event - a button press

    And the main problem I have is to by pressing buttons to change the Viewing Platform?
    I made same transformation to object, which reacts to key pressin:
    public class LewoPrawo extends Behavior{
        private TransformGroup targetLP;
        private Transform3D wysuwanie = new Transform3D();
        private float krok2 = (float) 0.0;
         // create LewoPrawo
        LewoPrawo(TransformGroup targetLP){
        this.targetLP = targetLP;
         public void initialize(){           
                this. wakeupOn(new WakeupOnAWTEvent(AWTEvent.KEY_EVENT_MASK));
        public void processStimulus(Enumeration enumeration){
            this.wakeupOn(new WakeupOnAWTEvent(AWTEvent.KEY_EVENT_MASK));
                KeyEvent event = (KeyEvent) ((WakeupOnAWTEvent) enumeration.nextElement()).getAWTEvent()[0];
               if (event.getKeyCode() == KeyEvent.VK_Q) {
                   krok2 += 0.01;
               if (event.getKeyCode() == KeyEvent.VK_W) {
                   krok2 -= 0.01;
               wysuwanie.set(new Vector3f(krok2, 0.0f, 0.0f));
               wysuwanie.mul(przewrocenie);
               targetLP.setTransform(wysuwanie);
        }And this is the one that I made up to move the viewing platform, but it doesn't work!!!
    public class Perspektywa extends ViewPlatformBehavior{
    private TransformGroup targetVP;
    private Transform3D obrot_obserwatora = new Transform3D();
    private double kat=0.0;
    //create Perspektywa
         Perspektywa(){
         public void initialize(){
         this.wakeupOn(new WakeupOnAWTEvent(AWTEvent.ACTION_EVENT_MASK));
         public void processStimulus(Enumeration enumeration){
         this.wakeupOn(new WakeupOnAWTEvent(AWTEvent.ACTION_EVENT_MASK));
    ActionEvent event = (ActionEvent) ((WakeupOnAWTEvent) enumeration.nextElement()).getAWTEvent()[0];
         if (event.getSource()== przyciski[0])  {
               kat += 0.1;
           if (event.getSource() == przyciski[3]) {
               kat -= 0.1;
            obrot_obserwatora.rotY(kat);
            TransformGroup targetVP =
                simpleU.getViewingPlatform().getViewPlatformTransform();
            targetVP.getTransform( obrot_obserwatora);
    }And what's worse, action events doesnt even work when i replace key events with them, but i don;t know why ;(

    The section from the Swing tutorial on "General Rules for Using Text Components" has a sample program that does this:
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html
    Or, you can create a new Action using DefaultEditorKit.CopyAction

Maybe you are looking for

  • Headphone is not working after plugin pavillion dv6000 CNF6430M51

    Product :        Hp Pavillion dv6000 Serial    :        CNF6430M51 Product no. : RG254UA this is the first time i sending you my first problem since i have formated my system my new headphones are not working after plugin i have intalled sp34200 aslo

  • Is my computer a ppc or a intel?

    i don't really know what this means but i know ppc is old and intel is new right? anyways its a imac aluminum front black back and here are the specs Model Name:          iMac   Model Identifier:          iMac7,1   Processor Name:          Intel Core

  • UNION operator in ejb 3.0

    Hi All, I have to use UNION operator in my ejb ql. My underlying database is MySQL. My ejb ql is SELECT s from eee s where s.name like 'XXX' UNION SELECT t from eee t where t.default_id = 'XXX' union is on the same entitybean. In my eee entity bean I

  • Clients local admin user is managed - how can it be unmanaged

    Hi. I have a local user on all my client machines called admin with admin rights. Have had this same user with same password for many years for over 300 client machines from emacs to intel macs. With the 10.6.3-5 server update (major issues for the l

  • ACE Cold Standby

    Hi, I've got an question about ACE modules in HA, when one of the switch is reloaded a couple of the ACE contexts come up in cold standby. I've check the config in the contexts to confirm that they match and the same ft interface is used by all conte