ActionListener for ComboBox

I'm trying to make the panel realign with the choice received from the ComboBox, but it's not responding at all. Any ideas?
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Layout
     public static int x = 5;
     public static int y = 5;
     public static int itext;
     public static String align = new String();
     public static String RIGHT = new String();
     public static String CENTER = new String();
     public static String LEFT = new String();
     public static void main(String[] args)
          JFrame frame = new JFrame("Exercise 28_1");                   //creating JFrame
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          final JPanel panel = new JPanel();
          panel.setPreferredSize(new Dimension(650, 400));               //setting panel size
          //creating and setting the flowLayout to the panel
          final FlowLayout layout = new FlowLayout();
          panel.setLayout(layout);          
          //making the buttons and adding them to the panel
          panel.add(new JButton("Component 0"));
          panel.add(new JButton("Component 1"));
          panel.add(new JButton("Component 2"));
          panel.add(new JButton("Component 3"));
          panel.add(new JButton("Component 4"));
          panel.add(new JButton("Component 5"));
          panel.add(new JButton("Component 6"));
          panel.add(new JButton("Component 7"));
          panel.add(new JButton("Component 8"));
          panel.add(new JButton("Component 9"));
          panel.add(new JButton("Component 10"));
          panel.add(new JButton("Component 11"));
          panel.add(new JButton("Component 12"));
          panel.add(new JButton("Component 13"));
          panel.add(new JButton("Component 14"));
          //creating ComboxBox and TextFields, and determining their size
          final JComboBox alignment = new JComboBox(new String[]{"LEFT", "CENTER", "RIGHT"});
          alignment.setPreferredSize(new Dimension(570, 25));
          alignment.addActionListener(new ActionListener()   //creating the actionListener
               public void actionPerformed(ActionEvent e)
                    align = (String)alignment.getSelectedItem();
                    if(align == RIGHT)
                         layout.setAlignment(FlowLayout.RIGHT);
                         System.out.println("right");
                         panel.revalidate();
                         panel.repaint();
                    if(align == CENTER)
                         layout.setAlignment(FlowLayout.CENTER);
                         System.out.println("Center");
                         panel.revalidate();
                         panel.repaint();
                    panel.repaint();
                    if(align == LEFT)
                         layout.setAlignment(FlowLayout.LEFT);
                         System.out.println("Left");
                         panel.revalidate();
                         panel.repaint();
          final JTextField hField = new JTextField();
          hField.setPreferredSize(new Dimension(600, 25));
          hField.addActionListener(new ActionListener()   //creating the actionListener
               public void actionPerformed(ActionEvent e)
                    try
                         x = Integer.parseInt(hField.getText()); //parsing the text from the TextField
                    catch(NumberFormatException nfe)
                    JOptionPane.showMessageDialog(null,"Only Numeric Values Allowed"); //catching any non-numeric answers
                    hField.setText("");  //clearing the textField
                    layout.setHgap(x); //setting the Hgap with the entered answer
                    panel.revalidate();
                    hField.setText("");  //clearing the textField
                    panel.repaint();    //repainting the textField with new Hgap value
          final JTextField vField = new JTextField();
          vField.setPreferredSize(new Dimension(600, 25));
          vField.addActionListener(new ActionListener()
               public void actionPerformed(ActionEvent e)
                    try
                         y = Integer.parseInt(vField.getText());
                    catch(NumberFormatException nfe)
                    JOptionPane.showMessageDialog(null,"Only Numeric Values Allowed");
                    vField.setText("");
                    layout.setVgap(y);
                    System.out.println(y);
                    panel.revalidate();
                    vField.setText("");
                    panel.repaint();
          //adding content to panel - labels, comboBox, and TextFields
          panel.add(new JLabel("Alignment"));   
          panel.add(alignment);                         
          panel.add(new JLabel("HGap"));
          panel.add(hField);
          panel.add(new JLabel("VGap"));
          panel.add(vField);
          Container content = frame.getContentPane();
        content.setLayout(new BorderLayout());
        content.add(panel, BorderLayout.NORTH);
          frame.pack();
          frame.setVisible(true);
     } //end of main
} //end of class

Besides; I think you ment to do something like this:
     public static String align = "";
     public final static String RIGHT = "RIGHT";
     public final static String CENTER = "CENTER";
     public final static String LEFT = "LEFT";
     // but you still need to use the equals method in String:
     if (align.equals(RIGHT)) {
          // something
     }But try to remember (and notice) that the align.equals(RIGHT) checks the variable RIGHT, not the String "RIGHT", though, in this case, the variable called RIGHT in fact contains the String "RIGHT".

Similar Messages

  • New Skinning For ComboBoxes

    Does anyone know a good resource for Skinning Comboboxes?  I know basic skining, and have been able to skin the text fields, and the 'openButton' for comboBox, however I am looking to do more.
    Specifically, I want to skin the BG of the dropDown so it will look similiar to this: http://screencast.com/t/NzY5YjYx however, with the BG scaling properly.
    Right now the BG is a MC i made in Flash (cs4) with 9 Slice enabled, and turned on. The skin that I currently have set on the box is as follows:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/mx">
        <!-- host component -->
        <fx:Metadata>
            [HostComponent("spark.components.ComboBox")]
        </fx:Metadata>
        <!-- states -->
        <s:states>
            <s:State name="open" />
            <s:State name="disabled" />
            <s:State name="normal" />
        </s:states>
        <!-- SkinParts
        name=textInput, type=spark.components.TextInput, required=false
        name=openButton, type=spark.components.supportClasses.ButtonBase, required=true
        name=dropDown, type=flash.display.DisplayObject, required=false
        name=scroller, type=spark.components.Scroller, required=false
        name=dropIndicator, type=mx.core.IFactory, required=false
        name=dataGroup, type=spark.components.DataGroup, required=false
        -->
        <s:PopUpAnchor id="popUp"  displayPopUp.normal="false" displayPopUp.open="true" includeIn="open"
                       left="0" right="0" top="0" bottom="0" itemDestructionPolicy="auto"
                       popUpPosition="below" popUpWidthMatchesAnchorWidth="true">
            <s:Group id="dropDown" maxHeight="184" minHeight="50" >
                <!-- drop shadow -->
                <!--- @private -->
                <s:RectangularDropShadow id="dropShadow" blurX="20" blurY="20" alpha="0.45" distance="7"
                                         angle="90" color="#FF0000" left="0" top="0" right="0" bottom="0"/>
                <!-- border -->
                <!--- @private -->
                <s:Rect id="border" left="0" right="0" top="0" bottom="0">
                    <s:fill>
                        <s:SolidColor color="0xff0000" alpha="0"/>
                    </s:fill>
                    <s:stroke>
                        <!--- @private -->
                        <s:SolidColorStroke id="borderStroke" weight="1" alpha="0" />
                    </s:stroke>
                </s:Rect>
                <mx:Image source="@Embed('src/com/mindspark/SkinTest1/assets/testSwf.swf#box2')"  id="background"  height="{dropDown.height}" width="{dropDown.width}"/>
                <!-- fill -->
                <!--- Defines the appearance of drop-down list's background fill. -->
                <s:Rect id="background2" left="1" right="1" top="1" bottom="1" >
                    <s:fill>
                        <!--- 
                        @private
                        The color of the drop down's background fill.
                        The default color is 0xFFFFFF.
                        -->
                        <s:SolidColor id="bgFill" color="0x000000" alpha="0"/>
                    </s:fill>
                </s:Rect>
                <!--- @private -->
                <s:Scroller id="scroller" left="0" top="0" right="0" bottom="0" hasFocusableChildren="false" minViewportInset="1">
                    <!--- @copy spark.components.SkinnableDataContainer#dataGroup-->
                    <s:DataGroup id="dataGroup" itemRenderer="spark.skins.spark.DefaultItemRenderer">
                        <s:layout>
                            <s:VerticalLayout gap="0" horizontalAlign="contentJustify"/>
                        </s:layout>
                    </s:DataGroup>
                </s:Scroller>
            </s:Group>
        </s:PopUpAnchor>
        <s:TextInput id="textInput" text="DOOOGs" skinClass="com.mindspark.SkinTest1.view.skin.TextInputSkin" />
        <!---  The default skin is ComboBoxButtonSkin.
        @copy spark.components.supportClasses.DropDownListBase#openButton
        @see spark.skins.spark.ComboBoxButtonSkin -->
        <s:Button id="openButton" width="19" right="0" top="0" bottom="0" focusEnabled="false"
                  skinClass="com.mindspark.SkinTest1.view.skin.OpenButtonSkin" /> 
    </s:Skin>
    Any help to what i am doing wrong, or a point to a good resource would be really super.  Thanks for the help.

    Hi,
    If you set the constraints rather than width and height it should work
    <mx:Image source="@Embed('src/com/mindspark/SkinTest1/assets/testSwf.swf#box2')"  id="background"
    top="1" left="1" bottom="1" right="1"/>
    David.

  • How to create a actionListener for individual JButton in a for loop?

    How to create a actionListener for individual JButton in a for loop? Can someone help me?

    Do you mean something like this?:
    JButton tempButton;
    for(int i = 0; i < 10; i++){
         tempButton = new JButton("Button " + String.valueOf(i));
         tempButton.setActionCommand("action" + String.valueOf(i));
         tempButton.addActionListener(this);
         // or tempButton.addActionLister(new ActionListener(){...});
         frame.add(tempButton);
    }

  • Flex 3 rowCount thing for combobox happen in flex 4

    I can't find a way to have the flex 3 rowCount thing for combobox happen in flex 4. I tried this:
    <s:ComboBox id="cb" width="240">
                    <s:layout>
                        <s:VerticalLayout requestedRowCount="25" >
                        </s:VerticalLayout>
    but no change

    Heres a skin you could try for the cb lol
    <?xml version="1.0" encoding="utf-8"?>
    <!--
    ADOBE SYSTEMS INCORPORATED
    Copyright 2008 Adobe Systems Incorporated
    All Rights Reserved.
    NOTICE: Adobe permits you to use, modify, and distribute this file
    in accordance with the terms of the license agreement accompanying it.
    -->
    <!--- The default skin class for the Spark DropDownList component.
    The skin for the anchor button for a DropDownList component
    is defined by the DropDownListButtonSkin class.
    <p>In a custom skin class that uses transitions, set the
    <code>itemDestructionPolicy</code> property to <code>none</code>
    for the PopUpAnchor defined by the popUp property.</p>    
    @see spark.components.DropDownList       
    @see spark.skins.spark.DropDownListButtonSkin
    @langversion 3.0
    @playerversion Flash 10
    @playerversion AIR 1.5
    @productversion Flex 4
    -->
    <s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
                 xmlns:fb="http://ns.adobe.com/flashbuilder/2009" alpha.disabled=".5">
        <!-- host component -->
        <fx:Metadata>
            <![CDATA[
            * @copy spark.skins.spark.ApplicationSkin#hostComponent
            [HostComponent("spark.components.DropDownList")]
            ]]>
        </fx:Metadata>
        <fx:Script fb:purpose="styling">
            <![CDATA[           
                /* Define the content fill items that should be colored by the "contentBackgroundColor" style. */
            //    static private const contentFill:Array = ["bgFill"];
                 * @private
            //    override public function get contentItems():Array {return contentFill};
                 * @private
                override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
                    if (getStyle("borderVisible") == false)
                        if (border)
                            border.visible = false;
                        if (background)
                            background.left = background.top = background.right = background.bottom = 0;
                        if (scroller)
                            scroller.minViewportInset = 0;
                    else
                        if (border)
                            border.visible = true;
                        if (background)
                            background.left = background.top = background.right = background.bottom = 1;
                        if (scroller)
                            scroller.minViewportInset = 1;
                    if (dropShadow)
                        dropShadow.visible = getStyle("dropShadowVisible");
                    openButton.setStyle("cornerRadius", getStyle("cornerRadius"));
                    if (borderStroke)
                        borderStroke.color = getStyle("borderColor");
                        borderStroke.alpha = getStyle("borderAlpha");
                    super.updateDisplayList(unscaledWidth, unscaledHeight);
            ]]>
        </fx:Script>
        <s:states>
            <s:State name="normal" />
            <s:State name="open" />
            <s:State name="disabled" />
        </s:states>
        <!---
        The PopUpAnchor control that opens the drop-down list.
        <p>In a custom skin class that uses transitions, set the
        <code>itemDestructionPolicy</code> property to <code>none</code>.</p>
        -->
        <s:PopUpAnchor id="popUp"  displayPopUp.normal="false" displayPopUp.open="true" includeIn="open"
                       left="0" right="0" top="0" bottom="0" itemDestructionPolicy="auto"
                       popUpPosition="below" popUpWidthMatchesAnchorWidth="true">
            <!---
            This includes borders, background colors, scrollers, and filters.
            @copy spark.components.supportClasses.DropDownListBase#dropDown
            -->
            <s:Group id="dropDown" maxHeight="800" minHeight="22" >
                <!--- @private -->
                <s:RectangularDropShadow id="dropShadow" blurX="20" blurY="20" alpha="0.45" distance="7"
                                         angle="90" color="#000000" left="0" top="0" right="0" bottom="0"/>
                <!--- @private -->
                <s:Rect id="border" left="0" right="0" top="0" bottom="0">
                    <s:stroke>
                        <!--- border stroke @private -->
                        <s:SolidColorStroke id="borderStroke" weight="1"/>
                    </s:stroke>
                </s:Rect>
                <!-- fill -->
                <!--- Defines the appearance of drop-down list's background fill. -->
                <s:Rect id="background" left="1" right="1" top="1" bottom="1" >
                    <!--    <s:SolidColor id="bgFill" color="0xFFFFFF" />-->
                    <s:stroke>
                        <s:SolidColorStroke color="#555555" />
                    </s:stroke>
                    <s:fill >
                        <s:LinearGradient rotation="75" >
                            <s:GradientEntry color="0x0e47a5"  />
                            <s:GradientEntry color="0x27c1f4" />
                            <s:GradientEntry color="0x0e47a5" />
                        </s:LinearGradient>
                    </s:fill>  
                </s:Rect>
                <!--- @private -->
                <s:Scroller id="scroller" left="0" top="0" right="0" bottom="0" hasFocusableChildren="false" minViewportInset="1">
                    <!--- @copy spark.components.SkinnableDataContainer#dataGroup-->
                    <s:DataGroup id="dataGroup" itemRenderer="spark.skins.spark.DefaultItemRenderer">
                        <s:layout>
                            <s:VerticalLayout gap="0" horizontalAlign="contentJustify" requestedRowCount="15"/>
                        </s:layout>
                    </s:DataGroup>
                </s:Scroller>
            </s:Group>
        </s:PopUpAnchor>
        <!---  The default skin is DropDownListButtonSkin.
        @copy spark.components.supportClasses.DropDownListBase#openButton
        @see spark.skins.spark.DropDownListButtonSkin -->
        <s:Button id="openButton" left="0" right="0" top="0" bottom="0" focusEnabled="false"
                  skinClass="spark.skins.spark.DropDownListButtonSkin" /> 
        <!--- @copy spark.components.DropDownList#labelDisplay -->
        <s:Label id="labelDisplay" verticalAlign="middle" maxDisplayedLines="1"
                 mouseEnabled="false" mouseChildren="false"
                 left="7" right="30" top="2" bottom="2" width="75" verticalCenter="1" />
    </s:SparkSkin>

  • [svn:fx-trunk] 12982: Fix for issue with exposing accessible names for combobox list items

    Revision: 12982
    Revision: 12982
    Author:   [email protected]
    Date:     2009-12-15 20:44:23 -0800 (Tue, 15 Dec 2009)
    Log Message:
    Fix for issue with exposing accessible names for combobox list items
    QE notes: none
    Doc notes: none
    Bugs: n/a
    Reviewer: Gordon
    Tests run: checkintests
    Is noteworthy for integration: no
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/accessibility/ComboBoxAccImpl.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/accessibility/ListBaseAccImpl.as

    Add this to the end of your nav p CSS selector at Line 209 of your HTML file, after 'background-repeat...':
    margin-bottom: -2px;
    Your nav p will then look like this:
    nav p {
              font-size: 90%;
              font-weight: bold;
              color: #FFC;
              background-color: #090;
              text-align: right;
              padding-top: 5px;
              padding-right: 20px;
              padding-bottom: 5px;
              border-bottom-width: 2px;
              border-bottom-style: solid;
              border-bottom-color: #060;
              background-image: url(images/background.png);
              background-repeat: repeat-x;
              margin-bottom: -2px;

  • Actionlistener - for multiple buttons with similar functionality

    Hi, all:
    I'm working on a calculator program and want to know how to go about making a generic ActionListener for all the functions (i.e. +,-,*,/) so that I don't have to write separate inner classes for each function (i.e. + button, - button, etc.).
    I think this generic class should be created within a method that takes parameters. The parameters are then used within the inner class.
    What I need to know specifically is whether it's possible to pass a string operator symbol (e.g. "+" or "-") as a parameter in the following context:
    class buttonListener implements ActionListener
    public void actionPerformed(ActionEvent e)
    intField1Val + intFieldVal2;
    in this case, the "+" would be the parameter that would change depending on the values provided to the method.
    Can this be done??
    I'd also appreciate any other feedback you can give m,e on this problem (i.e. how to set up the method...basic structure??)
    Thanks!!

    Hi there,
    One way to do this is as follows:
    Button plus = new Button("+");
    Button minus = new Button("-");
    public void actionPerformed(ActionEvent e) {
    String componentHit = e.getActionCommand();
    if (componentHit == "+") {
    doAddMeth(); // implemented elsewhere
    else
    if (componentHit == "-") {
    doSubMeth(); // implemented elsewhere
    ~Bill

  • Skinning Cell Renderer for ComboBox

    How does one change styles for the CellRenderer of a
    ComboBox?
    Flash help gives a nice example on how to skin CellRenderer
    styles for Datagrid and TileList components, but doesn't mention
    anything on how to do the same for a ComboBox.
    The code example for Datagrid and TileList doesn't work for
    ComboBox.

    Hi camickr - I apologize for initiating new threads. Although I am aware that I should reply to follow-up, to me these was a totally different question from the others, although the context was the same.
    I'll be more careful though !
    Thanks for your reply. Actually I got the two (Boolean and Object) renderers working. The problem I am having now is that before I implented the rendering piece, once I clicked on a row, it got highlighted, however now, after implementing these, that doesn't happen anymore. How can I get it to behave as before, where it highlighted a particular row ?
    Here is the code. Thanks again !
        table.setDefaultRenderer(Boolean.class, new TableRenderer());
       table.setDefaultRenderer(Object.class, new TableTextRenderer());
    //cell renderers
    class TableRenderer extends JCheckBox implements TableCellRenderer {
        public Component getTableCellRendererComponent(JTable table,
                                Object value, boolean isSelected,
                                boolean hasFocus, int row, int column ) {
            setSelected(((Boolean)value).booleanValue());
              if( row >= 3){
                setBackground( Color.yellow );
            else setBackground(Color.white);
            return this;
      class TableTextRenderer extends JTextArea implements TableCellRenderer {
          public Component getTableCellRendererComponent(JTable table,
                                  Object value, boolean isSelected,
                                  boolean hasFocus, int row, int column ) {
        JTextArea label = new JTextArea();
        label.setText((String)value);
        label.setBackground(Color.yellow);
                if( row >= 3 && column == 0){
                  setBackground( Color.yellow );
             else label.setBackground(Color.white);
      return label;
      }

  • Reusable ActionListener  for logging

    I am trying to develop an reusable ActionListener class called ActionLogger that will log user actions. I would like to use this ActionListener for different buttons in different forms and pages.
    Following scenario:
    User can:
    1. create an new message
    2. change an existing message
    3. acknowledge an message
    4. delete an message
    <h:commandButton action=?createMessage?>
    <f:actionListener type=? ActionLogger? />
    </h:commandButton>
    or
    <h:commandButton action=?deleteMessage?>
    <f:actionListener type=? ActionLogger? />
    </h:commandButton>Each action must be logged with date, userName (full user name) actionName (which button have been clicked.)
    I can get the user Object with firstName and lastName out of the Session Map, but how can I know which button have he clicked on, and if action method in the backing bean was successful or not??
    Any Ideas??
    Thank you in advance:
    Nermin B.

    You can assign ids to the individual commandButton components. When the ActionEvent
    arrives (and is accessible from the listener), it contains the source component - the component that
    caused the event.
    -roger

  • Maintaining global lists for ComboBox values

    I would like to maintain multi-lingual lists of allowable categories to be used
    in ComboBox controls. The values for these lists should be stored external to
    the application or at some global level to that they can be maintained by someone
    who is not necessarily a developer.
    When the user chooses a language when the application runs, the arrayCollections
    containing the data/value pairs should be loaded with the data in the appropriate
    language. These arrayCollections would be then bound as the data providers to
    ComboBox controls in the various modules and components of the application.
    For example, in an application about cars there could be a ComboBox containing
    colors  - in English (red, gray, blue, black) in German (rot, grau, blau, schwarz).
    There could also be a ComboxBox containing body types: (sedan, coupe, convertible)
    or (limosine, coupe, cabriolet).
    ComboBoxes using the data could be used anywhere in the application - in modules,
    components or whatever.
    What would be the best way to approach this from a design perspective? Where should
    the lists to be loaded into the control's data provider at run time be stored?
    Scott

    Resource modules are probably the right answer. They can even do an enumeration of sorts (an Array of Strings, which sounds like it could be a good fit for colors). In any case, if you ensure that your model (e.g., CarBuilderManager, with methods like getColors() and getBodyTypes()) is cleanly separated from your views and the actual comboboxes, you can do your localization work in there. Then, in your view, you can declare comboboxes like
    <mx:ComboBox id="colors" dataProvider="{model.getColors()}"/>
    and you can easily adapt the localization without changing the view (e.g., if you find ResourceManager is not doing it for you, you can roll your own localization method).

  • Hw do i set background color for ComboBox?

    If anyone knows how to set background color for disabeld (setEnabled(false)) of ComboBox in Windows Look and Feel. It will help me a lot.
    I don't know hoe to do it
    regards
    arun.

    At the start of your program add:
    UIManager.put("ComboBox.disabledBackground", Color.green);
    UIManager.put("ComboBox.disabledForeground", Color.blue);For a list of all the properties you can change with the UIManager see:
    http://www.discoverteenergy.com/files/ShowUIDefaults.java

  • Formatting textfile for Combobox.dataProvider

    Can't seem to find any formatting rules for array
    construction through an external file.
    This is what i am trying to do:
    I've loaded vars into the _root this works fine. Splitted its
    value for constructing an array. This seems to work fine aswell.
    If I code the array within the fla in this format:
    my_dP= new Array(
    {label:"choose..."},
    {data:"
    http://www.myserver.com/netlabel/Johannes
    Lauxen.txt",label:"Johanes Lauxen"},
    {data:"
    http://www.myserver.com/netlabel/PQR1.txt",
    label:"PQR1"}
    and use this for the dataProvider for the combobox named
    my_cb like this:
    my_cb.dataProvider = my_dP;
    everything works fine.
    The problem is:
    But if I put this in the same formatting in the textfile for
    the array I create using split like I described above, the values
    for my labels in my_cb are this text, i mean it doesn't
    interpretate the loaded text as script, it just displays the code
    as labels.
    my textfile looks like this :
    &var2={label:"choose..."}#{data:"
    http://www.myserver.com/netla
    bel/Johannes Lauxen.txt",label:"Johanes
    Lauxen"}#{data:"
    http://www.myserver.com/netlabel/PQR1.txt",
    label:"PQR1"}&
    (O, the # is used for delimiter)
    How can i get this to work ? Or is it not the
    textfileformatting that causes the problem ?
    many thanks
    (flash8 b.t.w.)

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="450" height="350">
        <mx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                [Bindable]
                private var types:Array = ['colors','numbers','shapes'];
                private var dataProviders:Object =
                    colors:['red','blue','green'],
                    numbers:['1','2','3'],
                    shapes:['circle', 'square','triangle']
                private function getItemDataProvider(type:Object):Array
                    return dataProviders[type] as Array;
            ]]>
        </mx:Script>
            <mx:ComboBox id="typeSelector" dataProvider="{types}"/>
            <mx:ComboBox id="itemSelector" dataProvider="{getItemDataProvider(typeSelector.selectedItem)}"/>
    </mx:Application>

  • Highlight color for Combobox

    I have a JComboBox, when i navigate between the various items inside the Combobox, it gets highlighted by some color. I want to know how to get that color object, i want to use the same color for something else. What would be the RGB combination for tat color?

    Popup, or drop down, list of JComboBox is a JList object.
    JList has getSelectionBackground() and ---Foreground() methods to get selection highlight
    color. In order to access the JList object in a JComboBox, study the source code
    JComboBox.java. Especially, its AccessibleJComboBox() constructor is the key.
    Alternately, you could use:
    UIManager.getColor("ComboBox.selectionBackground")
    // and
    UIManager.getColor("ComboBox.selectionForeground")

  • Using array as a dataprovider for combobox

    Hi folks, I would apreciate some help.
    I have a multi dimentional array as per
    _dbNames[0]=["Initialize User","","",""];
    How can assign an array like this as a dataprovider to a
    combobox using actionscript 3?
    Thanks for for the help!!

    Hey Jarno, 
    I did some playing around with this (sorry for the delay) and another workaround we can use is adding an Always Copy to the array before passing it into the Script Node. This will allow you to continue using Double precision arrays instead of going to Singles.
    It looks like there is an issue with the array copy that is passed into the SubVI through the terminal, but we can get around it by making a new copy that the Script Node can properly work with. 
    Tim A.
    National Instruments

  • ActionListener for JComboBox

    If I add an ActionListener to JComboBox or ComboBoxEditor I can get notified when user types some text into the combo-box and presses enter.
    If I need to get notifications after user types each letter. What should I do ?
    I'm stuck with this problem for a long time (I'm a beginner) - any help would be greatly appreciated. Thanks a lot,
    --Sergei 

    This would be my solution. There may be more but, this is the mest i can do;)
    So adding KeyListener.
    Let "cb" be your JComboBox object name, what you have to do is:
    cb.setEditable(true);
    ComboBoxEditor ce = cb.getEditor();
    ce.getEditorComponent().addKeyListener(this);
    here is the entire example. This progtram will count your keyevents
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Example extends Frame implements KeyListener
         private JComboBox cb = new JComboBox();
         private JLabel lab = new JLabel(" ");
         int numb = 0;
         public Example()
              cb.setEditable(true);
              ComboBoxEditor ce = cb.getEditor();
              ce.getEditorComponent().addKeyListener(this);
              setLayout(new FlowLayout());
              add(cb);
              add(lab);
              setSize(200,200);
              show();
         public static void main(String args[])
              new Example();          
         public void keyPressed(KeyEvent e)
         public void keyReleased(KeyEvent e)
                   numb ++;
                   lab.setText(Integer.toString(numb));
         public void keyTyped(KeyEvent e)

  • Need help creating actionListener for an array of text fields

    I am working on a school project, so I am very new to Java. I have a program which is basically a unit converter. Each unit type has its own tab. I was able to dynamically create text fields in each tab and now I need to add actionListener to each of those text fields. Probelm is, the text fields are not really unique. I guess they're only unique within their tab. So now I am having difficulty referring to my text fields. If you look at my actionListener in the code below, I am trying to refer to it as unitTFs[0].getText() and that's not working. Please help. Thanks in advance.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class UnitConverter extends JPanel
    public UnitConverter()
    String[] lengthUnits = {"cm","m","inch","feet","yard","mile"};
    String[] areaUnits = {"m2","a","feet2","yd2","Acre","ha"};
    String[] massUnits = {"g","kg","ton","ounce","pound"};
    String[] volumeUnits = {"liter","m3","inch3","feet3","Gallon","Barrel"};
    String[] tempUnits = {"C","F"};
    ImageIcon lengthICN = new ImageIcon("java-swing-tutorial.JPG");
    ImageIcon areaICN = new ImageIcon("java-swing-tutorial.JPG");
    ImageIcon massICN = new ImageIcon("java-swing-tutorial.JPG");
    ImageIcon volumeICN = new ImageIcon("java-swing-tutorial.JPG");
    ImageIcon tempICN = new ImageIcon("java-swing-tutorial.JPG");
    JTabbedPane tabPaneJTP = new JTabbedPane();
    JPanel lengthPNL = tabContents(lengthUnits);
    tabPaneJTP.addTab("Length", lengthICN, lengthPNL);
    tabPaneJTP.setSelectedIndex(0);
    JPanel areaPNL = tabContents(areaUnits);
    tabPaneJTP.addTab("Area", areaICN, areaPNL);
    JPanel massPNL = tabContents(massUnits);
    tabPaneJTP.addTab("Mass", massICN, massPNL);
    JPanel volumePNL = tabContents(volumeUnits);
    tabPaneJTP.addTab("Volume", volumeICN, volumePNL);
    JPanel tempPNL = tabContents(tempUnits);
    tabPaneJTP.addTab("Temperature", tempICN, tempPNL);
    //Add the tabbed pane to this panel.
    setLayout(new GridLayout(1, 1));
    add(tabPaneJTP);
    protected JPanel tabContents(String[] units)
    JPanel tabPNL = new JPanel();
    JTextField[] unitTFs = new JTextField[units.length];
    JLabel[] unitLs = new JLabel[units.length];
    for (int i = 0; i < units.length; i++)
    unitTFs[i] = new JTextField("0");
    unitLs[i] = new JLabel(units);
    tabPNL.add(unitTFs[i]);
    tabPNL.add(unitLs[i]);
    tabPNL.setLayout(new GridLayout(units.length, 1));
    return tabPNL;
    private class CmHandler implements ActionListener
    public void actionPerformed(ActionEvent e)
    double cm, m;
    cm = Double.parseDouble(unitTFs[0].getText());
    public static void main(String[] args)
    JFrame frame = new JFrame("Unit Converter Demo");
    frame.getContentPane().add(new UnitConverter(), BorderLayout.CENTER);
    frame.setSize(500, 500);
    frame.setVisible(true);

    Variables only have scope in the method (or block) in which they are created. That means if you create a variable in one function, you can't use it in another.
    If you want to use a variable in two different functions, you have to make it a member variable.
    [Declaring Member Variables|http://java.sun.com/docs/books/tutorial/java/javaOO/variables.html]

Maybe you are looking for

  • How to save settings in iPhoto '11 (9.1.3)?

    Hello, does everybody know how to save settings in iPhoto '11 (9.1.3)? Always when I change settings, for example when I check "Copy items to the Library", it is after new start up restored to the default. Also every start up appears "Welcome to iPho

  • Can iphoto 9 and iphoto 11 work on same computer

    I have a very large 222,000 file in iphoto 9 and when I upgraded my machine to iphoto 11 it crashed when I tried to move it into iphoto 11.  I have a backup but need to know what is the best way to handle the situation?

  • Downloading converted PDF file - output is truncated

    Hi - My requirement is to convert an SAP spool to a PDF file and download it to the presentation server. It is working, however, when I open the PDF file, the output is truncated such that only 132 characters of each line are being displayed (instead

  • LIS vs. BW

    All, I am looking for some feedback regarding LIS. I know that LIS once used to be used quite a lot but with BW I would have assumed that LIS goes more away from being used for new SAP implementation. On my current project they woulike the full exten

  • Newly opened windows can trash history and groups if closed last

    If I have FF set up to remember last opened tabs and groups, and I open a new window (or a link opens in a new window), then if I don't see that "new" window and close my main one, all my tabs and groups are lost. In fact the browser will remember ju