Catching changes on components

Hi all
Is there a way to add a listener or something to textfields, checkboxes, comboboxes and everything else that will update you when they have been changed? Can somebody post a simple code snippet?

I think this is what you are looking for:
http://java.sun.com/docs/books/tutorial/uiswing/events
/propertychangelistener.htmlThanks for this. The closest thing that fits what I'm trying to do is the property listener on the keyboardfocusmanager. Still, the problem with that is that is does not shoot until the component is deselected. In the case of a combobox, i'd like to get an update after the field has changed... You know kinda like in a GUI builder. How can you do this, besides adding different types of listeners to everything?

Similar Messages

  • How to change the components of the planned order? (FM or BAPI)

    I need to change the storage(LGORT) in the components.
    I found only MD_PLDORD_CHANGE_COMP_ITEMS, but could not get the correct result.
    Has anyone used this FM to change the components of the planned order?
    Can you please tell how to use it. Or advise an alternative solution.

    Hi Anton,
    There's a BAPI to change planned orders - BAPI_PLANNEDORDER_CHANGE, but it allows to change only header data.
    Therefore you'll have to go a bit longer, and use a couple of other BAPIs:
    First read the order that you want to change - BAPI_PLANNEDORDER_GET_DETAIL
    Second, create a new planned order with the changed data, based on the read planned order - BAPI_PLANNEDORDER_CREATE.
    Third, delete the old planned order - BAPI_PLANNEDORDER_DELETE.
    Regards,
    Mario

  • How to change the components in a visible JPanel?

    How to change the components in a visible JPanel?
    Is there any way to change the components in a JPanel while it is already visible in a JFrame? I tried the na�ve approach of removing the components and adding new ones, but the effect is not the expected.
    For now I'm opening new frames with newly created panels.

    After adding/removing components to/from a panel try:
    panel.revalidate();
    panel.repaint() // sometimes this is also needed, I'm
    not sure whyI'm not certain, but I think that panel.revalidate() implicitly calls repaint() only if something actually changed in the layout. If nothing changed, it sees no reason to repaint; hence, if something changed in appearance but not in layout, you have to repaint it yourself.
    Or something like that. I'm no expert. ;)

  • Change Cost components

    Hi,
    What is the transaction code/path to change Cost components in company code
    thanks

    Cost Component Structure is the Structure maintained for cost sheet/product costing. It is also used if Activity based costing etc.
    The T-code to maintian Cost Component Structure is OKTZ.
    The path is
    IMG-Controlling-Product Cost Controlling-product cost planning-basic setting- define cost component strucure
    Hope this solve your problem
    Pls Assign points if satisfied.

  • How to catch changed column values in alv oops using grid

    My requirement needs to catch changed column values in alv oops using grid .any method to do this.
    please help me out ,
    Tks in advance

    Have a look into the SAP standarad Programs those programs have the edit option on the ALV output.
    BCALV_EDIT_01
    BCALV_EDIT_02
    BCALV_EDIT_10.
    Regards,
    Gopi ,
    Reward points if helpfull.

  • Changing a components UI

    how would i change a components UI, for example.. how would i change the UI of the JFileChooser to only display the DirectoryDrop-Down, UP-Dirrector, and New Folder button on the top, and only the FileName TextField on the bottom, but still keep it's functionallity with the ability to select documents in the middle pane of dirrectories? any help and sample code are appreaciated, thank you.

    Ok, seems that you stiil have problems figuring this out. I have implemented a simple (and stupid) customizer for you. I'm posting the code in case others are interested in this topic (probably not).
    import java.awt.event.*;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Container;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    public class Structure {
        private Structure() {
        public static List createStructure(Container container) {
            Vector vectStructure = fillEditStructure(container, new Vector());
            final JDialog dialog = new JDialog();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setModal(true);
            JTree tree = new JTree(vectStructure);
            StructureEditor editor = new StructureEditor();
            tree.setCellEditor(editor);
            tree.setCellRenderer(new StructureRenderer());
            tree.setEditable(true);
            JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
            dialog.getContentPane().add(split, BorderLayout.CENTER);
            dialog.getContentPane().add(new JButton(new AbstractAction("OK") {
                                            public void actionPerformed(ActionEvent event) {
                                                dialog.dispose();
                                        BorderLayout.SOUTH);
            split.setLeftComponent(new JScrollPane(tree,
                                                   JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                   JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
            split.setRightComponent(container);
            dialog.setResizable(true);
            dialog.pack();
            dialog.show();
            return transformStructure(vectStructure);
        public static void disableComponents(Container container, List listContainerStructure) {
            Component acomponent[] = container.getComponents();
            for (int i = 0; i < acomponent.length; i++) {
                Object objData = listContainerStructure.get(i);
                if (objData instanceof Boolean) {
                    acomponent.setVisible(((Boolean) objData).booleanValue());
    } else if (acomponent[i] instanceof Container && objData instanceof List) {
    disableComponents((Container) acomponent[i], (List) objData);
    private static Vector fillEditStructure(Container container, Vector vectStructure) {
    Component acomponent[] = container.getComponents();
    for (int i = 0; i < acomponent.length; i++) {
    final Component component = acomponent[i];
    final JCheckBox box = new JCheckBox(identifier(component));
    box.setOpaque(false);
    box.setSelected(true);
    box.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent event) {
    component.setVisible(box.isSelected());
    StructureField field = new StructureField(box);
    vectStructure.addElement(field);
    if (component instanceof Container) {
    fillEditStructure((Container) component, field);
    return vectStructure;
    private static List transformStructure(Vector vectStructure) {
    List listStructureList = new ArrayList();
    Enumeration enumFields = vectStructure.elements();
    while (enumFields.hasMoreElements()) {
    StructureField field = (StructureField) enumFields.nextElement();
    if (field.isEnabled() && !field.isEmpty()) {
    listStructureList.add(transformStructure(field));
    } else {
    listStructureList.add(field.isEnabled() ? Boolean.TRUE : Boolean.FALSE);
    return listStructureList;
    private static String identifier(Component component) {
    return component.getClass() + ":" + component.hashCode();
    private static class StructureField extends Vector {
    private JCheckBox box;
    public StructureField(JCheckBox box) {
    this.box = box;
    public JCheckBox getEditBox() {
    return box;
    public boolean isEnabled() {
    return box.isSelected();
    private static class StructureRenderer implements TreeCellRenderer {
    public Component getTreeCellRendererComponent(JTree tree,
    Object value,
    boolean selected,
    boolean expanded,
    boolean leaf,
    int row,
    boolean hasFocus) {
    value = ((DefaultMutableTreeNode) value).getUserObject();
    if (value instanceof StructureField) {
    return ((StructureField) value).getEditBox();
    } else {
    return new JLabel(String.valueOf(value));
    private static class StructureEditor implements ActionListener, TreeCellEditor {
    private ArrayList alListeners = new ArrayList();
    private StructureField field = null;
    public void addCellEditorListener(CellEditorListener listener) {
    alListeners.add(listener);
    public void removeCellEditorListener(CellEditorListener listener) {
    alListeners.remove(listener);
    public Object getCellEditorValue() {
    return field;
    public boolean isCellEditable(EventObject event) {
    return true;
    public boolean shouldSelectCell(EventObject event) {
    return true;
    public boolean stopCellEditing() {
    field.getEditBox().removeActionListener(this);
    fireStopEvent();
    return true;
    public void cancelCellEditing() {
    field.getEditBox().removeActionListener(this);
    fireCancelEvent();
    private void fireCancelEvent() {
    ChangeEvent event = new ChangeEvent(this);
    Iterator it = alListeners.iterator();
    while (it.hasNext()) {
    ((CellEditorListener) it.next()).editingCanceled(event);
    private void fireStopEvent() {
    ChangeEvent event = new ChangeEvent(this);
    Iterator it = alListeners.iterator();
    while (it.hasNext()) {
    ((CellEditorListener) it.next()).editingStopped(event);
    public void actionPerformed(ActionEvent event) {
    stopCellEditing();
    public Component getTreeCellEditorComponent(JTree tree,
    Object value,
    boolean isSelected,
    boolean expanded,
    boolean leaf,
    int row) {
    field = (StructureField) ((DefaultMutableTreeNode) value).getUserObject();
    field.getEditBox().addActionListener(this);
    return field.getEditBox();
    public static void main(String args[]) throws IOException {
    List listStructure = createStructure(new JFileChooser());
    ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("filechooser.structure"));
    output.writeObject(listStructure);
    output.flush();
    output.close();
    System.exit(0);
    After you customize your component, you will have the structure saved in a file. You can either use that fiel to customize all your components, or you can manually create that list.
    This is one example of aplying the customization taken from the file (I will not start to create the list myself just for an example).
    import java.awt.Component;
    import java.awt.Container;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    public class Chooser {
        public static void main (String args[]) throws IOException, ClassNotFoundException {
            JFileChooser filechooser = new JFileChooser();
            ObjectInputStream input = new ObjectInputStream(new FileInputStream("filechooser.structure"));
            List listChooserStructure = (List) input.readObject();
            Structure.disableComponents(filechooser, listChooserStructure);
            filechooser.showOpenDialog(null);
    }As long as the structure of the component is the same, your customization will work.

  • Programatically change JSF Components

    Hi all,
    I need to change "Disable" property of all components of a UIViewRoot based on calculated information. I can put an EL on Disable property to it, but i need to change all components once, and wouldn't like to put a EL on each component. I've tried to do it on Customized ViewHandlerImpl that extends oracle.adfinternal.view.faces.application.ViewHandlerImpl, method renderView
    public void renderView(FacesContext facesContext,
    UIViewRoot uiViewRoot) throws IOException,
    FacesException {
    // Try to get Children here, and change all editables components.
    super.renderView(facesContext, uiViewRoot);
    So, i've attempted get Children before super.renderView call, but in this moment Children is 0 length, only after super.renderView, i can get Children components.
    Has anybody any tip about this?
    Thanks

    user9546730 wrote:
    1. Do we loose any of the ADF faces (including Rich Client framework, partial rendering, Expression bindings, AJAX calls etc) feature by adding the component at runtime or programatically against the typical way of dragging and dropping the component to the screen at design time.(Except the drag and drop functionality and filling the component property at property window!)?No.
    user9546730 wrote:
    I am worried on the features part while taking programmatic approach bcoz i heard that there is no 100% guarantee on Postback features available and Adf component state feature in my scenario, if i take the programmatic approach.Should not be an issue if done correctly.
    user9546730 wrote:
    The scenrio in programatic approach:
    There is one static yyy.jspx, where a declarative component(might be a layout kind of declarative component) is placed and binded to a bean, from the bean i am adding the ADF controls dynamically to the declarative component by parsing an xml.
    Here if multiple users are accessing the yyy.jspx the content inside the declarative component can change user to user, So here the worry is whether the JSF/ADF lifecycle will work properly(the postback, ADF component state saving mechanism etc) for all the users.I would not use a declarative component nor the binding to initialize the component, else you'll calling for state issues that you fear about. Make a fully fledged component and initialize the component subtree in the tag file (or TagHandler if using Facelets, which I doubt you are), after creating the root component (the container).
    Regards,
    ~ Simon

  • Changing form components by selectOneMenu - so easy, but doesn't work

    Hi,
    I have silly problem that makes me crazy: I have a little form and I want to change content of all components dependent on my choice made in selectOneMenu. But it doesn't work like it's supposed to in logical way. For instance I have a selectOneRadio component in which I want to display a proper radio marked dependent on my choice in selectOneMenu. So I am setting Radio's 'rodzaj' bean property (Integer) in the valueChangeListener (idZmWart) of Select element to the chosen value. Bean is updated, but no effect on the page at all, no matter of Select's choice. Am I completely misunderstanding JSF lifecycle (studied many times) or it's just a very stupid mistake?
    Code is below:
    code fragment in jsp page:
    <f:view>
      <h:form>
         <h:selectOneMenu id="wyborId" value="#{Backingbean.id}"
                       valueChangeListener="#{Backingbean.idZmWart}"
                       onchange="submit()">                                  
             <f:selectItems value="#{Backingbean.listaId}" />              
         </h:selectOneMenu>
        <h:selectOneRadio id="wyborRodzaj" value="#{Backingbean.rodzaj}"
                      valueChangeListener="#{Backingbean.rodzajZmWart}"
                      onchange="submit()">
             <f:selectItems value="#{Backingbean.listaRodzaj}"/> 
        </h:selectOneRadio>                              
       <h:commandButton value="button" action="#{Backingbean.button_action}" />                               
    </h:form>
    </f:view>Backingbean code:
    package com.jsf;
    import java.util.ArrayList;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ValueChangeEvent;
    import javax.faces.model.SelectItem;
    public class Backingbean {
       public Backingbean() {
       public String button_action()
          setRodzaj(getId());                
          return "success";
       private Integer id = new Integer(1);
       public Integer getId() {
          return id;
       public void setId(Integer id) {
          this.id = id;
       public void idZmWart(ValueChangeEvent ev) {
          if (ev.getNewValue() != null){
             Integer i = (Integer) ev.getNewValue();
             setRodzaj(i);          
       private ArrayList listaId = new ArrayList();
       public ArrayList getListaId() {     
          ArrayList tmpLista = new ArrayList();
          for (int j=1; j<5; j++) {
             Integer i = new Integer(j);           
             SelectItem si = new SelectItem(i, i.toString());           
             tmpLista.add(si);                    
          listaId = tmpLista;
          return listaId;
       public void setListaId(ArrayList listaId) {
          this.listaId = listaId;
       private Integer rodzaj = new Integer(1);
       public Integer getRodzaj() {
          return rodzaj;
       public void setRodzaj(Integer rodzaj) {
          this.rodzaj = rodzaj;
       private SelectItem[] listaRodzaj = {
          new SelectItem(new Integer(1), "przedmiot"), //value, label
          new SelectItem(new Integer(2), "pracownik"),     
          new SelectItem(new Integer(3), "strona"),     
          new SelectItem(new Integer(4), "menu"),     
       public SelectItem[] getListaRodzaj() {
          return listaRodzaj;     
       public void setListaRodzaj(SelectItem[] listaRodzaj) {
          this.listaRodzaj = listaRodzaj;
       public void rodzajZmWart(ValueChangeEvent ev) {
          if (ev.getNewValue() != null) {
             String sRodzaj = ev.getNewValue().toString();        
    }And fragment of faces-config.xml - in one of the many shapes I've tried
    <managed-bean>
       <managed-bean-name>Backingbean</managed-bean-name>
       <managed-bean-class>com.jsf.Backingbean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       <managed-property>listaId</managed-property>
    </managed-bean>
    <managed-bean>
       <managed-bean-name>listaId</managed-bean-name>
       <managed-bean-class>java.util.ArrayList</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>  
    </managed-bean>Thanks for any reply. Regards,
    savage82

    Yeh sorry the points are not linked so you either can do 1 or 2 or 3
    With 3)
    You would have to bind all the components that get updated by your value changed listeners to your backing bean (using the binding attribute)
    And in your value changed listeners you would call the .setValue() on the components whose variable values changed during the value changed code. When your finished you would call the .renderResponse(). The reason this works is that a straight call to .renderResposne() it seems JSF does something funny, it should call the getters() of your variables then use these values and call the .setValue() on your components. But it doesn�t so instead you call the .setValue() yourself. The problem is you have to update every component potentially allot of work
    point 2 is an easy solution
    from my blog
    public void changeMethod(ValueChangeEvent event)
    PhaseId phaseId = event.getPhaseId();
    String oldValue = (String) event.getOldValue();
    String newValue = (String) event.getNewValue();
    if (phaseId.equals(PhaseId.ANY_PHASE))
    event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
    event.queue();
    else if (phaseId.equals(PhaseId.UPDATE_MODEL_VALUES))
    // do you method here
    }what this does the changeMethod will get called twice. First off it gets called when it is meant to during validation phase. So we catch this call in our if statment then we queue the value changed event until the update model phase. So then when the update model phase is called your value changed event will be fired again. Basically this just moves the value changed code after the setters are called. That way any changes you make to your component values in your value change code will not be overwritten by the setters.
    point 1)
    Sorry forgot to add you may need renderResponse() after navigation rule (should test this)
    using the navigation rule well i dont exactly understand why this works. But my educated guess is using a navigation rule forces jsf to recreate the view i.e. the component tree is lost so the values you change in your value changed listeners will be reflected in your components as the components get recreated with the changed variables values.
    So take the above code
    and replace // do you method here
    with whatever your value changed code would be
    This is possibly a bad solution not exactly sure the performance hit you would take on this one i have never noticed any problems with my system but never benched marked it either.

  • How to catch change cell selection in a JTable?

    I'm using a ListSelectionListener with a JTable to catch the list selection changes but it only detects row changes, and if i select a different cell but within the same row it does not trigger the event.
    Do you guys know a way to detect this event?
    Thanks!!!

    I'm using a ListSelectionListener with a JTable to catch the list selection changes but it only detects row changes,Try adding a listener for the columns as well:
    table.getTableHeader().getColumnModel().getSelectionModel().addListSelectionListener(...);

  • Function Module /BAPI for changing the components in Production order

    Hi,
    We are in ECC5.0. We have requirement wherein we want to change /delete the existing component of the production order and add new component through RFC call from an external system. We tried to use CO_XT_COMPONENT_ADD FM for adding new components and when we tested this FM in SM37  with data there were no error messages . When we checked the Production order ,no changes were made to the production order component. Tried to use Commit statement and there is no change in the system behavior.Can some one help me to  understand the system behavior . If possible kindly suggest me some alternate FM/BAPI .
    With regards,
    Joseph Anand B

    Dear,
    Please check this link,
    ADD COMPONENTS TO PRODUCTION ORDER
    Regards,
    R.Brahmankar

  • Changing AWT components to Swing components

    I'm having a little trouble changing some AWT components to Swing components. I received an error message when I tried to run my program. I looked up the component in the java docs. But, I did not see the option the error was talking about. The error and the area of code is listed below. Thank you for any help you can provide.
    Error message:
    Exception in thread "main" java.lang.Error: Do not use P5AWT.setLayout() use P5A
    WT.getContentPane().setLayout() instead
    at javax.swing.JFrame.createRootPaneException(JFrame.java:446)
    at javax.swing.JFrame.setLayout(JFrame.java:512)
    at P5AWT.<init>(P5AWT.java:56)
    at P5AWT.main(P5AWT.java:133)
    Press any key to continue . . .
    Code:
    JPanel p3 = new JPanel();
    p3.setLayout(new FlowLayout(FlowLayout.CENTER));
    ta = new JTextArea(20, 60);
    p3.add(ta);
    setLayout(new FlowLayout(FlowLayout.CENTER));
    add(p3);

    you need to change the line...
    setLayout(new FlowLayout(FlowLayout.CENTER)); to
    getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));

  • Change JPanel Components

    Hi ya,
    I need some help with what seems like quite a simple problem ... on an action from lets say a JButton I need the contents of a JPanel to change.
    I thought this would work :
    this.getContectPane().add(newPanel);where the current object holds the main JPanel which I want to change. This does not seem to work even if I add the pack(); or setVisible();
    How do I set this view to a new JPanel Object??
    Thanks

    Well normally all you need to do is:
    validate() (for AWT components or revalidate() for
    Swing components
    repaint() is sometimes required.
    If you need further help then you need to create a
    [url
    http://homepage1.nifty.com/algafield/sscce.html]Short,
    Self Contained, Compilable and Executable, Example
    Program that demonstrates the incorrectbehaviour, because I can't guess exactly what you are
    doing based on the information provided.
    And don't forget to use the [url
    http://forum.java.sun.com/help.jspa?sec=formatting]Cod
    e Formatting Tags so the code retains its
    original formatting.
    Thanks for everyones help but I have resolved the problem here, simple little error.

  • Changing a components values by an event of another avoiding recurse calls

    Hello
    assume there are two Components (e.g. an JCheckBox and a JList) placed on a JPanel. The state of the one components shall depend on the state of the other (e.g. If the user selects one or more items in the List, the checkbox has to be selected automatically whereas if the user deselects the checkbox, all the listitems shall be automatically deselected.)
    If I implement two listener for each of the component which call the other ones API, I get recursive calls. (e.g. if I call "JCheckBox.setSelected(boolean)" by the event-method of the JList-Listener, this method would fire an event...)
    One solution would be to implement a model, which is used by both of the components, but this seems to be a little bit oversized for this simple task. Is there another pattern that I could use?
    Thanks
    Thorsten

    As I said: you could use a boolean flag! :-)
    Eg. something like this:
    public class MyPanel extends JPanel{
      private boolean inUpdate = false;
      SomeListener sl1 = new SomeListener(){
        public void someMethod(...){
           if (! inUpdate){
             inUpdate = true;
             // update code -> calls someMethod of sl2
             inUpdate = false;
      SomeListener sl2 = new SomeListener(){
        public void someMethod(...){
           if (! inUpdate){
             inUpdate = true;
             // update code -> calls someMethod of sl1
             inUpdate = false;
      // register the listeners to the components
    }

  • Change BOM components to non-purchase items

    Hi there,
    At the moment for a BOM component, the item cannot be changed from "purchase" to "non-purchase" item. This can only be done if we remove the component from the BOM, change it to non-purchase, and then re-add it.
    We need to do this for hundreds of items regularly. Please can this be fixed, or can this limitation at least be explained?
    Thanks
    Rajiv

    Dear Mr. Agarwalla,
    The documentation on production module available mentions that "As long as the item is linked to a bill of materials, its status cannot be
    modified."
    It is not allowed to change the Item status because it will impact inventory management including MRP.
    Regards
    Preety Goel

  • JFrame change : now components are not resized

    I recompiled a Swing app that I wrote a few years back and noticed that resizing the window does not resize the components within it.
    To see what I mean, compile and run BorderLayoutDemo.java with 1.6, and then with 1.4 (I don't know about 1.5). The buttons will resize in the version compiled and run with 1.4 but will not with 1.6.
    Does anyone know of a readme or tutorial which details what mods I have to make to my code to effect the "old" functionality of having the Components of a JFrame resize using the default ContentPane and LayoutManager ?

    Both work OK for me, 1.4 and 1.6, on winxp

Maybe you are looking for