Tutorial on AWT/Swing control flow

Greetings all,
Just wondering if any of you folks know of a good tutorial on AWT/Swing control flow? I'm doing some pretty complex stuff with a table whose editors call other windows and insert values into the table based on callback objects...weird stuff happening with loss of focus when the other windows come out, etc etc etc.
I have it working via a series of what I consider kludges, but I would really like to implement it cleanly, and it's looking like that's going to require understanding <ugh> <grin>
So it looks like it's time that I bit the bullet and got to grips with control flow in AWT/Swing. Is there a tutorial out there that could help me with this?
Many TIA

skiaddict1 wrote:
Let's take your word for it, but if you have the slightest doubt please consider the subject: EDT violation is a classic here.OK sure, but I really don't think I'm violating it. I avoid multi-threading like the plague, and only introduced it for my report writer because I wanted to have a little window advising the user that the report was in the process of being written.Raise your left hand and swear this report writer is not running when you experience the problem you describe! >o(
OK, this is just kidding, as per the rest of your description, it sounds reasonable now to assume that your problem is not related to EDT violation.
I'm doing some pretty complex stuff with a table whose editors call other windows and insert values into the table based on callback objects...This summary is a bit worrying, and I thought you would mention problems in the display of the table being edited. But you seem to refer to problems in other windows, or did I misunderstand?
Or do you mean, loss of focus in the editor still being edited? Can you please clarify what you do and what your problems are?
In particular, what does the other windows come out mean?OK, I was trying to be sparse with details because I didn't think they were relevant.Actually the worrying seems all the more justified, now that you have described it more extensively: I was afraid that you would raise other windows while editing, and that's the case. I know little of focus though...
I have a table in window A, one of whose columns has a custom editor which, when a cell in the column is double-clicked, registers itself with window B as a choice-listener (see later) then asks window B to come to the front. Window B, when the user performs a choice amongst the UI elements in there, fires a choice-event to its listener, i.e. the custom editor. At which point the editor saves away the chosen value (for use by getCellEditorValue()), sets the text in the cell appropriately, turns edit mode off via fireEditStopped(), and brings window A back to the front.
(...) once the custom editor asks window B to come to the front, the table in window A loses focus and when it is brought back to the front, the table's JScrollPane seems to have the focus (visually, it has the focus rectangle around it). Pressing the Tab key has no effect on focus; you have to use the mouse to focus something.I assume you have read the tutorial on using tables in Swing.
It contains an example where a custom editor is bringing up a dialog: http://download.oracle.com/javase/tutorial/uiswing/components/table.html#editor
AFAIK, the example does not suffer from focus problems.
What I am finding, and I reiterate this is new since I rewrote the windowing subsystem for the app (the custom editor was not changed in the rewrite), is that (...)Just what do you call "rewriting the windowing system" (just to rule out the possibility of something Ramboesque)?
I have no idea why this loss of focus is occurring, and I am at a loss to begin to figure it out. As I wrote above, I have a series of kludges which gets around the symptoms, but I would really rather figure it out and fix it.OK I admit I cannot tell what happens exactly, but:
1) instead of bringing window B to front, couldn't the editor bring up a dialog B (e.g. using JOptionPane.showXxxDialog() to bring up just the choice panel? The advantage is that it is more "synchronous", you can control when the window A's table model is updated.
2) what worries me too is that you update the model of the table being edited while you're editing one cell of it? Would it be possible, and make sense in your case, to update this model later (that is, post the model update as an invokeLater(...) call)? I don't see how seeing the table updating underneath helps the user editing its cell, but you may have your reasons.
What do you call flow control , or control flow in AWT/Swing?Basically, what I am after is something that will help me begin to understand/diagnose problems such as the above when they happen in my code. I am deeply averse to multi-threading (...) Things in my code were working, and that was enough for me.
But the above behaviour, and another weird behaviour I was having last week, which again I have solved with what I consider a kludge, and again which only began with my new windowing subsystem, have caused me to realise that it's time I really got to grips with this issue.Yes, when they say beware of threads when using Swing , nobody tells to not use threads! Just to be aware of how special Swing is with regards to threads (at least, compared to AWT, that didn't make such warning).
I would like, for example, to really deep-down understand exactly when listeners for AWT-Swing events get called. I don't really care so much when the events get put on the queue, but I do care when exactly my event handlers will be called. This will help me diagnose problems, I'm sure.Well they get called in the EDT, by some framework code that, in an infinite loop, does something along the lines of:
- pop next event from the event queue
- determine which is the target widget
- let the widget transform the event and send it to all registered listeners
Now with dialogs, things gets dimmer, because while a dialog is brought up (via a<tt>setVisible(true)</TT> call on the EDT, the EDT is indeed suspended, and a new event thread manages the events for the dialog).
I'm sorry I have no reference for that behavior, and my description is certainly blurry (and possibly wrong), but I don't think your problem is so much related to threading as I initially thought.
N.B.: Darryl's second link does features sequence diagrams that try to demonstrate what happen (in a specific example with asynchronous access, but you can derive the simpler, regular, working, from it).OK, yes I saw that diagram, I was offput by the asynchronicity but I will have another look tomorrow also. Thanks againDon't put too much hopes in there, indeed it's definitely not the kind of info I understand you're looking after.
Much luck all the same, and feel free to come back with your findings, or with more questions, about the initial subject (reference on event flow) and the specific problem (your focus issues with the editor).
I also cannot end this message without suggesting that you try to reproduce the problem with an SSCCE (http://sscce.org), that you could post here for us to try out. See this recent discussion about the multiple interests of this approach: {message:id=9587964}
Best regards,
J.

Similar Messages

  • A new AWT/Swing?

    I have a question for the community.
    IMHO, and I am not alone, AWT/Swing have major flaws that really ought to be fixed. Probably, because the APIs themselves are seriously flawed, what is required is a replacement for Swing.
    How would one go about proposing such a thing and getting Sun's support?
    Specific issues:
    1) A set of specific design rules should be codified, which all conforming components, layout managers, UIs, etc., should obey. Along with the rules, there should be automated tests, so that it could be confirmed whether components, layout managers, UIs, etc., work correctly.
    Currently, Swing and 3rd party components often do not work well together, for reasons such as
    a) Highly irrational behavior of layout managers. Currently, none of the AWT/Swing layout managers behave in a reasonable way under all circumstances, with the possible exception of BorderLayout. Also, layout managers use constraints in inconsistent ways, and they are ill-suited to control by GUI builders.
    b) Failure to use minimumSize, preferredSize, and size consistently.
    c) Inconsistent use of UIs. What is the division of responsibility between the UI, layout managers, L&F, and the main class(es)?
    2) Software design rules. For example, there is currently at least one Swing class that alters its behavior depending on which container it is placed in. That violates basic principles of OO development. Perusing the AWT/Swing source code, you will find plenty of objectional coding practices. It seems that the pressure to maintain backwards compatibility has been a real impediment to "doing things right".
    3) Performance. AWT/Swing are notorious for various performance problems, including
    a) Non-linear CPU cost associated with building certain graphical data structures (combo-boxes, for one).
    b) Layout managers that call getMinimumSize or getPreferredSize on child components multiple times. Currently, the layout managers are the CPU bottleneck in many AWT/Swing GUIs.
    c) Some text components are almost unbelievably slow. Try scrolling a lot of text through a JTextArea and you will be disappointed.
    d) The current validation logic is extremely complex, inefficient, and undocumented. I count approximately 15 basic API methods that affect how and when components are repainted. I defy ANYONE to explain how it all works. The typical result is that repaints occur FAR more often than is necessary.
    A lot of optimization is required to fix these problems. That means automating tests, profiling, removing extra repaints, CPU bottlenecks, etc.
    4) Excessive complexity of the APIs. For example, it seems that building practical tables and trees is harder than it should be. The APIs are complex and documentation obscure or lacking in detail. Also, the separation between model and view is often tainted. It shouldn't be necessary to do so much conversion between model and view indices, for example. A basic set of model classes should be shared by all components that use underlying data models. These model classes should support standard functionality such as filtering, sorting, etc.
    5) No portable remote operation. Yes, I am familiar with SAWT (slow and buggy), and the possibility of using X11 remotely when the Java application is run on a *nix platform (slow over a high-latency network such as the Internet and unusable on Windows systems).  There does not seem to be a usable, universal solution.
    Yes, I am familiar with SWT. However, for a variety of reasons, I believe that the AWT approach is superior. SWT is more platform dependent and it has the X11 reverse-object-orientation in which child classes know about their parents. I have done some performance testing, which suggests that
    1) SWT layout managers are faster than their corresponding AWT/Swing managers
    2) Most other graphics, including 2D graphics, are faster in AWT/Swing than SWT.
    I am sure that SWT encapsulates some good ideas. However, it seems that if the efficiency of validation and layouts could be improved, then AWT/Swing performance would be excellent, while maintaining OO and platform-independent characteristics.
    Possibly, these issues could be worked out piecemeal. For example, a new, rational set of layout managers could be developed entirely independently.
    Other issues, such as defining how UIs, L&F, and component classes should be architected, are going to be more problematic. Creating order in the current chaos will be difficult.
    Any ideas?

    >
    How would one go about proposing such a thing and
    getting Sun's support?
    As for proposing such a thing, you can always become a member of the Java Community Process Program (it's free for individual members): http://www.jcp.org/en/home/index. As a member you can post a Java Specification Request with your suggestions. If you want to operate on a smaller scale you can report bugs to the bug database.
    As for getting Sun's support....well, good luck! :-)

  • Control flow

    I still have a problem dealing with control flow statements, e.g. if(current != null)
    What does that mean?

    I still have a problem dealing with control flow
    statements, e.g. if(current != null)
    What does that mean?This tutorial might help you:
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/flow.html
    Sorry, Sun still didn't get the url tags fixed.

  • Dialog control flow case not opening in new browser window

    Hello -
    Using JDev 11gR1.
    I have a page fragment that contains a table of command links like so:
            <af:commandLink text="#{row.id}" id="cl2"
                            action="#{reportRunnerBean.runReportAction}"
                            useWindow="true" windowHeight="500" windowWidth="500">
              <f:param value="#{row.id}" name="reportId" id="p2"/>
            </af:commandLink>the runReportAction method returns the String: "dialog:runReport"
    in my page flow, the page fragment has a control flow case with the outcome "dialog:runReport" that leads to a URL View with the URL setting set to #{pageFlowScope.reportUrl}
    (the reportRunAction places a string in page flow scope with the key of "reportUrl". in case it matters, the url is external to the application)
    When I click on the link, I am directed to the correct URL. However, it does not open in a new browser window - it takes up the main browser window.
    Is there something obvious that I am doing wrong?
    Thank you for reading this,
    -- Scott

    Well, I couldn't figure out why the dialog wasn't working correctly, so I changed my page to use a server listener to handle the logic I wanted and just used af:goLink instead of a command link. That command link above became:
              <af:goLink text="#{row.id}" id="gl1"
                         destination="#{row.reportUrl}"
                         targetFrame="_blank">
                <af:clientAttribute name="reportId" value="#{row.id}"/>
                <af:clientListener method="logReport" type="click"/>
                <af:serverListener type="LogReportEvent"
                                   method="#{reportListBean.logReportInvocation}"/>
              </af:goLink>with the following client listener:
        <af:resource type="javascript">
          function logReport(evt) {
              var component = evt.getSource();
              var reportIdParam = component.getProperty("reportId");
              AdfCustomEvent.queue(component,
                                   "LogReportEvent",
                                   { reportId: reportIdParam}, false);
        </af:resource>and code in the bean:
        public void logReportInvocation(ClientEvent clientEvent) {
                String reportId =
                    (String)clientEvent.getParameters().get("reportId");
                //...do something w/reportId here...
        }Thanks to anyone who took the time to read this.

  • AWT/Swing gui flickering

    I am trying to add the swing JDesktopPane to java.awt.Frame .The JDesktopPane includes
    JInternalFrame.The problem is that the GUI is flickering when resized or moved.
    I migrated from jre1.4 to jre1.5 and the flickering of the JDesktopPane stops but the
    JInternalFrame is still flickering when resized/moved.I am wondering if at this point
    this is a AWT/Swing issue.

    Never ever mix AWT and Swing!At least not their components. :p ;)

  • Awt swing 1.1

    Hi,
    Where can I actually download AWT swing 1.1 package to run with jdk 1.1.?

    http://java.sun.com/products/archive/jfc/1.1.1/index.html

  • Can I use Swing controls with Forms 9i?

    Is there a way to use Java Swing controls with Forms 9i via a PJC or something? If so, is there a white paper on it? Thanks.

    Yes you can. There is a quick start about PJC here:
    http://otn-stage.us.oracle.com/products/forms/htdocs/upgrade/pjc/content.html
    And there is also a paper about Forms in the Java World that you should read.
    http://otn.oracle.com/products/forms/pdf/forms_in_java_world.pdf
    You might want to have a look at the Oracle9i Forms Demos for some code samples as well.

  • Programatically calling control flows from java code

    Hi all,
    I have a bounded taskFlow that uses pageFragments. This flow is a region in a page(.jspx).
    In my page fragment, I have a inputComboboxListOfValues with a ValueChangeListener code in a java bean.
    I want when a value is changed, to programatically call "controll flow" (this one has: "From Activity Id" -the page fragment with that inputComboboxListOfValues, and "To Activity Id" - the default Activity on this task Flow).
    So when the value change, practically I want to restart the flow programatically and pass the selected value as input parameter.
    Since the inputComboboxListOfValues is not like a button where in the "Action" property you can set the Control Flow and navigate somewhere, the only option I have is to programatically cause navigation from java code (example: the value change listener code).
    Can this be achieved?
    Any advice is helpfull.

    Hi,
    Absolutely, you can do it using the NavigationHandler. Try the following in you value change listener:
    FacesContext context = FacesContext.getcurrentInstance();
    NavigationHandler handler = context.getApplication().getNavigationHandler();
    handler.handleNavigation(context, null, outcome);
    // Render the response after that phase, the button actions should not be called
    context.renderResponse();
    // Add the following line if you want to prevent further value change listeners to be called
    // throw new AbortProcessingException();Regards,
    ~ Simon

  • Bounded-Task-Flow Page Fragment Control Flow Help

    jDeveloper: 11.1.1.0.2
    I am having an issue trying to figure out the correct way to use control flow cases between a bounded-task-flow with page fragments and an unbounded-task-flow page. We have taken the approach in our application to have a few shell / container pages to host bounded-task-flows made up of page fragments to facilitate re-usability and to speed up development. There are 4 or 5 shell pages on the applications unbounded-task-flow. As of now, we have about 20 page fragments that are implemented as bounded-task-flows. These fragments don't do much now, meaning there is only a single fragment in each bounded-task-flow. The issue I am having is trying to invoke a control flow navigation action from one of the fragments to load a different shell page.
    For Example, shellPage1.jspx contains fragment-flow-1 as a region. In my adfc-config.xml I have shellPage1.jspx and shellPage2.jspx, with control flow cases "toShell1" and "toShell2" respectively connecting the two pages. I have a link's action bound to the "toShell2" within the fragment that makes up fragment-flow-1. When the application is run, shellPage1.jspx and its fragment are displayed. But clicking on the link in the fragment ("toShell2") does absolutely nothing. It does not navigate me to the shellPage2.jspx as expected. What am I doing wrong here or do not understand?
    If the fragment is included as a JSP include, and not a bounded task flow include, everything works as expected. This is not desirable as we then need to copy the fragment's pageDef into the shellPage's pageDef to get the DataControls to function.
    If the faces-config.xml is used instead, and a JSF navigation case is used, it will also work as expected. This is not desirable because we really don't want to be mixing adcf-config and faces-config.
    So I am really stumped here.... Thanks in advance!

    Hi there:
    In your case, the adfc-config.xml has the control flow case between shell pages. And the task-flow-N.xml or your-task-flow.xml for each page fragment by default doesn't inherit control flow case from their containing shell page. In your case, in the page fragment task-flow.xml, you should add a "Parent Action" to flow to shell page2 for example. The outcome of "Parent Action" would be "toShell2" if calling from ShellPage1 page fragment.
    Is this 'Correct' or 'Helpful' for you? Please mark it as so if it does.
    Good luck,
    Alex

  • From where i can understand the control flow and architecture of JVM?

    i want to know control flow and architecture of JVM?
    Where i can know from?
    if some one wish to explain you can here also.

    makpandian wrote:
    No it s not broken.
    As per your experience,tell me some links.Per my experience I don't need links. I could build the VM both from the general level and the specific levels by referring only to the VM spec.
    And I read the book I suggested, first edition, years ago. Although with many other books.
    Conversely if I wanted to find a link now then I would use google.

  • Why do we want use 'Data Flow Task' to 'Data Flow Tast' in Control Flow?

    I found an example in my company's SSIS package folders. In Control Flow, it has one data flow connected to the other. Both of them are importing data from flat file and then exported to database. I think these two are kind of at the same level and cannot
    see any reasons to conncect them together.
    Thanks & Happy Thxgiving,
    Gavin 

    Hi Gavin,
    Just as Arthur said, if there is no relationship between those two data flow tasks, we don’t have to connect them together. If they connect together, maybe there are some relationship between them.
    According to your description, both of the data flow tasks are importing data from flat file and then exported to database. It seems that there is no direct relationship between them. Another possibility is that there is a precedence constraint between them.
    The precedence constraint can be based on a combination of the first execution results and the evaluation of expressions. We can check the issue by double-check the connection string between them.
    The following screenshot is for your reference:
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Setting Control-Flow- Case on java class/method

    hello All :D
    i have little problem about control flow case, in my case i've 2 page where before load to the page i'wanna make condition (if-else)
    when the user choose the field, the java class get the value for make true condition. In this case, i wanna implement ControlFlowCase in java class/method, so anyone help..?
    thx
    agungdmt

    Have you considered using router activity - http://download.oracle.com/docs/cd/E17904_01/web.1111/b31974/taskflows_activities.htm#CJHFFGAF ?

  • Ssis data flow item and ssis control flow item tab missing in choose toolbox item from ssdt 2010

    ssis data flow item and ssis control flow item  tab missing in choose toolbox item from ssdt 2010

    I have the same problem.
     When i click on tools -> choose tools Items dialog box, Control Flow and Data Flow Tab are missing.
    I've just worked with SQL Server Data Tools and SQL Server 2012 and these tabs are not missing.
    i think this is a problem installing SQL Server.
    I've not yet  found a solution.

  • Better control flow?

    Actually this is a general question I've been wondering for a while...
    As the title states, I'm looking for a better control flow statement for what I planned.
    I have 4 variables that determine types of pipe in a program in my main class. There are 6 possible pipe types.
    For example Type 1 would have plastic grade = 5-7, color = 2, inner reinforcement = yes etc.
    My main method determines which type the client chose, (if it matched one of the types or not so if all 4 were true then it matches x type.)
    It's going to get really ugly if I use ifs and I don't think using a case statement would work.
    Any suggestions in what I can use?

    Unless you're just referring to getting user input and using it to look up a pipe >type?That would be what I'm doing, if I could figure out how to get the input variables from my applet class to the class that sorts out which pipe they picked.
    Except the variables had to be defined within a method so the try catch statments could be added to them to catch the nfe as most of them are converted from String to int.
    Let me suggest you to use nested switch case to solve the problemHmm, ok, I'll look into that. Would nested ifs suffice?
    Message was edited by:
    Yuriy_Ivanov

  • Control flow case to return from any page to start page!

    I need to use a Image Link at Master Page for go to "Start page". but when i use control flow case don't work.
    How can i assign a control flow case in a master page?
    My djeveloper version is 11.1.2.3

    You have to define what you mean by master page and start page. Are both pages are on the same talk flow?
    What do you mean by 'the navigation doesn't work'? Do you get an error?
    Normally you implement a wild card navigation which points to the start page. This navigation you use as target for the image link.
    Please post the code of your image link.
    Timo

Maybe you are looking for