Problem adding action event to cells in JTable

hi frends i m developing file transfer client server.My client GUI contains JTable in which it displays directory and file in the current directory.Now i want to display files under the directory when i double click on the directory bt it doesnt happen though i hav applied event to the cell.My code is as below:
The FileTransfer.java cotains code for table as::
File dir=new File(".");
localTable=new JTable(new FileTableModel(dir));
localTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
localTable.getColumnModel().getColumn(0).setCellRenderer(new FileTableCellRenderer());
The file FileTableModel.java is
public class FileTableModel extends AbstractTableModel {
private File dir;
private File[] list;
private String[] columnNames = new String[] {
     "Name", "Size", "last modified"};
public FileTableModel(File dir) {
setDirectory(dir);
public void setDirectory(File dir) {
this.dir = dir;
list = dir.listFiles();
public int getRowCount() {
return list.length;
public int getColumnCount() {
return 3;
public String getColumnName(int col) {
     return columnNames[col];
public Object getValueAt(int row, int col) {
switch(col) {
case 0:
return list[row];
case 1:
return list[row].isDirectory()?"Dir":(list[row].length()+"");
case 2:
return new Date(list[row].lastModified());
default:
return null;
public Class getColumnClass(int col) {
switch (col) {
case 0:
return File.class;
case 1:
return String.class;
case 2:
return Date.class;
default:
return null;
and FileTableCellTandrer.java is
public class FileTableCellRenderer implements TableCellRenderer {
     public FileTableCellRenderer(){
public Component getTableCellRendererComponent(final JTable table,final Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
JTextField fileField = new JTextField(((File)value).getName());
Color normalBackground = Color.white;
Color selectedBackground = Color.gray;
Color focusBackground = Color.green;
fileField.setBackground(normalBackground);
if (isSelected) {
fileField.setBackground(selectedBackground);
if (hasFocus) {
fileField.setBackground(focusBackground);
fileField.setEnabled(false);
if (((File)value).isDirectory()) {
     fileField.setEnabled(true);
     System.out.println("Inside isDirectory");
fileField.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent ae) {
          ((FileTableModel)table.getModel()).setDirectory((File)value);
          ((AbstractTableModel)table.getModel()).fireTableDataChanged();
return fileField;
so plz help me out.Is there any change needed in my code of FileTableCellRenderer thn tell me.

Make the cells non-editable then use a MouseListener on the table and handle the double click.
If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

Similar Messages

  • Problem with action events........ :(

    hi all,
    there is a strange problem which me and my colleagues are facing now-a-days......
    For some odd and unknown reason, the links on the page suddenly stops woking... it goes like this....
    we write events (buttons or action links) .... we test them and they are working fine...... than we write some other piece of code and than run the program and links work no more... The program never goes in the action event for the component...... and surprisingly it also dont show an error.... It just keeps on refreshing itself again and again....... (this thing is also verified by using debugger that actions events just stop being called....) it happens for random situations ...... Once i thought that maybe its has to do something with beforeRenderResponse() method... but it happens even in beans without beforeRenderResponse() method.....
    Can anyone tell me whats going on around here???? we are extremely confused here with dead lines approaching fast........
    regards

    I've had this same problem....links were working fine yesterday. I added more functionality which didn't even affect the links, and now they're not working. Unfortunately, I don't have a solution either.
    Has anybody been able to access the logging in the facescontext or application to see what the lifecycle is doing before it stops???

  • Adding action events

    Whenever i used to add action event, i used to do it like:
    submitJButton.addActionListener(
             new ActionListener() // anonymous inner class
                // event handler called when startJButton is pressed
                public void actionPerformed( ActionEvent event1 )
                   submitJButtonActionPerformed( event1 );
             } // end anonymous inner class
          ); // end call to addActionListenerHow can i add action events to these two buttons though?
        private JPanel createButtonPanel() {
              JPanel panel = new JPanel();
              JPanel temp = new JPanel(new GridLayout(1,2, 5,5));
              temp.add(new JButton("REGISTER"), BorderLayout.LINE_START);
              temp.setPreferredSize(new Dimension(200, 40));
              temp.add(new JButton("LOGIN"), BorderLayout.LINE_END);
              temp.setPreferredSize(new Dimension(200, 40));
              panel.add(temp);
              return panel;
         }

    That works really well. Now for the register button, how would i get this register class to display?
    package layout;
    import javax.swing.*;
    import java.awt.*;
    public class Register {
        private static void createAndShowGUI() {
         String[] labels = {"Name: ", "ID No: ", "Username: ", "Password: "};
         int numPairs = labels.length;
        JPanel pan = new JPanel(new SpringLayout());
        for (int i = 0; i < numPairs; i++) {
            JLabel lab = new JLabel(labels, JLabel.TRAILING);
    pan.add(lab);
    JTextField textField = new JTextField(10);
    lab.setLabelFor(textField);
    pan.add(textField);
    SpringUtilities.makeCompactGrid(pan, numPairs, 2, 6, 6, 6, 6); //(rows, columns, initx, inity, xpad, ypad
         JFrame frame = new JFrame("Nerkesa Pignatelli");
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         pan.setOpaque(true);
         frame.setContentPane(pan);
         //Display the window.
         frame.pack();
         frame.setVisible(true);
    public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }The only reason i ask this is because i followed the sun tutorial site to produce this register form and when it run's it,, it uses createAndShowGUI(); where when i have added different classes to action events before, i have normally used somthing like in my title class, new Title().setVisible(true);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Problem Adding iCal Events Received via Email (used to work fine)

    My wife and I share iCal calendar events between our Mac's via email. A month or so ago I started getting this error when clicking on the link that comes with the iCal event email:
    "This calendar file is empty. No new events have been added to your iCal calendars."
    We are both on Intel Powermacs running OS 10.4.11 and have the same version of iCal (2.0.5). I can still email her iCal events and she can add them to her calendar just fine. But anything she sends me gives me this error.
    Help?

    Travis,
    I had the exact same problem (with my wife's iCal account to boot ). The solution lies in the "(null) informs you..." It turns out that iCal looks at your personal address card to figure out who you are when populating the email. So, if don't have the email address you are sending FROM listed under your address book entry, then the notice is from NULL.
    I added my wife's email accounts to her address book entry on her machine (sorry for the bolds, but the details count.) Then I tried sending a calendar event from her iCal to me. This time it populated with her name and it added to my calendar just fine when I received the email.
    I hope this solution works for you (it drove me crazy for about two weeks.)
    -Dave

  • Problem in Setting value in cells of jTable

    I am trying to set values in the table by editing the cells, the problem is that once i enter some values in the cells and hit enter or click on next cell it gives an exception of stack overflow, i tried tracing i am getting all the values of the particular row and colums and the value which is entered,
    public void setValueAt(Object aValue, int rowIndex, int columnIndex)
    Object[] row = (Object[]) data.get(rowIndex);
    row[columnIndex] = aValue;
    super.fireTableCellUpdated(rowIndex, columnIndex);
    but it is not executing the super.fireTableCellUpdated() function.
    i will be thankful if you provide me with the solution for the above problem or provide me any other way.
    Thank's in Advance.

    Use the DefaultTableModel, then you don't have to write custom code for the setValueAt() method.
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

  • Problem with select all cells in JTable

    Hi guys! I get some problem about selecting all cells in JTable. I tried to used two methods:
    1> table.selectAll()2> changeSelection(firstcell, lastcell,false,true)
    firstcell:[0,0], lastcell[rowcount-1,colcount-1]
    Result: only the first row selected when i use both methods.
    Note: i set up the selection model as following:
    this.dataSheet.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                    this.dataSheet.setCellSelectionEnabled(true);
                    this.dataSheet.setRowSelectionAllowed(true);
                    this.dataSheet.setColumnSelectionAllowed(true);Thanks !

    What selection properity should be changed in order to enable selectAll() method work properly? Is there Any constraints? Here is the TableModel I am using. And i set up selection mode use the following code:
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setCellSelectionEnabled(true);
    table.setRowSelectionAllowed(true);
    table.setColumnSelectionAllowed(true);
    import java.util.Vector;
    import javax.swing.table.*;
    import javax.swing.JTable;
    public class DataSheetModel extends AbstractTableModel{
              private Vector data = new Vector();//Store data
              private Vector columnNames = new Vector();//Store head
              public DataSheetModel(){}
              public DataSheetModel(Vector headVector, Vector dataVector){
                   if(headVector != null) this.columnNames = headVector;
                   if(dataVector != null) this.data = dataVector;
              public int getColumnCount(){
                   return columnNames.size()+1;
              public int getRowCount(){
                   return data.size()+1;
              public String getColumnName(int col){
                   if(col==0) return "";
                   else return (String)columnNames.get(col-1);
              public Object getValueAt(int row, int col){
                   if(col==0) {
                        if(row != data.size()) return String.valueOf(row);
                        else return "*";
                   else{
                        if(row != data.size()){
                             Vector rowVector = (Vector)data.elementAt(row);
                             return rowVector.elementAt(col-1);
                        }else return null;
              public void setValueAt(Object value, int row, int col){
                   if(row != this.data.size()){
                        Vector rowVector = (Vector)data.elementAt(row);
                        rowVector.set(col-1,value);
                        this.data.set(row,rowVector);
                        this.fireTableDataChanged();
                   }else{
                        Vector rowVector = new Vector();
                        for(int i=0; i<this.getColumnCount()-1; i++) rowVector.add(null);
                        rowVector.set(col-1,value);
                        this.data.add(rowVector);
                        this.fireTableDataChanged();
              public Class getColumnClass(int c){
                   return getValueAt(0,c).getClass();
              public boolean isCellEditable(int row, int col){
                   if(col == 0) return false;
                   else return true;
              public void setDataVector(Vector head, Vector data){
                   if(head != null) this.columnNames = head;
                   if(data != null) this.data = data;
    }

  • Keypressed event for a particular  edited cell of jtable

    hi friend,
    how to write the key pressed event for the edited cell of jtable which having focus on that particular cell.
    pls help me out.

    [http://catb.org/~esr/faqs/smart-questions.html]
    [http://mindprod.com/jgloss/sscce.html]
    db

  • Problem adding events to calendar - they don't show up

    I have an intermittent and very strange problem which occurs when adding an event to the calendar on my iPhone 4 (Verizon - running latest iOS).
    I will create an event, fill out time, date, name, etc and click done, and then the event will not show up in the calendar. Sometimes I can go through this process five or six times in a row before the event finally appears. None of the other attempts ever show up later, and they're not findable via search, so I know this isn't either me doing something dumb (like entering the wrong date) or a delay of some kind.
    I am using MobileMe and the calendar in question is always a MobileMe calendar, simply because those are the only ones I use. I have not tested this with the iPhone local calendar.
    Recently, I experienced the same issue when deleting an event. It took a few tries before the deletion did anything.
    This occurs probably 80% of the time I create an event, and has always occurred. It NEVER happens when I create an event via a hyperlinked date/time shortcut suggestion in an email or the like.
    Has anyone experienced this?

    If you only have one account, it, inherently will be the default.
    On the iPhone, Settings >Mail, Contacts, Calendar
    Scroll down. In each section there should be a 'Default Account'. So one form Mail, Contacts and Calendar. Check that the one account you have / use is set to the default.

  • Row action event on data table does not occur when rows added dynamically

    Row action event on data table does not occur (only refreshes the page) when the rows in the data table are added dynamically at run time using button click and java bean.
    please tell me a way to catch the row click event when adding rows dynamically to data table. i m using RAD 6.0 to develop Faces jsp pages.
    thanks
    amit

    i got the answer

  • JComboBox Action Event problems

    I have a complex UI with which I am having action event issues. Basically, the panel displays info about an object, which can be selected from within the panel through a button/popup window mechanism. A JComboBox (#1) selection determines the contents of another JComboBox (#2) on the same panel. Currently an ActionEvent fires when the user makes a selection using #1 that updates #2. This fuctions correctly with repeated testing so long as a new object is not selected.
    When a new object is selected from within this panel this ActionEvent no longer fires. JComboBox #1 will be updated correctly and #2 will reflect the initial selection in #1, but user selections in #1 will not fire the ActionEvent and thus #2 is never updated.
    Any help is appreciated. I feel like I'm missing something basic here, but I've stared at it for long enough...

    By the way, the workaround is to use the ItemListener as the ItemStateChanged Event is fired reliably.

  • How do i do that? MultiLine in a cell of JTable !!!

    Dear friends,
    I am trying to add multiline in a cell of JTable. For that bellow code i have written, but my statement in cell displays in a line only. Code is given bellow (copy/paste/run), could anyone help me how to do that?
    Regards..
    Jaya.
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import java.sql.*;
    public class OtL extends JFrame {
        public OtL()
          initComponents();
        private void initComponents() {
            model1 = new DefaultTableModel();
            btnClose  = new javax.swing.JButton();
            tblOt       = new javax.swing.JTable(model1);
            scrOt   = new javax.swing.JScrollPane();
            TableCellRenderer renderer = new TableRenderer();
            tblOt.setDefaultRenderer(Object.class,renderer);
            tblOt.setRowHeight(tblOt.getRowHeight()*3);
            tblOt.setBackground(new java.awt.Color(250,225,162));
            getContentPane().setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            btnClose.setText("CLOSE");
            btnClose.setToolTipText("Close This Screen");
            btnClose.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
            btnClose.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                  System.exit(0);
            getContentPane().add(btnClose);
            btnClose.setBounds(380, 470, 110, 25);
            tblOt.setToolTipText("Operation Theatre Booking List");
            scrOt.setViewportView(tblOt);
            tableSize();
            scrOt.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
            scrOt.setToolTipText("Operation Theatre Booking List");
            getContentPane().add(scrOt);
            scrOt.setBounds(15, 150, 770, 300);
            displayOtList();
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
        public static void main(String args[]) {
            JFrame j  = new OtL();
            j.setSize(800,560);
            j.show();
    /**********Code for displaying Operation Theater Booking List****Start Here*************/
        public void displayOtList(){
    Here i fire a sql query and i populate data in table.
    Sometime i get more than 1 value for some column e.g Surgery Name and Surgeon Name, so
    i want to display more than 1 value in the same cell. like bellow i have mentiond for
    5th and 6th column. But its displayin in one line only, how can i display that in multiple line!!
    I know that can be taken care with  Renderer, i tried but couldn't go through. I have written TableRenderer
    class for that, please help me what should i do in Renderer class.
          int row1=0;
          tableSize();
          DefaultTableModel model1 = (DefaultTableModel)tblOt.getModel();
          Object[] newRow = new Object[6];
            for(int i=0;i<1;i++){
              row1 = tblOt.getRowCount() + 1;
              newRow[0] = "1";
              newRow[1] = "10:10";
              newRow[2] = "11:30";
              newRow[3] = "Name Here";
              newRow[4] = "Surgery Name1 \n Surgery Name2";
              newRow[5] = "Dr. Amit \n Dr. Johnson";
              model1.addRow(newRow);
    /**********Code for displaying Operation Theater Booking List****End Here*************/
       class TableRenderer extends DefaultTableCellRenderer{
         public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean
    hasFocus, int row, int column)
           super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
          setOpaque(true);
           return this;
    /******tableSize()*****code for sizing table******start here()********/
      public void tableSize(){
        tblOt.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {},
            new String [] {"Ot No.", "Start Time","End Time", "Patient Name", "Surgery Name","Surgeon Name"}
        TableColumn column = null;
        for (int i = 0; i < 6; i++) {
          column = tblOt.getColumnModel().getColumn(i);
          if (i == 0) {
            column.setPreferredWidth(5);
          if (i == 1) {
            column.setPreferredWidth(15);
          if (i == 2) {
          column.setPreferredWidth(15);
          if (i == 3) {
            column.setPreferredWidth(130);
          if (i == 4) {
            column.setPreferredWidth(130);
          if (i == 5) {
            column.setPreferredWidth(130);
    /******tableSize()*****code for sizing table******end here()********/
        private javax.swing.JButton btnClose;
        private javax.swing.JScrollPane scrOt;
        private javax.swing.JTable tblOt;
        private DefaultTableModel model1;
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    OK Filne, Thanx .. its displaying data in multiple line now.
    But still there is a problem, whenever i move mouse over the table row it returns error like bellow. I am not able to findout the reason of error. I tried to put code in try{} catch{} block to avoid this error, but still its coming. Help me.....!!!!!!!!
    java.lang.NullPointerException
            at javax.swing.text.View.getViewIndex(View.java:1060)
            at javax.swing.text.View.getToolTipText(View.java:1031)
            at javax.swing.plaf.basic.BasicTextUI.getToolTipText(BasicTextUI.java:1057)
            at javax.swing.text.JTextComponent.getToolTipText(JTextComponent.java:1533)
            at javax.swing.JTable.getToolTipText(JTable.java:2380)
            at javax.swing.ToolTipManager$insideTimerAction.actionPerformed(ToolTipManager.java:669)
            at javax.swing.Timer.fireActionPerformed(Timer.java:256)
            at javax.swing.Timer$DoPostEvent.run(Timer.java:190)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:167)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:437)
            at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:150)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:131)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)my latest programe code is here :
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    public class OtL extends JFrame {
        public OtL()
          initComponents();
        private void initComponents() {
            model1 = new DefaultTableModel();
            btnClose  = new javax.swing.JButton();
            tblOt       = new javax.swing.JTable(model1);
            scrOt   = new javax.swing.JScrollPane();
            TableCellRenderer renderer = new TableRenderer();
            tblOt.setDefaultRenderer(Object.class,renderer);
            tblOt.setRowHeight(tblOt.getRowHeight()*3);
            tblOt.setBackground(new java.awt.Color(250,225,162));
            getContentPane().setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            btnClose.setText("CLOSE");
            btnClose.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
            btnClose.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                  System.exit(0);
            getContentPane().add(btnClose);
            btnClose.setBounds(380, 470, 110, 25);
            scrOt.setViewportView(tblOt);
            tableSize();
            scrOt.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
            getContentPane().add(scrOt);
            scrOt.setBounds(15, 150, 770, 300);
            displayOtList();
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
        public static void main(String args[]) {
            JFrame j  = new OtL();
            j.setSize(800,560);
            j.show();
        public void displayOtList(){
          int row1=0;
          tableSize();
          DefaultTableModel model1 = (DefaultTableModel)tblOt.getModel();
          Object[] newRow = new Object[6];
            for(int i=0;i<1;i++){
              row1 = tblOt.getRowCount() + 1;
              newRow[0] = "1";
              newRow[1] = "10:10";
              newRow[2] = "11:30";
              newRow[3] = "Name Here";
              newRow[4] = "Surgery Name1 \n Surgery Name2";
              newRow[5] = "Dr. Amit \n Dr. Johnson";
              model1.addRow(newRow);
       class TableRenderer extends JTextArea implements TableCellRenderer{
          public TableRenderer(){
            setLineWrap(true);
            setWrapStyleWord(true);
            setOpaque(true);
         public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean
    hasFocus, int row, int column)
          if (isSelected) {
            setForeground(tblOt.getSelectionForeground());
            setBackground(tblOt.getSelectionBackground());
          } else {
            setForeground(tblOt.getForeground());
          setFont(tblOt.getFont());
          if (hasFocus) {
            setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
              if (tblOt.isCellEditable(row, column)) {
                setForeground( UIManager.getColor("Table.focusCellForeground") );
                setBackground( UIManager.getColor("Table.focusCellBackground") );
              } else {
            setBorder(new EmptyBorder(1, 2, 1, 2));
          setText((value == null) ? "" : value.toString());
          return this;
    /******tableSize()*****code for sizing table******start here()********/
      public void tableSize(){
        tblOt.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {},
            new String [] {"Ot No.", "Start Time","End Time", "Patient Name", "Surgery Name","Surgeon Name"}
        TableColumn column = null;
        for (int i = 0; i < 6; i++) {
          column = tblOt.getColumnModel().getColumn(i);
          if (i == 0) {
            column.setPreferredWidth(5);
          if (i == 1) {
            column.setPreferredWidth(15);
          if (i == 2) {
          column.setPreferredWidth(15);
          if (i == 3) {
            column.setPreferredWidth(130);
          if (i == 4) {
            column.setPreferredWidth(130);
          if (i == 5) {
            column.setPreferredWidth(130);
    /******tableSize()*****code for sizing table******end here()********/
        private javax.swing.JButton btnClose;
        private javax.swing.JScrollPane scrOt;
        private javax.swing.JTable tblOt;
        private DefaultTableModel model1;
    }

  • Action event automatically triggered for combo box

    Hi all,
    I am facing a typical event handling problem for combo box in Swing(Using Net Beans 5.0, jdk 1.4.2)
    While adding items to combo box it is firing action event twice instead of once irrespective of no. of items added to it.
    For eg if there are 1 or more than 1 item added to combo box it is triggerring action event twice(one just after when first item is added and one again when rest all items are added)
    and if there is no item then also it is triggering once.
    Can you please help me out.
    Thanks

    post the SSCCE code, then only it is easy to find the problem

  • Action Event

    Hi,
    Slight problem with an action event, have a workaround but want to make sure there isnt another way!
    Basically I have 2 combo boxes, Make and Model. When an item is selected in one of them the following happens:
    Gets the value selected, runs a query on a data base, clears the other combobox, and inserts the data returned in the other combo box.
    The problem is that clearing the other combobox registers as an actionPerformed on that box, and so does adding the data to that box.
    Can I consume that event?? i.e. make the latter 2 actions not register as events???
    I have worked around it using a boolean, but am looking for another way.
    I dont have the code off hand to show it!!
    Thanks
    Ciara

    I have worked around it using a boolean, but am looking for another way.If the MakeActionListener fiddle-diddles with the Model, it's the first ones responsibility
    that the second one doesn't get spurious events fired towards its general direction. A boolean, as
    you describe, solves the problem but then its the ModelActionListener that's got to check it.
    Would it be possible that the MakeActionListener temporarily removes the other listener from
    the notification list and re-install it after it has performed its dirty deeds?
    kind regards,
    Jos

  • Temparally remove rows from a ADF table by action event of a jsf page.

    Hello Developers,
    I needed to temporally remove rows of a ADF table when execute action event of corresponding page.
    So in this case my task can describe by following steps,
    (1). I created a ADF table using <af:table> on a jsf page.
    (2). The data populated using a VO.
    (3). Several radio buttons added to the page for temporally remove rows from the table.
    This means one radio button check, it responsible to temporally remove rows which contain empty cell values of a identified column.
    If I check another radio button it should temporally remove identified data included rows but above removed (empty cell included rows) rows should appear in this event
    My ultimate target is temporally remove rows of a table & re call again removed rows another event without again & again query from BC.
    Pleas advice me to archive this task very sealy?
    (Are there have a way to do this using EL or coding in Manage bean ?)
    Thanks in advance..!

    Hi,
    the DCIterator gives you an option to iterate over the fetched rows (the ones you see in the table). You can try call removeAndRetain() on these rows. This will not remove or delete rows but allows you to insert these rows back to the collection.
    JavaDocs:
    * Removes the row from the collection and then retain it for insertion
    * into another location.
    * <p>
    * This method differs from <code>{@link #remove()}</code> in that
    * it just removes the row from the collection. It does not
    * remove the underlying Entity row(s) or database row(s).
    * <p>
    * This method also differs from <code>{@link #removeFromCollection()}</code>
    * in that after the row is removed from the collection, it can be inserted
    * back into the collection at another location.
    void removeAndRetain();
    Frank

  • How to disable a particular cell in JTable ?

    I having a problem on how to set disable a particular cell in JTable. At the first place to load the JTable, I want to set some of the cell to disabled, it only will run at the first time, is there anyway to do it ?

    This is the function that disable/enable cells in JTables.
    Are you looking for this?
    public boolean isCellEditable(int row, int col)
      if(((new Integer((String)(getValueAt(row,0)).toString()).intValue()>9))&&(col==1))
        return true;
      if(row!=4&&col!=5)
        return true;
      return false;
         this metod belong to the TableModel function
    and what I gave you is only an example of what you can do with it.
    if it return false it disable and if true it enable the cell...but I think this you allready know!
    Regards Amnon

Maybe you are looking for

  • Is it possible to make comments or notes on a read only pdf document?

    Is it possible to make comments or notes on a read only pdf document?  Thank you.

  • Trouble signing into iCloud

    Hi there, I am a new user, still trying to get iCloud up and runing ,when I sign in it says  my id is valid but is not an iCloud account.  I have tried changing my password but it still comes back with the same answer.. I have a ipod nano,my coputer

  • Need help with capturing live performance with 2 cameras

    I captured a live performance with two different cameras, one was AVCHD the other in DV. In Adobe, is there a way to down convert the large AVCHD to match the HD so that I can do a multi-camera edit? Here are the specs of the videos Here are the two

  • Reading encrypted XML in swf.

    Hello Friends,      I am at beginners level for flash. I have a XML file which will used as a datasource to swf. But before using it I want to decrypt the xml with the given key. Thus can we achieve this in action script.

  • HT204655 Can I create folders and subfolders in the new Photos on my mac?

    I've just started using the new Photos app in the latest Yosemite update on my Macbook Pro. Until recently I was using Aperture to sort all my photos into folders and subfolders - I think they were called "events" or "projects" in Aperture.  In Apert