How to add action listener to internal frame?

I have frame Main where I am trying to add action listener.
Action listener should be listening button in frame Menu.
I think it should be:
Menu frame = new Menu();
frame.btn_start.addActionListener(this);but it seems to be doing absolutely nothing.
If I try to add in menu:
btn_start.addActionListener(new Main());it generates: java.lang.StackOverflowError
What should I do? Please help noob :)

To get better help sooner, post a [_Short, Self Contained, Compilable and Executable, Example Program (SSCCE)_|http://mindprod.com/jgloss/sscce.html] that clearly demonstrates your problem.
You're quite possible adding the ActionListener to the wrong component. And constructing a new instance of a class within the constructor is likely the cause of your StackOverflowError.
db

Similar Messages

  • How to add HTTP Header Response X-Frame-Options:SAMEORIGIN from OWA published via Forefront TMG 2010 to stop Clickjacking

    How to add HTTP Header Response X-Frame-Options:SAMEORIGIN from OWA published via Forefront TMG 2010 to stop Clickjacking. I have put the IIS setting X-Frame-Options:SAMEORIGIN  on my Internal CAS Server. However as the OWA page is published through
    Forefront TMG 2010, the iFrame tag is not blocked when the page is first opened. Only when you login with your credentials to the OWA page inside the frame and the page reaches IIS on the Internal CAS it gets blocked. I want to block it in the first
    instance when it is opened from TMG.

    Hi,
    Thank you for the post.
    To modify the http header, please refer to this blog:
    http://tmgblog.richardhicks.com/2009/03/27/using-the-isa-http-filter-to-modify-via-headers-and-prevent-information-disclosure/
    Regards,
    Nick Gu - MSFT

  • Add action listener to an image....

    Hello there,
    I was wondering is it possible to add action listener to an image to connected back to a different page....
    for example if i have this code:
    ImageComponent displayFrame = new ImageComponent();
    add(displayFrame,"West");
    displayFrame.setBounds( 90,100,52,58);
    in one of my frame calling an instance Image component...
    Your coorperation is greatly appreaciated,
    Thanks,
    -pal-

    Here are a couple of suggestions.
    First suggestion is to use java.awt.CardLayout. This sets up a series of "cards" where only one is visible at a time.
            ActionListener buttonListener = new ButtonListener();
            JButton mainButton = new JButton("Forward");
            mainButton.addActionListener(buttonListener);
            JButton subButton = new JButton("Back");
            subButton.addActionListener(buttonListener);
            menuLayout = new java.awt.CardLayout();
            menuPanel = new JPanel(menuLayout);
            menuPanel.add("Main", mainPanel);
            menuPanel.add("Sub", subPanel);
        class ButtonListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                String cmd = e.getActionCommand();
                if (cmd.equals("Forward")) {
                    menuLayout.show(menuPanel, "Sub");
                } else if (cmd.equals("Back")) {
                    menuLayout.show(menuPanel, "Main");
        }The other suggestion would be to use javax.swing.JDialog. That might be a little cleaner because it could be set up modal. It depends on what your menus look like. Check out this:
    http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html

  • Add action listener to table cell

    The topic of my previous thread was:
    How can I get characters, which user inputs into table cell?
    I've added lisateners to table:
    table.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt){
                    System.out.println("keyPressed");
                public void keyReleased(java.awt.event.KeyEvent evt){
                    System.out.println("keyReleased");
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    System.out.println("keyTyped");
            });But it's not exactly what I need.
    I need to do the same, but with table cell.
    I want to see user input char by char and set color font for user input string.
    How can I add action listener to tble cell?

    This is my newly created JTextField which I will use as CellEditor for My JTable
    JTextField textField = new JTextField(); //creating Component
            textField.addKeyListener(new java.awt.event.KeyAdapter(){ //adding KeyListener
                public void keyReleased(java.awt.event.KeyEvent evt){
                    System.out.println("keyReleased" + ((JTextField)evt.getSource()).getText() + "column = " +table.getSelectedColumn());//test functionality
                    if ( isColumnHasSameValue(table.getSelectedRow(),table.getSelectedColumn(), ((JTextField)evt.getSource()).getText() ) ){//test column for equal values
                        ((JTextField)evt.getSource()).setForeground(Color.RED); //if there is equal value set Color.RED for JTextField text
                    else{ //else set Color.BLACK
                        ((JTextField)evt.getSource()).setForeground(Color.BLACK);
            table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(textField)); //set custom CellEditor
    private boolean isColumnHasSameValue(int row, int column, String testVal){
            testVal = testVal.trim().toLowerCase(); //put away UpperCase and empty spaces
            for(int i=0;i<model.getRowCount();i++){
               if(i == row){
                   continue;//skip selected row where user inputs text
               if(model.getValueAt(i,column).toString().trim().toLowerCase().startsWith(testVal)){
                    return true; //if test passed
            return false; //if there are no mathes
        }I have a question:
    It seems to me, I did not use optimal solution for JTable values testing.
    What can ty else?
    Maybe, It is better to use
    tableModel.getDataVector();And then use Pattern and Matcher ?
    Am I right?

  • Windows 8 and PSE7 and PSE11 how to add actions

    I changed over to Windows 8.  PSE 7 downloaded and opens up just fine.  I cannot seem to find any info on how to add actions to PSE7.  Windows 8 is not setup like 7.  There is no start button.  You cannot input programdata to find the hidden files.  I downloaded PSE11 trial version thinking it was just PSE 7..........same thing, downloaded no problem, opens up but how do you add actions?   I used many actions to resize the file, sharpen, and a few makeover actions by Florabella.  I would love to be able to use those again.   Thank you.

    You probably need to do some study on how Microsoft expect Windows 8 to be used, especially if you don't have a touch screen.
    Two thoughts
    1. If you don't have a touch screen, Adobe Reader Touch may not be the best choice. It is much more limited than the regular Adobe Reader. Did you pick it for a reason, or just because Microsoft encouraged you into their App Store?
    2. Try a right click, sometimes seems to substitute for a touch off the edge. I know you can't just use the mouse as if it were touch.

  • How to know which leaf node i click and how to add a listener to each node?

    hi! hello to all members, i have a problem i know how to create a listener, but i dont know how to add a listener to each leaf node. here is the scenario i want to do, i have a JTree where theres a topic that you can select on each leaf node, so when the user click the specific topic it will open another JFrame,which i dont know how to do it also, that its! the next problem will be how do i know which leaf node i select, so that i can open a right topic before the JFrame will open?please, i am very need this to solve quickly as possible. thanks again to all members.

    What you have to do is to add a mouse listener on your JTree. Try something like this:
    tree.addMouseListener(new java.awt.event.MouseAdapter() {
             public void mouseReleased(MouseEvent e) {
                tree_mouseReleased(e);
    private void tree_mouseReleased(MouseEvent e) {
          TreePath selPath = tree.getSelectionPath();
          // Check If the click is the Right Click
          if (e.isPopupTrigger() == true) {
          // This is your right Click
           else {
                     // This is your Left Click
    }Your other problem: Set the userObject on nodes and on left click compare it with your object, if it matches, display the appropriate file. Alternatively, if your nodes are unique, you can match the names to open the file.
    Hope this Helps
    Regard
    Raheel

  • How do I only allow 1 internal frame to be added?

    Could you pls show me how can I do this, I need some code to learn how this code work.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Test1a extends JFrame
         private JLabel label1;
    //     private JLabel label2;
         private JLabel label3;
         private JLabel label4;
         private JLabel label5;
         private JDesktopPane theDesktop;
         public Test1a()
              super("TESTING JLABEL");
              setLayout(new BorderLayout(5, 5));
            JMenuBar bar = new JMenuBar();
          JMenu addMenu = new JMenu( "Add" );
          JMenuItem newFrame = new JMenuItem( "Internal Frame" );
          addMenu.add( newFrame );
          bar.add( addMenu );
          setJMenuBar( bar );
           theDesktop = new JDesktopPane();
          add( theDesktop, BorderLayout.CENTER );
          newFrame.addActionListener(
             new ActionListener()
                // display new internal window
                public void actionPerformed( ActionEvent event )
                   // create internal frame
                   JInternalFrame frame = new JInternalFrame("Internal Frame", true, true, true, true);
                   MyJPanel panel = new MyJPanel();
                   frame.add( panel, BorderLayout.CENTER );
                   frame.pack(); // set internal frame to size of contents
                   theDesktop.add( frame );
                   frame.setVisible( true );
              label1= new JLabel ();
              label1.setText("Label 1");
              add(label1, BorderLayout.WEST);
         //     label2= new JLabel ("Label 2", SwingConstants.CENTER);
         //   add(label2, BorderLayout.CENTER);
              label3= new JLabel ();
              label3.setText("Label 3");
              add(label3, BorderLayout.EAST);
              label4= new JLabel ("Label 4", SwingConstants.CENTER);
              add(label4, BorderLayout.NORTH);
              label5= new JLabel ("Label 5", SwingConstants.CENTER);
              add(label5, BorderLayout.SOUTH);
    =============================================
    import java.awt.*;
    import javax.swing.*;
    // class to display an ImageIcon on a panel
    class MyJPanel extends JPanel
       private ImageIcon imageIcon;
       // load image
       public MyJPanel()
          imageIcon = new ImageIcon("yellowflowers.png");
       // display imageIcon on panel
       public void paintComponent( Graphics g )
          super.paintComponent( g );
          imageIcon.paintIcon( this, g, 0, 0 );
       public Dimension getPreferredSize()
          return new Dimension( imageIcon.getIconWidth(), imageIcon.getIconHeight() ); 
    ========================================
    import javax.swing.*;
    public class Test1b
         public static void main (String args[])
              Test1a test1a = new Test1a();
              test1a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              test1a.setSize(800, 600);
              test1a.setVisible(true);
    }

    You where given an answer in your original posting:
    http://forum.java.sun.com/thread.jspa?threadID=5146301

  • How to add event listener?

    i want to add event listener when i click on a button in mxml, the event listener should be added in the action script file, how to do this?
    can anyone help? urgent!!!

    Hi Lakshmi,
    You can do this just put all the script in the mxml block in seperate AS file as shown below... Observe that I have included an AS file named Script.as and removed the script block form mxml and moved to this Script.as file. Place the Script.as file in your src folder ....
    // Main mxml file....
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onCreationComplete()">
        <mx:Script source="Script.as"/>
    <mx:TextArea id="textArea" width="300" height="100" />
    <mx:Button id="myButton" label="Click ME"/>
    </mx:Application>
    //Script.as file
    import mx.controls.Alert;
                private function onCreationComplete():void
                 myButton.addEventListener(MouseEvent.CLICK, onButtonClick);
                private function onButtonClick(event:MouseEvent):void
                 Alert.show("Button is Clicked");
    Thanks,
    Bhasker

  • Urgent.. How to add a menubar to a frame by reading a file

    Hi All,
    I am involved in a project where in i need to add a menubar to the frame by reading a text file. The text file consists of all the Menu Items and subMenu items.This text file will be a editable file where-in the user can add his own menu-items.
    i.e when i run the java program i should read the menu items from a file and then display those menuitems in the Menubar.
    I am not getting the idea how i should proceed. Can any one help.
    Thanks in advance.
    Regards
    Ravi Kumar

    Sorry again - my use of i as an array index wasn't very clever. The post should have been as follows:
    Hi,
    You can read in the menu names from the file and add them fairly simply, with something like this:
    JMenuBar jmb = new JMenuBar();
    JMenu myMenu = new Jmenu("Custom");
    jmb.add(myMenu);
    in = new BufferedReader(new FileReader("file.txt"));
    JMenuItem [] menulist = new JMenuItem[MAXITEMS];
    for (int j=0; j < MAXITEMS; j++) {
    menulist[j] = new JMenuItem(in.readLine());
    myMenu.add(menulist);
    Then add the JMenuBar to the parent frame.
    However, for the menus to be of much use, you'd need to add actionlisteners to them as well.
    If you had a set of possible menu items, and it was just a question of which order the user's file defined them in, and which it used, you could then just test the name of each item in the file and assign an appropriate class of actionlistener to it, something like:
    if(menuitem.getText().equals("Open")) {
    menuitem[j].addActionListener(new OpenActionListener());
    where you'd defined the OpenActionListener class somewhere else.
    Hope this helps,
    Neil
    http://www.theBatCave.org.uk
    (Not having a very good day!)

  • How to add a Listener to the JLabel

    Hi,
    I am doing a Designer module in which i want to Listen Focus gained event on JLabel. For that i have added FocusListener to the JLabel but it does not listen to this event. (i think because of JLabels extraodinary property).
    So How to add listener to the JLabel?

    Set the label to be focusable. This will allow it to gain focus from the
    keyboard (from pressing TAB, for example), but not from being clicked on.
    It's easy to give some demo code than to explain it:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class LabelListening extends MouseAdapter implements FocusListener {
        private static final String TEXT_KEY = "jlabel_text_key";
        public void focusGained(FocusEvent e) {
            JLabel label = (JLabel) e.getComponent();
            String text = (String) label.getClientProperty(TEXT_KEY);
            label.setText("<html><u>" + text + "</u></html>");
        public void focusLost(FocusEvent e) {
            JLabel label = (JLabel) e.getComponent();
            String text = (String) label.getClientProperty(TEXT_KEY);
            label.setText(text);
        public void mousePressed(MouseEvent e) {
            e.getComponent().requestFocusInWindow();
        public static void main(String[] args) {
            LabelListening app = new LabelListening();
            JPanel contentPane = new JPanel();
            for(int i=0; i<4; ++i) {
                String text = "label " + i;
                JLabel label = new JLabel(text);
                label.putClientProperty(TEXT_KEY, text);
                label.setFocusable(true);
                label.addFocusListener(app);
                label.addMouseListener(app);
                contentPane.add(label);
            JButton btn = new JButton("a button");
            btn.setBorderPainted(false);
            btn.setContentAreaFilled(false);
            btn.setMargin(new Insets(0,0,0,0));
            contentPane.add(btn);
            final JFrame f = new JFrame("");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(contentPane);
            f.pack();
            SwingUtilities.invokeLater(new Runnable(){
                public void run() {
                    f.setLocationRelativeTo(null);
                    f.setVisible(true);
    }In this example, I have the focused label underlined. I don't
    know what your context is, but it may be simpler just to work with
    buttons instead. I "undecorate" a button in this example to make it look
    similar to a label.

  • How to add scrollbar to the JInternal Frame

    How to add scrollbar to JInternal Frame?
    I have One JInternal frame i want it should have a scrollbar when we reduces its size.

    [url http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html]How to Use Scroll Panes

  • How to add actions to Elements 10

    How does one add actions to elements 10? I have access to some PS action files but the help file does not explain how to add them to Elements. Helps says to Click Add on the Actions panel, but there is no where "add" option.

    Install Actions in PSE
    scroll down to Install Actions in PSE 9 and 10.

  • How to add actions to keyboard?

    Hello I´ve been looking around the net, and found a lot
    of confusing information.
    I would like to know how to add simple actions like
    gotoAndPlay("next"); to a key.
    e.g. the right arrow.
    How could I do this? any simple way?
    thanks in advance, marcelo.

    In AS3 you can just use:
    if(event.keyCode == Keyboard.A)
    help doc:
    http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/ui/Keyboard.html
    In AS2 you can use:
    if(String.fromCharCode(Key.getCode()) == "a")
    help doc:
    http://help.adobe.com/en_US/AS2LCR/Flash_10.0/00001143.html#300959
    That way you don't have to look up the key codes.

  • How can I add action listener to a cell or row in a table?

    hi there
    I need to be able to click on one cell or one row in a table, and perform some action, like openning a dialog or something. how can i add listener?

    // See How to Use Tables in tutorial. You will get one idea about Table Renderer and Editors.
    // If u understand the concept, ur problem is very easy to solve by adding Editor to your column.
    "You can think of the renderer as a configurable ink stamp that the table uses to stamp appropriately formatted data onto each cell. When the user starts to edit a cell's data, a cell editor takes over the cell, controlling the cell's editing behavior.
    Here, While tabing thru the table row, default all cell editors are JLabels. (Not editables)
    So u can make it those cells are editable JTextFields or JComboBoxes based on the column while tabbing. And you can add Listeners to that fields too. So those editable fields are called Editor Components.
    // see javax.swing.DefaultCellEditor class for more description
    Here i am adding my own JTextField editor to 3rd column of a table by using
    mytable.getColumnModel().getColumn(2).setCellEditor(editor );
    Here editor is a obj of below class. (Not complete..class)
    public class JbuiEditor extends DefaultCellEditor implements // any listener {
    public JbuiEditor(JTextField tField) {
    super(tField);
    setClickCountToStart(1);
    tField.addFocusListener(this);
    this.editorComponent = tField;
    public Component getComponent(){
         return editorComponent;
    public Component getTreeCellEditorComponent(JTree tree, Object value,
                                  boolean isSelected,
                                  boolean expanded,
                                  boolean leaf, int row) {
         String StringValue = tree.convertValueToText(value, isSelected,
                             expanded, leaf, row, false);
         delegate.setValue(stringValue);
         return editorComponent;
    public Object getCellEditorValue() {
    return super.getCellEditorValue();
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,int row, int column) {
    super.getTableCellEditorComponent(table,value,isSelected,row,column);
    ((JTextField)editorComponent).setText(value.toString());
    //Here u can add any type of listener to this Editor component.like..
    ((JTextField)editorComponent).addActionListener(..);
    ((JTextField)editorComponent).addFocusListener(..);
    return editorComponent;
    Hope gives some idea.

  • How to add a listener for frame change

    hello
    Im quite new to jmf, and im writing a code which uses the webcam, but im stuck at a point where i want a listener which is called whenever the frame changes in the visualcomponent. so basically im looking for a frame changed listener to be added to the visual component instead of using a loop or a timer or something.
    i just need a method to be called constantly along the stream coming from the webcam but which is consistent with the changing of the frames.
    i would really appreciate any kind of help.
    thank you

    i thought there would be a listener or something ready to do thisThere is. It's the Rendered interface, which has a callback everytime data is received. If you want to create a custom renderer that is triggered everytime data is available, you set a processor to use your renderer and when data is available, your process command will be called. Same as an event listener...but it's very advanced stuff to implement the renderer interface.
    for example if u want to record a video ull need to capture every frame as soon as it comesNo, the video doesn't come to you a frame at a time. The video is already encoded somehow when you get it, so it's coming in as a stream just like it'll be going out to the file... It's a stream of bytes, not a stream of images... You're not digitizing here, you're transcoding.

Maybe you are looking for

  • Adobe Audition CS5.5 corrupted a session

    I recorded a couple of sessions with Audition. The waveforms appeared onscreen as usual. Once the session was finished, I tried to play the audio back. The waveform changed to a repetitive pattern and the audio played one second looped from beginning

  • "RCL" folder in all hard drives

    Can someone help creating a batch file? I want to locate "RCL" folder in all hard drives on a computer and copy few important files and folders from this directory.It needs to be DOS batch file.

  • Chart rendering problem

    When i'm trying to view report charts they are not rendering. Java host,pop chart services r running, also i have installed flash player. Any idea?

  • ITUNES download error -61??

    how do i solve error -61? i have an external hard drive which is holding almost all my music. what do i do???

  • PM Order description based on the Package Due

    Hello Experts, Can anyone explain me if PM Order description can be defaulted based on the Package Due such as Weekly, Monthly, Quarterly, Annual, etc.. I know we can have multiple maintenance items with different task list for each package, so that