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?

Similar Messages

  • 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.

  • 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

  • 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

  • How to listener a table cell

    I have this table cell editable and I want to listen when value changes (to update the database data) but I am not being able to do that, any help?
    I also would like to activate the new cell value with ENTER key, the way it is now I have to get ou of the cell clicking outside somewhere or using TAB key to move.
    I am using these tow classes to Editor and Renderer (for numbers):
    import java.awt.*;
    import java.text.*;
    import javax.swing.table.*;
    import javax.swing.*;
    public class DecimalRenderer extends DefaultTableCellRenderer {
        DecimalFormat  formatter;
        public DecimalRenderer(String pattern) {
            this(new DecimalFormat(pattern));
        public DecimalRenderer(DecimalFormat formatter) {
            this.formatter = formatter;
            setHorizontalAlignment(JLabel.RIGHT);
        public void setValue(Object value) {
            setText((value == null) ? "" : formatter.format(((Double)value).doubleValue()));
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            cell.setBackground( Color.white );
            cell.setForeground( Color.black );
            return cell;
    import java.awt.*;
    import javax.swing.table.*;
    import javax.swing.*;
    public class NumberCellEditor extends AbstractCellEditor implements TableCellEditor {
        //protected JTextField textField;
        protected JFormattedTextField textField;
        private JTable tableUsed;
        protected Object oldValue;
        public NumberCellEditor() {
            textField = new JFormattedTextField();
            textField.setEditable(true);
            textField.setHorizontalAlignment(SwingConstants.RIGHT);
            textField.setFont(new java.awt.Font("Tahoma", 1, 12));
            textField.setBackground(Color.white);
            textField.setForeground(Color.red);
        public NumberCellEditor(int decimal) {
            textField = new JFormattedTextField();
            textField.setEditable(true);
            textField.setHorizontalAlignment(SwingConstants.RIGHT);
            textField.setBackground(Color.white);
            textField.setForeground(Color.red);
            textField.setFormatterFactory(Lib.setFormatDouble(decimal));
            public NumberCellEditor(boolean currency, int decimal) {
            textField = new JFormattedTextField();
            textField.setEditable(true);
            textField.setHorizontalAlignment(SwingConstants.RIGHT);
            textField.setBackground(Color.white);
            textField.setForeground(Color.red);
            textField.setFormatterFactory(Lib.setCurrencyFormat(decimal));
        private void setConfig(){
            textField.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    if(tableUsed.isEditing()){
                        tableUsed.getCellEditor().stopCellEditing();
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
            //textField.setText(value.toString());
            textField.setValue(value);
            oldValue = value;
            this.tableUsed = table;
            String className = value.getClass().getName();
            System.out.println("Type: "+className);
            return textField;
        /** Returns the value contained in the editor */
        public Object getCellEditorValue() {
            String name = oldValue.getClass().getName();
            Object returnValue=null;
            try {
                if (name.equals("java.lang.Integer"))
                    returnValue = new java.lang.Integer(textField.getText());
                else if (name.equals("java.lang.Double"))
                    returnValue = (Double)textField.getValue(); //new java.lang.Double(textField.getText());
                else if (name.equals("java.lang.Float"))
                    returnValue = new java.lang.Float(textField.getText());
                else if (name.equals("java.lang.Long"))
                    returnValue = new java.lang.Long(textField.getText());
                else if (name.equals("java.lang.Short"))
                    returnValue = new java.lang.Short(textField.getText());
                else if (name.equals("java.lang.Byte"))
                    returnValue = new java.lang.Byte(textField.getText());
                else if (name.equals("java.math.BigDecimal"))
                    returnValue = new java.math.BigDecimal(textField.getText());
                else if (name.equals("java.math.BigInteger"))
                    returnValue = new java.math.BigInteger(textField.getText());
            } catch (NumberFormatException e) {}
            return returnValue;
    }My code to that column/cell:
    TableColumn columnValueService = tabelaListaQuantidade.getColumn(colunas[4]);
    columnValueService.setPreferredWidth(150);
    columnValueService.setCellRenderer(new DecimalRenderer("###,###,##0.00"));
    columnValueService.setCellEditor(new NumberCellEditor(true, 2));I would appreciate any help.
    Thanks

    I want to listen when value changes Use a TableModelListener
    I also would like to activate the new cell value with ENTER keyThis is the default behaviour with the default editors. I suggest you extend the default editor instead of extending the abstract editor

  • REG: How to add elements onto htmlb table cell.. URGENT PLZ HELP

    Hi all,
    I have created a htmlb table. And the jsp code is as follows
    <%@ taglib uri="tagLib" prefix="hbj" %>
    <jsp:useBean id="myBean" scope="application" class="com.linde.myaccounts.util.TableBean" />
    <hbj:content id="myContext">
      <hbj:page title="PageTitle">
       <hbj:form id="myFormId" >
       <hbj:tableView id="myTableView1"
                          model="myBean.model"
                          design="ALTERNATING"
                          headerVisible="false"
                          footerVisible="false"
                          fillUpEmptyRows="true"
                          visibleFirstRow="1"
                          visibleRowCount="5"
    </hbj:form>
      </hbj:page>
    </hbj:content>
                          width="500 px" >
    </hbj:tableView>
    I have used a table bean by which I am getting the column header names. I have 5 columns, I have to add input field in the first column, checkbox in the second column, leave the third column blank, checkbox in the fourth column and again a input field in the fifth column. I am not understanding on how to add this elements onto the table. Will I add it from the JSP using <hbj:tableViewColumns> tag or I have add them in the bean or in the dynpage. Kindly someone give me the code for this...
    This is very urgent..Kindly help...
    Thanks in advance,
    Priyanka

    Hi,
    Have you tried looking at the examples that come with the PDK for all of the HTMLB elements?  From memory, there should be a small table example or 2 that have different types of columns shown similar to what you want - they have the full source code with them for you to look at.
    If you are working in a portal, go to the Java Developer tab and I "think" there should be a tab linking to HTMLB documentation and examples - sorry I can't be more specific but I don't have access to a portal at the moment so am trying to remember.
    Gareth.

  • Unable to add Action for table - throwing Fatal error while rendering the table after adding

    Hi,
    I am not able to add action to the table i created.
    when i click on events and then Create Action for "onFilter" event, it is giving me Internal Error. The message details is:
    eclipse.buildId=@qualifier@
    java.version=1.6.0_45
    java.vendor=Sun Microsystems Inc.
    BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en
    Command-line arguments:  -os win32 -ws win32 -arch x86 -data C:\NWDS\Workspace
    Error
    Thu Jul 17 11:17:27 IST 2014
    Internal Error
       Plug-In Name: Web Dynpro HTML Rendering
       Internal Error  : com.sap.ide.webdynpro.rendering.html
       Class      : com.sap.ide.webdynpro.viewdesigner.ur.RenderingService
       Method     : renderDelta
       Message    : java.lang.RuntimeException: nullFatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.TableAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSSapTableRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.TableAdapter@1376233Fatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSFlowLayoutRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter@1102ae6Fatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.GroupAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSGroupRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.GroupAdapter@70815bFatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSFlowLayoutRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter@3cb708Fatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.ScrollContainerAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSScrollContainerRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.ScrollContainerAdapter@14a4b5Fatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSFlowLayoutRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter@14983d6Fatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.ScrollContainerAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSScrollContainerRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.ScrollContainerAdapter@16e8151
       Exception  : java.lang.RuntimeException: java.lang.RuntimeException: nullFatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.TableAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSSapTableRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.TableAdapter@1376233Fatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSFlowLayoutRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter@1102ae6Fatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.GroupAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSGroupRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.GroupAdapter@70815bFatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSFlowLayoutRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter@3cb708Fatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.ScrollContainerAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSScrollContainerRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.ScrollContainerAdapter@14a4b5Fatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSFlowLayoutRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FlowLayoutAdapter@14983d6Fatal rendering error at control com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.ScrollContainerAdapter [] and renderer com.sap.tc.ls.renderer.ie6.LSScrollContainerRenderer. Please contact the developer of the renderer. com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.ScrollContainerAdapter@16e8151
          [Error: com.sap.ide.tools.services.ui.dialog.DialogService  Thread[main,6,main]]
    The complete error details is also attached with the message.
    After creating the action, the table looks like below:
    Can someone help me on fixing this issue.
    Thanks,
    Abhishek.

    Its a rendering issue with the NWDS/IDE.
    Try, close and re-open for fix it. If it still persists, uninstall NWDS and re-install the right version of NWDS w.r.t the Portal server.
    Regards,
    Sharath

  • RoboHelp 7 to 9 : Table Cell Padding

    HI All,
    I very recently upgraded from TCS 1.3 with RoboHelp 7 to TCS 3.5 with RoboHelp 9. Yeay! All is good so far except one little niggle. . .
    I use tables frequently in my source files to set out information. In RH7 I did this through Table > Insert > Table... Select number of rows and columns then click OK.
    When I did this I could see that RH had automatically added padding to the table cells. If I added text into the cell there was a small gap between the table border and start of the text.
    When I perform the same action in RH9, the padding appears to be missing (highlight a table cell and skip over to HTML view). I can't figure out how to add this automatically.It could get a little tiresome if I have to add it for each table cell from now on in order to be consistent with the tables already in my project. Manually adding a margin from the Table properties dialog appears to make no difference. Even when I set the margin to be outrageously huge, my text still butts right up against the table border.
    So, does anyone know how I can set my table cells to automatically have the same padding  as they did in RH7?
    Any ideas or help are welcomed. Thanks guys!
    Lil

    Presumably, after reading the Table Styles topic in the help as well as your tour Peter, my existing tables stay as is unless I apply a table style to them but I have to create a style for any new tables I add into my project files?
    Yes to all questions. At some point it may be worth converting your inline tables to CSS though so that future changes are just at CSS level.
    You don't mention in your tour Peter whether the mapping issue across to printed documentation has now been fixed in RH9?
    If you mean what I think you do, not that is still an issue.
    Having attempted to create a table style, I'm now trying to work out why if I choose to apply formatting to the 'Whole Table' and set the borders to 'Solid', '1px', 'All Borders' and 'Silver', I get an outline around the whole table rather than all cells bordered. Confused?!!
    The table editor is a nightmare. Whole table means the outer borders, not the whole table, as one might reasonably expect. I think the trick is to set borders for odd rows as top left and even rows as bottom right, something like that.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Problem with action listener

    hello
    the problem in my code is that i defined
    actionlistener for a button but it does not
    do what it should do . it throws an error in the console
    and i think my code is 100% correct what is the problem
    please help me this is the codewith
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class Library extends JFrame implements ActionListener     {
         private JMenuBar jmb      = new JMenuBar();
         private JMenu books      = new JMenu("Books",true);
         private JMenu members      = new JMenu("Members",true);
         private JMenu loans      = new JMenu("Loans",true);
         private JMenuItem addNb = new JMenuItem("Add New Book");
         private JMenuItem listB = new JMenuItem("List All Books");
         private JMenuItem listAb = new JMenuItem("List Available Books");
         private JMenuItem listBb = new JMenuItem("List Borrowed Books");
         private JMenuItem addNm = new JMenuItem("Add New Member");
         private JMenuItem removeM = new JMenuItem("Remove a Member");
         private JMenuItem listAm = new JMenuItem("List All Members");
         private JMenuItem loanB = new JMenuItem("Loan A Book");
         private JMenuItem returnB = new JMenuItem("Return A Book");
         private JTextField bNumber = new JTextField(14);
         private JTextField bAuthor = new JTextField(14);
         private JTextField bTitle = new JTextField(14);
         private JTextField mId = new JTextField(14);
         private JTextField mName = new JTextField(14);
         private JTextField idB = new JTextField(14);
         private JTextField nBToB = new JTextField(14);
         private JTextField nBTor = new JTextField(14);
         private JTextArea dispaly = new JTextArea();
         private JButton oKb1 = new JButton("OK");
         private JButton okb2 = new JButton("OK");
         private JButton cloaseb = new JButton("Close");
         private JButton oKm1 = new JButton("OK");
         private JButton oKm2 = new JButton("OK");
         private JButton cancelM = new JButton("Cancel");
         private JButton oKm3 = new JButton("OK");
         private JButton oKm4 = new JButton("OK");
         private JButton cancelM2 = new JButton("Cancel");
         private JButton oKl = new JButton("OK");
         private JButton oKr = new JButton("OK");
         private JButton yes = new JButton("Yes");
         private JButton no = new JButton("No");     
         private JLabel bN = new JLabel("Book Number");
         private JLabel bA = new JLabel("Book Author");
         private JLabel bT = new JLabel("Book Title");
         private JLabel iN          = new JLabel("ID Number");
         private JLabel mN          = new JLabel("Member's Name");
         private JLabel     iNb          = new JLabel("ID number of the borrower");
         private JLabel nBb          = new JLabel("Number of the books to borrow");
         private JLabel nBr          = new JLabel("Number of the books to return");
         private JLabel mIdl     = new JLabel("ID number of the stuednt");
         private JPanel tempoIPanel= new JPanel(new FlowLayout());
         Container cp;
         JFrame mainFrame;
         JInternalFrame tempoI;
    Library()     {
         //LibraryClass lClass = new LibraryClass();/*
         mainFrame = new JFrame();
         mainFrame.setJMenuBar(jmb);
         mainFrame.setSize(800,550);
         mainFrame.getContentPane().setLayout(new FlowLayout());
         jmb.add(books);
         jmb.add(members);
         jmb.add(loans);
         books.add(addNb);
         addNb.addActionListener(this);
         books.add(listB);
         listB.addActionListener(this);
         books.add(listAb);
         listAb.addActionListener(this);
         books.add(listBb);
         listBb.addActionListener(this);
         members.add(addNm);
         addNm.addActionListener(this);
         members.add(removeM);
         removeM.addActionListener(this);
         members.add(listAm);
         listAm.addActionListener(this);
         loans.add(loanB);
         loanB.addActionListener(this);
         loans.add(returnB);
         returnB.addActionListener(this);
         //actions listeners
         oKb1.addActionListener(this);
         mainFrame.setVisible(true);
    public void actionPerformed(ActionEvent ae)     {
         if(ae.getSource() == addNb)     {
              tempoI = new JInternalFrame("Add new Book",true,true);
              mainFrame.getContentPane().add(tempoI);
              tempoI.getContentPane().setLayout(new FlowLayout());
              tempoI.getContentPane().add(bN);
              tempoI.getContentPane().add(bNumber);
              tempoI.getContentPane().add(bA);
              tempoI.getContentPane().add(bAuthor);
              tempoI.getContentPane().add(bT);
              tempoI.getContentPane().add(bTitle);
              tempoI.getContentPane().add(oKb1);//add action listener here
              tempoI.setVisible(true);
         if(ae.getSource() == listB)     {
              //LibraryClass.listBooks();
         if(ae.getSource() == listAb){}
         if(ae.getSource() == listBb){}
         if(ae.getSource() == addNm)     {
              tempoI = new JInternalFrame("Add new Member",true,true);
              mainFrame.getContentPane().add(tempoI);
              tempoI.getContentPane().setLayout(new FlowLayout());
              tempoI.getContentPane().add(iN);
              tempoI.getContentPane().add(mId);
              tempoI.getContentPane().add(mN);
              tempoI.getContentPane().add(mName);
              tempoI.getContentPane().add(oKm1);//add action listener
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == removeM)     {
              tempoI = new JInternalFrame("Rmove member",true,true);
              mainFrame.getContentPane().add(tempoI);
              tempoI.getContentPane().setLayout(new FlowLayout());
              tempoI.getContentPane().add(mIdl);
              tempoI.getContentPane().add(mId);
              tempoI.getContentPane().add(oKm2);//add action listener
              //LibraryClass.removeM(Double.parseDouble(mId.getText()));
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == listAm)     {
              //LibraryClass.listMembers();
         if(ae.getSource() == loanB)     {
              tempoI = new JInternalFrame("Loan book",true,true);
              mainFrame.getContentPane().add(tempoI);
              tempoI.getContentPane().setLayout(new FlowLayout());
              tempoI.getContentPane().add(iNb);
              tempoI.getContentPane().add(idB);
              tempoI.getContentPane().add(nBb);
              tempoI.getContentPane().add(nBToB);
              tempoI.getContentPane().add(oKl);
              //LibraryClass.borrowBook(Book bk,Member m);
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == returnB)     {
              tempoI = new JInternalFrame("Return Book",true,true);
              mainFrame.getContentPane().add(tempoI);
              tempoI.getContentPane().setLayout(new FlowLayout());
              tempoI.getContentPane().add(iNb);
              tempoI.getContentPane().add(idB);
              tempoI.getContentPane().add(nBr);
              tempoI.getContentPane().add(nBTor);
              tempoI.getContentPane().add(oKr);
              tempoI.getContentPane().setSize(400,300);
              tempoI.setVisible(true);
              //Book.addBook(bNumber.getText(),bAuthor.getText(),bTitle.getText());
    class ClubLibrarySystem     {
         public static void main(String[] args)     {
         new Library();
    }

    hello
    the problem in my code is that i defined
    actionlistener for a button but it does not
    do what it should do . it throws an error in the
    consoleWhat error?
    and i think my code is 100% correct what is theWell, but it isn't.
    Have you tried using a debugger?
    problem
    please help me this is the codewith
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class Library extends JFrame implements
    ActionListener     {
         private JMenuBar jmb      = new JMenuBar();
         private JMenu books      = new JMenu("Books",true);
    private JMenu members      = new
    JMenu("Members",true);
    private JMenu loans      = new
    JMenu("Loans",true);
    private JMenuItem addNb = new JMenuItem("Add New
    Book");
    private JMenuItem listB = new JMenuItem("List All
    Books");
    private JMenuItem listAb = new JMenuItem("List
    Available Books");
    private JMenuItem listBb = new JMenuItem("List
    Borrowed Books");
    private JMenuItem addNm = new JMenuItem("Add New
    Member");
    private JMenuItem removeM = new JMenuItem("Remove a
    Member");
    private JMenuItem listAm = new JMenuItem("List All
    Members");
    private JMenuItem loanB = new JMenuItem("Loan A
    Book");
    private JMenuItem returnB = new JMenuItem("Return A
    Book");
         private JTextField bNumber = new JTextField(14);
         private JTextField bAuthor = new JTextField(14);
         private JTextField bTitle = new JTextField(14);
         private JTextField mId = new JTextField(14);
         private JTextField mName = new JTextField(14);
         private JTextField idB = new JTextField(14);
         private JTextField nBToB = new JTextField(14);
         private JTextField nBTor = new JTextField(14);
         private JTextArea dispaly = new JTextArea();
         private JButton oKb1 = new JButton("OK");
         private JButton okb2 = new JButton("OK");
         private JButton cloaseb = new JButton("Close");
         private JButton oKm1 = new JButton("OK");
         private JButton oKm2 = new JButton("OK");
         private JButton cancelM = new JButton("Cancel");
         private JButton oKm3 = new JButton("OK");
         private JButton oKm4 = new JButton("OK");
         private JButton cancelM2 = new JButton("Cancel");
         private JButton oKl = new JButton("OK");
         private JButton oKr = new JButton("OK");
         private JButton yes = new JButton("Yes");
         private JButton no = new JButton("No");     
    private JLabel bN = new JLabel("Book
    Number");
    private JLabel bA = new JLabel("Book
    Author");
    private JLabel bT = new JLabel("Book
    Title");
         private JLabel iN          = new JLabel("ID Number");
    private JLabel mN          = new JLabel("Member's
    Name");
    private JLabel     iNb          = new JLabel("ID number of the
    borrower");
    private JLabel nBb          = new JLabel("Number of the
    books to borrow");
    private JLabel nBr          = new JLabel("Number of the
    books to return");
    private JLabel mIdl     = new JLabel("ID number of
    the stuednt");
    private JPanel tempoIPanel= new JPanel(new
    FlowLayout());
         Container cp;
         JFrame mainFrame;
         JInternalFrame tempoI;
    Library()     {
         //LibraryClass lClass = new LibraryClass();/*
         mainFrame = new JFrame();
         mainFrame.setJMenuBar(jmb);
         mainFrame.setSize(800,550);
    mainFrame.getContentPane().setLayout(new
    FlowLayout());
         jmb.add(books);
         jmb.add(members);
         jmb.add(loans);
         books.add(addNb);
         addNb.addActionListener(this);
         books.add(listB);
         listB.addActionListener(this);
         books.add(listAb);
         listAb.addActionListener(this);
         books.add(listBb);
         listBb.addActionListener(this);
         members.add(addNm);
         addNm.addActionListener(this);
         members.add(removeM);
         removeM.addActionListener(this);
         members.add(listAm);
         listAm.addActionListener(this);
         loans.add(loanB);
         loanB.addActionListener(this);
         loans.add(returnB);
         returnB.addActionListener(this);
         //actions listeners
         oKb1.addActionListener(this);
         mainFrame.setVisible(true);
    public void actionPerformed(ActionEvent ae)     {
         if(ae.getSource() == addNb)     {
    tempoI = new JInternalFrame("Add new
    w Book",true,true);
              mainFrame.getContentPane().add(tempoI);
    tempoI.getContentPane().setLayout(new
    w FlowLayout());
              tempoI.getContentPane().add(bN);
              tempoI.getContentPane().add(bNumber);
              tempoI.getContentPane().add(bA);
              tempoI.getContentPane().add(bAuthor);
              tempoI.getContentPane().add(bT);
              tempoI.getContentPane().add(bTitle);
    tempoI.getContentPane().add(oKb1);//add action
    n listener here
              tempoI.setVisible(true);
         if(ae.getSource() == listB)     {
              //LibraryClass.listBooks();
         if(ae.getSource() == listAb){}
         if(ae.getSource() == listBb){}
         if(ae.getSource() == addNm)     {
    tempoI = new JInternalFrame("Add new
    w Member",true,true);
              mainFrame.getContentPane().add(tempoI);
    tempoI.getContentPane().setLayout(new
    w FlowLayout());
              tempoI.getContentPane().add(iN);
              tempoI.getContentPane().add(mId);
              tempoI.getContentPane().add(mN);
              tempoI.getContentPane().add(mName);
    tempoI.getContentPane().add(oKm1);//add action
    n listener
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == removeM)     {
    tempoI = new JInternalFrame("Rmove
    e member",true,true);
              mainFrame.getContentPane().add(tempoI);
    tempoI.getContentPane().setLayout(new
    w FlowLayout());
              tempoI.getContentPane().add(mIdl);
              tempoI.getContentPane().add(mId);
    tempoI.getContentPane().add(oKm2);//add action
    n listener
              //LibraryClass.removeM(Double.parseDouble(mId.getText
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == listAm)     {
              //LibraryClass.listMembers();
         if(ae.getSource() == loanB)     {
              tempoI = new JInternalFrame("Loan book",true,true);
              mainFrame.getContentPane().add(tempoI);
    tempoI.getContentPane().setLayout(new
    w FlowLayout());
              tempoI.getContentPane().add(iNb);
              tempoI.getContentPane().add(idB);
              tempoI.getContentPane().add(nBb);
              tempoI.getContentPane().add(nBToB);
              tempoI.getContentPane().add(oKl);
              //LibraryClass.borrowBook(Book bk,Member m);
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == returnB)     {
    tempoI = new JInternalFrame("Return
    n Book",true,true);
              mainFrame.getContentPane().add(tempoI);
    tempoI.getContentPane().setLayout(new
    w FlowLayout());
              tempoI.getContentPane().add(iNb);
              tempoI.getContentPane().add(idB);
              tempoI.getContentPane().add(nBr);
              tempoI.getContentPane().add(nBTor);
              tempoI.getContentPane().add(oKr);
              tempoI.getContentPane().setSize(400,300);
              tempoI.setVisible(true);
              //Book.addBook(bNumber.getText(),bAuthor.getText(),bT
    tle.getText());
    class ClubLibrarySystem     {
         public static void main(String[] args)     {
         new Library();

  • How can I add dots after text to fill the remaining space in a table cell?

    What is the most efficient way to add dots after text to fill the remaining space in a table cell? I know it is possible using tabs but is this possible using a table?

    You can put a tab inside a table cell using Option+Tab
    Then just set the right-aligned tab stop and the right edge of the table cell and add the leader.

  • [pages 5.0.1] How can I add Pictures to the Text in a Table cell?

    Hi,
    is it possible to add a graphic to a cell in a table, where i have already entered some text?
    Everytime I insert the graphic, Pages makes it to the cell's background...
    Can anyone help me?
    Thanks.

    The feature to add images in tables is gone, ike about another 90 features that exists in Pages 09.

  • Get table cell value on click without using submit or action

    hello ,
    i am having html table containing values retrieved from database.
    i want to create table cell as a link and want to pass cell's value to the next page without using submit, radio button, checkbox.
    it is feasible in PHP and ASP but i want to solve in jsp. pls suggest the solution.
    Edited by: Avinash123 on Dec 16, 2008 2:58 AM

    Here is sample code
    <script type="text/javascript">
    function callForm(data)
    frm.action="anotherjsp.jsp?value="+data;
    frm.submit();
    </script>
    <form name="frm" action="">
    <table id="test" border='1'>
    <tr >
    <td onclick="callForm('Data1')" > Data1 </td>
    <td onclick="callForm('Data2')" > Data2 </td>
    <td onclick="callForm('Data3')" > Data3 </td>
    <td onclick="callForm('Data4')" > Data4 </td>
    </tr>
    </table>
    </form>

  • Table Cell Editor - Link To Action UI

    Hi,
    I have a Table UI element in the first view and i need that the first column should have Link To Action UI as the cell editor.
    For this the requirment is that Context Attribute Type should be Boolean. please let me know why this is so.
    Also i want that Link To Action UI should have the text property set to a values from another context attribute. How will this be possible. Please provide some suggestion on this.
    Regards
    Sidharth

    Hi,
    Do you use the table binding wizard? There the first option for the binding property of a Link to action is "enabled" as far as I can remember... And <b>this</b> of course has to be boolean.
    If you want to bind the text property to a Context element you can do it by choosing text as binding property.
    You may also bind the text property to a Context element after completing the wizard.
    Does this answer your question?
    Rgds
    Daniel

  • Add the action listener to a JLabel

    Hi,
    I created a custom JLabel. This should work like a JButton.
    So how i can add a method like
    MyLabel.addActionListener(ActionListener aListener);The action listener can simulated through the mouseClicked method to get a simillar effect but
    the action listener method is more oop.
    So any ideas?
    regards,
    Olek

    Olek wrote:
    I created a custom JLabel. This should work like a JButton.You may be better off creating a JButton that looks like a JLabel. That's my recommendation for implementing this.
    Edit: I remember seeing this at JavaRanch a while back. Perhaps it will be useful to you:
    [actionListener for JLabel|http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=017064]
    Edited by: Encephalopathic on Jul 12, 2008 6:13 PM

  • Add image to Table cell

    Hi All,
       Based on condition how can i add image to Table cell.

    Hi,
    Its very simple and straightforward.
    All you need to do is:
    1...Create a context(value attribute) of type string.
    2...I am assuming that you have created a table, and mapped its columns with a node.
    3...In the <i>TableCellEditor</i>  of your desired column, map the above context with the <i>imagesource</i> property.
    4...In the code, set the value of this context to the image name(eg: abc.gif), on satisfying of a condition.
    5...However, keep in mind to set the context value to some default blank image in the doinit() of the view, else, you will get a null pointer exception.
    I hope this solves your problem.
    Keep posting if you have any further queries.
    Regards,
    Hanoz

Maybe you are looking for

  • New GL and PCA

    Hi, Can the new GL and Profit center accounting be implemented parellel.Is there a real need to do so?.The scenario would be doc split activation along with profit centers and segments. Please share ur ideas

  • Navbar problems in different browsers

    Please help! I designed a navbar using a preformatted Dreamweaver template, but found that it displays differently in different browsers. The file can be found at http://www.npc.org/NPC909/links.html It displays fine in Opera and Safari (both Mac), b

  • Need help with a unique WMV export

    Hi, everyone! This is my first post on this board. I have a sequence in Final Cut Pro that is three 640x480 clips laid out end-to-end to make a 1920x480 movie. The total length of the program is 7-8 minutes. I am needing to export this from Compresso

  • How do I turn firefox off and back on so I can do a download

    I am trying to download an adobe flash player update and it is requiring me to turn off firefox before it will complete. how do I shut it off?

  • Crystal reports 9 installation hangs on xp craxdrt9.dll PLEASE help!!

    I uninstalled crystal reports 9 and did a re-install on the same machine, but the re-install is hangig on registering modules crxdrt9.dll. This .dll is in the correct folder and I tried to manually uninstall it and re-install but it keeps on trying t