[iPhone] Custom UITableViewController and selecting cell problem.

Hello,
I'm creating a custom table view controller by declaring a UIViewController and adopting the UITableViewDataSource and UITableViewDelegate protocol.
With my current implementation, if I select a cell to transition to another view and then navigate back to the tableview, the cell will remain selected.
There must be some delegate method I am not implementing.
If I update the header file of my table view controller by removing the adopted protocols and subclassing the UITableViewController, I dont have this "selection sticking" problem.
Any ideas as to what I am doing wrong?
Thanks!

You're not doing anything wrong, except by omission. If you choose to implement a table view controller as a UIViewController rather than a UITableViewController, you are responsible for controlling selection/deselection of the cells on returning back to the table view from some child view. In the common case where something going on in the child controller affects what cell should be selected/deselected on returning back to the parent table view, this is exactly what you want, because the UITableViewController doesn't always get it right, to sometimes comical effect.
How you would set this up is highly context-dependent.
Doug

Similar Messages

  • Is there a recommended limit on the number of custom sections and the cells per table so that there are no performance issues with the UI?

    Is there a recommended limit on the number of custom sections and the cells per table so that there are no performance issues with the UI?

    Thanks Kelly,
    The answers would be the following:
    1200 cells per custom section (NEW COUNT), and up to 30 custom sections per spec.
    Assuming all will be populated, and this would apply to all final material specs in the system which could be ~25% of all material specs.
    The cells will be numeric, free text, drop downs, and some calculated numeric.
    Are we reaching the limits for UI performance?
    Thanks

  • HT4061 i us iphon in syria and i have problem in the mic how can you help me

    i us iphon in syria and i have problem in the mic how can you help me

    Try to Reset it (hold down the home and sleep buttons, ignore the red off slider, wait for the Apple logo, let go of the buttons).
    If that does not work try Restoring it in iTunes.
    Still no go? You will need to get it serviced.

  • New iPhone 5 - internet and mail reception problems?

    I just acquired a new iPhone 5. I have regular reception internet and mail reception problems. The internet on both Wifi and provider network drops out on a regular basis, although reception signals of both wifi and network are strong. When turning off the phone and restarting the internet comes back for a short while and loses connection again. Has somebody else experience similar difficiulties, If yes how can this be fixed.

    I just acquired a new iPhone 5. I have regular reception internet and mail reception problems. The internet on both Wifi and provider network drops out on a regular basis, although reception signals of both wifi and network are strong. When turning off the phone and restarting the internet comes back for a short while and loses connection again. Has somebody else experience similar difficiulties, If yes how can this be fixed.

  • Bounding box and selection tool problems (CS5.5 Illustrator OSX)

    When I select objects by dragging arrow tool (i.e. logos, headlines, etc.) I often have a problem that other objects are also selected (images, things that are not visible or not actually there) and I can't unselect them easily to get just my selection of objects and be able to resize them by dragging corners. It's like you have to scale everything including the weird extra invisible items across the page somewhere. Sometimes if it's an image that gets selected in addition I can click on and off it to get just my selected objects. And then sometimes the bounding box does not work at all and I can't resize my selected objects by dragging the corners (scale tool works though). Showing and hiding bounding box from drop down menu does nothing. This seems random but happens all the time. It also happened in CS5 on a different Mac computer. Anybody run into this? I know other designers in the office have experienced this. Is there a weird selection preference I need to set? Should I try resetting preferences? Could it be Ram issues? (Sometimes have Illustrator, Photoshop, and InDesign open all at once)
    I've just been dealing with it up to this point but I am really ready for a fix for this issue. It seems buggy.

    Pam,
    You may try to move the folder, following the first hint here: http://www.bugge.com/Family-and-friends/Illy/illy.html

  • IPhone - music skipping and pausing - headset problem?

    I've noticed a problem when I've been out on a run with my iPhone. Late in the run the music will stop and start and skip around. I suspect the problem is in the Apple headset. I think sweat is getting into the mouthpiece/pause-advance gismo and sending false signals to the iPhone. I've also noticed (during runs) that the pause-advance feature is inconsistant; sometimes it advances, sometimes not.
    I would like to upgrade the headset to the V-Moda Vibe headset as soon as those are available with the call receive/hangup function.
    Has anyone else noticed these problems.

    that's funny... that just occured to me last night... thought the phone was buggin out so i restored it... shoulda just did a search on the forums... now i have to reinstall all my 3rd party apps...
    i was also at the gym sweatin to the oldies when this occurred... and i do believe it's the head set... i understand the pausing and playin, but sometimes the song will change back and forth and what not... very strange behavior....

  • IPhone 6 4G and/or LTE problems AT&T

    Anyone else had this problem?  Sometimes 4G works faster than LTE even if it has less bars...sometimes it's the other way around.  Last week I had my iPhone 5 and since updating to iOS 8 along with new carrier settings update, it's been spotty. 
    Danny
    i6 iOS8

    I had this same issue with AT&T. I upgraded from an iPhone 4S to the new iPhone 6 and it would only connect to 4G, not LTE. Additionally, the data connection would often drop out entirely, which could be remedied by cycling airplane mode. I tried resetting network settings and rebooting the phone several times, but nothing helped.
    Swapping the SIM card fixed the issue on my phone. I got a new SIM from an AT&T retail store. I spent TWO HOURS in online tech support chat with an AT&T representative before they finally agreed to let me swap SIMs. I powered off the phone, put in the new SIM, powered it on, and I immediately had LTE connectivity.

  • Exchange 2013 issue / OWA time-out and WiFi/Cell problem.

    Hi everybody,
    I'm having some issues with an Exchange 2013 server.
    When some users try to logon to the OWA page it keeps loading the page and ends with a time-out.
    This only applies to 6 or 7 users, other users can login and open the page.
    I tried to replace the signed certificate to solve this problem, and did a online analyzer check, most tests come out good.
    I can't seem to find the source of this problem.
    There are also multiple users that are having trouble to receive e-mail through the wifi on phones and tablets at home but when they switch to 3g it works fine.
    You might need more information, just ask.. i don't know where to search anymore.
    I tried inheritance on the AD, disabled SSL in the IIS, restarted the server, replaced the signed cert. etc.
    Update:
    I set the selfsigned cert in the IIS default web page,, to check if it responds to the certificate and it does, so the issue doesn't come from the certificate.
    This issue probably came up after CU1, and i've read something about healthboxes..
    I'm going to install CU6 and hope for good result.
    Kind regards,
    Tim

    I've installed CU6, only one of the six users have gained access to OWA or ECP.
    Al the other users won't get a logon screen, just a blank page.
    So there is no option to insert a username or password to login, the page keeps loading and ends with "the page cannot be displayed"
    But on my working spot i can open owa or ecp without any issues.
    I've recreated the virtual directory for ECP and OWA with powershell, and checked the certificate.
    I checked if the same certificate was connected to the back-end port 444, and this is set correct.
    I even reconnected the cert on 444 with the following.
    Open the Command Prompt
    Run-
    netsh http show sslcert
    This will show the certs, copy and paste this information into notepad.  Under     IP:port   : 127.0.0.1:443, note the certificate hash and application ID.
    Run this command-  (Yes, I know there is no :444 listed in the output from the earlier command.)
    netsh http delete sslcert ipport=0.0.0.0:444
    Run this command.  Replace certhas with the certificate hash and appid with the application ID you saved in notepad.
    netsh http add sslcert ipport=0.0.0.0:444 certhash=123123123123123 appid="{123123123123-1231231235}"
    I used powershell to set the login authentication,
    et-Owavirtualdirectory -identity "YourMailBoxServerName\owa (Exchange Back End)" -WindowsAuthentication $True -Basicauthentication $false -Formsauthentication $false
    set-Owavirtualdirectory -identity "YourCASserverName\owa (Default Web Site)" -WindowsAuthentication $True -Basicauthentication $false -Formsauthentication $false
    and iisreset /noforce
    I unchecked the "require SSL" on the default website and left it enabled on the owa and ecp etc.
    Checked if HTTP over Proxy is installed, but this one is need to install exchange 2013.
    I've checked all ECP/OWA directories in in the IIS, the directories point to the Exchange V15 folders, this should be correct.
    Something is really broken, i really can use the help..
    I'm going to try to install Exchange 2013 SP1, but i don't know if this one is needed when CU6 has been installed.
    The strange thing is, it seem to be location based, not user based.
    I can login perfectly, but when i try this at one of the employees, it ends up blank.
    When i try to connect on a location dat does not work, at the exact time i press the enter-key to open the page, the eventviewer logs the following:
    Event 4634 - An account was logged off.
    For the issue on the smartphones and tablets, everything worked fine a few months ago, and happens to users on different ISP connections.
    I already checked the inheritance settings on the users in the AD.
    Kind regards,
    Tim

  • Custom Trigger and error handling problem

    hi ! I'm creating a custom trigger in ASP
    <br />
    <br />all it do is to check the lenght of given string.
    <br />it has a logic , true or false operation.
    <br />I just want to display an error message !
    <br />
    <br />I try BEFORE or AFTER in trigger register, but still didn't work !
    <br />
    <br />but why it didn't work ?
    <br />
    <br />any ideas ?
    <br />
    <br /><%<br />'start Trigger_Custom trigger<br />Function Trigger_Custom (ByRef tNG)<br /><br /> xemployer = len(trim(tNG.getColumnValue("employer")))<br /> xemail = len(trim(tNG.getColumnValue("email")))<br /> xjob_position = len(trim(tNG.getColumnValue("job_position")))<br /> xeducation = len(trim(tNG.getColumnValue("education")))<br /> xreference = len(trim(tNG.getColumnValue("reference")))<br /> xage_max = len(trim(tNG.getColumnValue("age_max")))<br /> xgender = len(trim(tNG.getColumnValue("gender")))<br /> <br /> totallen = (xemployer + xemail + xjob_position + xeducation + xreference + xage_max + xgender)<br /><br /> if (totallen > 158) then<br /><br /> Set update_error = new tNG_error<br /> update_error.init "Your Data contain too much characters ! (max 158)", Array(), Array()<br /> Set Trigger_Custom = update_error<br /><br />  else<br /> Set Trigger_Custom = nothing<br />  end if<br /><br />Set Trigger_Custom = nothing<br />End Function<br />'end Trigger_Custom trigger<br />%>
    <br /><%<br />' Register triggers<br />ins_Job.registerTrigger Array("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1")<br />ins_Job.registerTrigger Array("BEFORE", "Trigger_Default_FormValidation", 10, formValidation)<br />ins_Job.registerTrigger Array("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.asp")<br />ins_Job.registerTrigger Array("BEFORE", "Trigger_Custom", 50)<br />%>
    <br />
    <br /><%<br />' Register triggers<br />upd_Job.registerTrigger Array("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1")<br />upd_Job.registerTrigger Array("BEFORE", "Trigger_Default_FormValidation", 10, formValidation)<br />upd_Job.registerTrigger Array("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.asp")<br />upd_Job.registerTrigger Array("BEFORE", "Trigger_Custom", 50)<br />%>

    hello there, thanks for replying
    <br />i know what you mean, i see that the first time i submitted in to this forum.
    <br />
    <br />actually IT IS SEPARATED !
    <br />i just copy paste my code into this TextBOX, and that's whats happened
    <br />
    <br />ok i copy paste my code again, but this time i use ENTER to seperated those lines.
    <br />
    <br /><% 'start Trigger_Custom trigger <br /><br />Function Trigger_Custom (ByRef tNG) <br /><br />xemployer = len(trim(tNG.getColumnValue("employer"))) <br />xemail = len(trim(tNG.getColumnValue("email"))) <br />xjob_position = len(trim(tNG.getColumnValue("job_position"))) <br />xeducation = len(trim(tNG.getColumnValue("education"))) <br />xreference = len(trim(tNG.getColumnValue("reference"))) <br />xage_max = len(trim(tNG.getColumnValue("age_max"))) <br />xgender = len(trim(tNG.getColumnValue("gender"))) <br /><br />totallen = (xemployer + xemail + xjob_position + xeducation + xreference + xage_max + xgender) <br /><br />if (totallen > 158) then <br /><br />Set update_error = new tNG_error <br />update_error.init "Your Data contain too much characters ! (max 158)", Array(), Array() <br />Set Trigger_Custom = update_error <br /><br />else <br />Set Trigger_Custom = nothing <br />end if <br /><br />Set Trigger_Custom = nothing <br />End Function <br />'end Trigger_Custom trigger <br />%>
    <br />
    <br /><% ' Register triggers <br /><br />ins_Job.registerTrigger Array("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1") ins_Job.registerTrigger Array("BEFORE", "Trigger_Default_FormValidation", 10, formValidation) ins_Job.registerTrigger Array("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.asp") ins_Job.registerTrigger Array("BEFORE", "Trigger_Custom", 50) <br /><br />%>
    <br />
    <br /><% ' Register triggers <br /><br />upd_Job.registerTrigger Array("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1") upd_Job.registerTrigger Array("BEFORE", "Trigger_Default_FormValidation", 10, formValidation) upd_Job.registerTrigger Array("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.asp") upd_Job.registerTrigger Array("BEFORE", "Trigger_Custom", 50) <br /><br />%>
    <br />
    <br />there it is My Actual Code looks like.
    <br />
    <br />again, thanks for replying

  • HT201269 hi, I made a mistake when I first connected my iphone to itunes and selected "set up as new device" instead of restore from back up. How do I go back to that step

    hello

    See  Erase your device  Here  >  http://support.apple.com/kb/HT4137
    Go to Settings > General > Reset > Erase all content and settings
    Then...
    Restore from Backup  >  http://support.apple.com/kb/ht1766

  • JTree selection problem when using custom renderer and editor

    Hello:
    I created a JTree with custom renderer and editor.
    The customization makes JCheckBox to be the component
    responsible for editing and rendering.
    The problem is that when I click on the node with the checkbox
    the JTree selection model does not get updated.
    Without customizations of the editor and renderer the MouseEvent would be fired and BasicTreeUI$MouseHandler.mousePressed() method would call
    the selectPathForEvent() method which would be responsible for updating
    the selection model. At the same time if I attach a mouse listener to the JTree (customized) I see the events when clicking on the nodes. It seems like the MouseEvent gets lost and somehow as a result of which the selection model does not get updated.
    Am I missing something?
    Thanks
    Alexander

    You probably forgot to call super.getTreeCellRendererComponent(...) at the beginning of your getTreeCellRendererComponent(...) method in your custom renderer.
    Or maybe in the getTreeCellEditorComponent(...) of the TreeCellEditor...

  • HT201210 Contact List Problem.   I have duplicates on my iPhone.  I turned off my Contact and selected "Delete Contacts"  Most of the contacts were deleted but about 120 were left on my phone.   I've tried selecting individual contacts and deleting them,

    Contact List Problem.   I have duplicates on my iPhone.  I turned off my Contact and selected "Delete Contacts"  Most of the contacts were deleted but about 120 were left on my phone.   I've tried selecting individual contacts and deleting them, No Go. 
    Can anyone help?   How do I get rid of these contacts so I can re-synch my iPhone. 

    I have exactly the same problem on my ipad. It is happening on only some contacts but, as with you, when I delete one of the contacts on the ipad, the second ipad contact and the contact on the imac are also deleted. This is even the case when I have differentiated the two contacts on the ipad and can see the one I have deleted on the ipad is not the same one as is then deleted on the imac.

  • Problems with Customer Service AND unexplained charges!

    I've been with Verizon for I-don't-know-how-many years, and through the years you are bound to have a few problems here and there but some of the problems are just ridiculous! It's also the same reocurring problem!!!!!!!!!!!!!!!! I was with Alltel first, before it was bought out by Verizon. The years I was with Alltel, I didn't have near as many problems. It seems EVERY time I do the smallest change or something to my phone or bill, I get a ridiculous amount of charges that I was NOT aware of, nor told about... EVEN IF I ask "So this isn't going to change my bill, or there will not be any unexpected/unexplained charges that I don't know about?"... BUT not matter how many times I ask... and NO matter how many times I am told "no"... there always is. For example.... last year, I updated and signed a new 2 year contract and purchased the first Driod. Before, my 30 day warranty was up, I was having problems with my Driod, and decided to send it in and get a new one. Before I did this.. I called customer service to make sure there would be no interuption in my bill, and there wouldn't be any unexpect charges, and there would be no difference in anything. I was told there was not, and once I recieved my new phone, just send it in and nothing would be changed. Of course, when I get my bill.. I see I was charged $500 for the new phone. It was explained to me that my credit card was reimbursed (which I never check that card, because I never used it expect to purchase the phone) and that I was recharged for the new phone, since it was a new phone. So I had to fork out the $500 (on top of my bill) and then wait months to get the $100 rebate card. Months after that, I "assumed liablity of my line" because I was on a plan with my family. I decided to have my own line, so I "assumed liability." I was not told that when I did that, I "renewed" my contract date. So I just added 6 more months to my 2 year contract. Was NOT told about that! Then again...... I was recently having problems with my Driod (the screen went black and would not come back on.) I had to turn on an OLD motorola razor, so I would not be without a phone for two days while I was waiting on my phone to come in. As soon as my phone came in, I had my Droid turned back on. I recieved my bill recently, and my bill was $200 over what it normally should be.... so I called in... apparently, when I had my phone replaced, they dropped off my data package and when I recieved my replacement driod, they never put it back on. So I was being charged for alllll my data usage... again I was NOT told about this. I wasn't even aware that they had dropped off my data package, and when/where did they get the authority to do that??? These are just a FEW of the problems that I have had.................................
    Does anyone have these reoccuring problems!?

    I understand that my bill can be viewed online, and I do view it fairly regularly, so if there are any unexplained charges, I can call Verizon asap. The problem does not come from me not understanding my bill, but from customer service. I have been with Verizon for a very long time, and it is a continuing problem. Where did Verizon get the 'OK' to drop my data package off my plan? Who authorized that?
    After calling Verizon and trying to find out the problem, the gentleman told me that when I activated on old phone while I was waiting on my new Droid to arrive, my data package was dropped off and I "should" have been told about that. When I reactiviated my new Droid, I "should" have called and had them restart my data package. I was not aware that when you activate an old phone that data plan is taken off your plan. In all my years of having cell phones, I never make two years with one phone. I have always, at one point, had to turn on an old phone, and my data package has NEVER changed. Why would I have my data package dropped and why would I have to call Verizon to have it restarted. I would never know to do that unless I was TOLD that my data packaged HAD to be re-added when I recieved my new phone, but I was never told of that.
    All of that is beside the point, the point is, Verizon was never given the authorization to change my plan. Never. My bill was taken care of and readjusted, and I am thankful for that. It does not change the fact it is always a hassle with Verizon Customer Service and I am always the one having to PROVE that I am not at fault, or that I was NEVER told of certian things. EVERY TIME I HAVE CALLED CUSTOMER SERVICE, I AM TOLD "I'M SORRY, THEY SHOULD HAVE TOLD YOU THAT."
    "they should" does not help my bill with the extra armount of charges.

  • Problem with addRow and MultiLine Cell renderer

    Hi ,
    Ive a problem with no solution to me .......
    Ive seen in the forum and Ivent found an answer.......
    The problem is this:
    Ive a JTable with a custom model and I use a custom multiline cell renderer.
    (becuse in the real application "way" hasnt static lenght)
    When I add the first row all seem to be ok.....
    when I try to add more row I obtain :
    java.lang.ArrayIndexOutOfBoundsException: 1
    at javax.swing.SizeSequence.insertEntries(SizeSequence.java:332)
    at javax.swing.JTable.tableRowsInserted(JTable.java:2926)
    at javax.swing.JTable.tableChanged(JTable.java:2858)
    at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableMo
    del.java:280)
    at javax.swing.table.AbstractTableModel.fireTableRowsInserted(AbstractTa
    bleModel.java:215)
    at TableDemo$MyTableModel.addRow(TableDemo.java:103)
    at TableDemo$2.actionPerformed(TableDemo.java:256)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
    64)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
    ctButton.java:1817)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
    .java:419)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
    istener.java:245)
    at java.awt.Component.processMouseEvent(Component.java:5134)
    at java.awt.Component.processEvent(Component.java:4931)
    at java.awt.Container.processEvent(Container.java:1566)
    at java.awt.Component.dispatchEventImpl(Component.java:3639)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
    at java.awt.Container.dispatchEventImpl(Container.java:1609)
    at java.awt.Window.dispatchEventImpl(Window.java:1590)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    This seems to be caused by
    table.setRowHeight(row,(getPreferredSize().height+2)); (line 164 of my example code)
    About the model I think its ok.....but who knows :-(......
    Please HELP me in anyway!!!
    Example code :
    import javax.swing.*;
    import javax.swing.table.*;
    import java.text.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class TableDemo extends JFrame {
    private boolean DEBUG = true;
    MyTableModel myModel = new MyTableModel();
    MyTable table = new MyTable(myModel);
    int i=0;
    public TableDemo() {
    super("TableDemo");
    JButton bottone = new JButton("Aggiungi 1 elemento");
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    //table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this window.
    getContentPane().add(bottone,BorderLayout.NORTH);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    bottone.addActionListener(Add_Action);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    class MyTable extends JTable {
    MultiLineCellRenderer multiRenderer=new MultiLineCellRenderer();
    MyTable(TableModel tm)
    super(tm);
    public TableCellRenderer getCellRenderer(int row,int col) {
              if (col==1) return multiRenderer;
              else return super.getCellRenderer(row,col);
    class MyTableModel extends AbstractTableModel {
    Vector data=new Vector();
    final String[] columnNames = {"Name",
    "Way",
    "DeadLine (ms)"
    public int getColumnCount() { return 3; }
    public int getRowCount() { return data.size(); }
    public Object getValueAt(int row, int col) {
    Vector rowdata=(Vector)data.get(row);
                                                                return rowdata.get(col); }
    public String getColumnName(int col) {
    return columnNames[col];
    public void setValueAt (Object value, int row,int col)
         //setto i dati della modifica
    Vector actrow=(Vector)data.get(row);
    actrow.set(col,value);
         this.fireTableCellUpdated(row,col);
         public Class getColumnClass(int c)
              return this.getValueAt(0,c).getClass();
         public boolean isCellEditable(int row, int col) {
    //Note that the data/cell address is constant,
    //no matter where the cell appears onscreen.
    if (col == 1)
    return false;
    else
    return true;
    public void addRow (String name,ArrayList path,Double dead) {
         Vector row =new Vector();
         row.add(name);
         row.add(path);
         row.add(dead);
         row.add(name); //!!!Mi tengo questo dato da utilizzare come key per andare a
         //prendere il path nella lista dei paths di Project
         //(needed as key to retrive data if name in col. 1 is changed)
         data.add(row);
         //Inspector.inspect(this);
         System.out.println ("Before firing Adding row...."+this.getRowCount());
         this.fireTableRowsInserted(this.getRowCount(),this.getRowCount());
    public void delRow (String namekey)
    for (int i=0;i<this.getRowCount();i++)
    if (namekey.equals(this.getValueAt(i,3)))
    data.remove(i);
    this.fireTableRowsDeleted(i,i);
    //per uscire dal ciclo
    i=this.getRowCount();
    public void delAllRows()
    int i;
    int bound =this.getRowCount();     
    for (i=0;i<bound;i++)     
         {data.remove(0);
         System.out.println ("Deleting .."+data);
    this.fireTableRowsDeleted(0,i);          
    class MultiLineCellRenderer extends JTextArea implements TableCellRenderer {
    private Hashtable rowHeights=new Hashtable();
    public MultiLineCellRenderer() {
    setEditable(false);
    setLineWrap(true);
    setWrapStyleWord(true);
    //this.setBorder(new Border(
    public Component getTableCellRendererComponent(JTable table,Object value,                              boolean isSelected, boolean hasFocus, int row, int column) {
    //System.out.println ("Renderer called"+value.getClass());
    if (value instanceof ArrayList) {
    String way=new String     (value.toString());
    setText(way);
    TableColumn thiscol=table.getColumn("Way");
    //System.out.println ("thiscol :"+thiscol.getPreferredWidth());
    //setto il size della JTextarea sulle dimensioni della colonna
    //per quanto riguarda il widht e su quelle ottenute da screen per l'height
    this.setSize(thiscol.getPreferredWidth(),this.getPreferredSize().height);
    // set the table's row height, if necessary
    //System.out.println ("Valore getPreferred.height"+getPreferredSize().height);
         if (table.getRowHeight(row)!=(this.getPreferredSize().height+2))
         {System.out.println ("Setting Row :"+row);
             System.out.println ("Dimension"+(getPreferredSize().height+2));
             System.out.println ("There are "+table.getRowCount()+"rows in the table ");
             if (row<table.getRowCount())
             table.setRowHeight(row,(getPreferredSize().height+2));
    else
    setText("");
    return this;
    /**Custom JTextField Subclass che permette all'utente di immettere solo numeri
    class WholeNumberField extends JTextField {
    private Toolkit toolkit;
    private NumberFormat integerFormatter;
    public WholeNumberField(int value, int columns) {
    super(columns);
    toolkit = Toolkit.getDefaultToolkit();
    integerFormatter = NumberFormat.getNumberInstance(Locale.US);
    integerFormatter.setParseIntegerOnly(true);
    setValue(value);
    public int getValue() {
    int retVal = 0;
    try {
    retVal = integerFormatter.parse(getText()).intValue();
    } catch (ParseException e) {
    // This should never happen because insertString allows
    // only properly formatted data to get in the field.
    toolkit.beep();
    return retVal;
    public void setValue(int value) {
    setText(integerFormatter.format(value));
    protected Document createDefaultModel() {
    return new WholeNumberDocument();
    protected class WholeNumberDocument extends PlainDocument {
    public void insertString(int offs,
    String str,
    AttributeSet a)
    throws BadLocationException {
    char[] source = str.toCharArray();
    char[] result = new char[source.length];
    int j = 0;
    for (int i = 0; i < result.length; i++) {
    if (Character.isDigit(source))
    result[j++] = source[i];
    else {
    toolkit.beep();
    System.err.println("insertString: " + source[i]);
    super.insertString(offs, new String(result, 0, j), a);
    ActionListener Add_Action = new ActionListener() {
              public void actionPerformed (ActionEvent e)
              System.out.println ("Adding");
              ArrayList way =new ArrayList();
              way.add(new String("Uno"));
              way.add(new String("Due"));
              way.add(new String("Tre"));
              way.add(new String("Quattro"));
              myModel.addRow(new String("Nome"+i++),way,new Double(0));     
    public static void main(String[] args) {
    TableDemo frame = new TableDemo();
    frame.pack();
    frame.setVisible(true);

    In the addRow method, change the line
    this.fireTableRowsInserted(this.getRowCount(),this.getRowCount()); to
    this.fireTableRowsInserted(data.size() - 1, data.size() - 1);Sai Pullabhotla

  • How to outline selected cells during drag and drop in the jtable

    Hi,
    I have spent a lot of time to find out how to outline selected cells during drag in the jtable, but I did not find the answer.
    Can anybody give me a tip, where to read more about this problem or even better, give an example...
    I have the following situation:
    1.Table has 10 rows and 10 columns
    2.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION) and setCellSelectionEnabled(true)
    3.user select 5 cells in 4th row (for example cell45,cell46,cell47,cell48 and cell49)
    4.user starts dragging. During dragging an outline should be drawn. Outline should be a rectangular with width of 5 cells and height of one cell. Outline should move according to the mouse position.
    5.rectangular disappears when dropped
    Regards,
    Primoz

    In "createTransferable" you can create a drag image
    which you can paint in "dragOver" and clear in "drop" method of DropTarget :
    package dnd;
    * DragDropJTableCellContents.java
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.datatransfer.*;
    import java.awt.dnd.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    public class DragDropJTableCellContents extends JFrame {
        public DragDropJTableCellContents() {
            setTitle("Drag and Drop JTable");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            getContentPane().add(createTable("JTable"), BorderLayout.CENTER);
            setSize(400, 300);
            setLocationRelativeTo(null);
        private JPanel createTable(String tableId) {
            DefaultTableModel model = new DefaultTableModel();
            for (int i = 0; i < 10; i++) {
                model.addColumn("Column "+i);
            for (int i = 0; i < 10; i++) {
                String[] rowData = new String[10];
                for (int j = 0; j < 10; j++) {
                    rowData[j] = tableId + " " + i + j;
                model.addRow(rowData);
            JTable table = new JTable(model);
            table.getTableHeader().setReorderingAllowed(false);
            table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            table.setCellSelectionEnabled(true);
            JScrollPane scrollPane = new JScrollPane(table);
            table.setDragEnabled(true);
            TableTransferHandler th = new TableTransferHandler();
            table.setTransferHandler(th);
            table.setDropTarget(new TableDropTarget(th));
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(scrollPane);
            panel.setBorder(BorderFactory.createTitledBorder(tableId));
            return panel;
        public static void main(String[] args) {
            new DragDropJTableCellContents().setVisible(true);
        abstract class StringTransferHandler extends TransferHandler {
            public int dropAction;
            protected abstract String exportString(JComponent c);
            protected abstract void importString(JComponent c, String str);
            @Override
            protected Transferable createTransferable(JComponent c) {
                return new StringSelection(exportString(c));
            @Override
            public int getSourceActions(JComponent c) {
                return COPY;
            @Override
            public boolean importData(JComponent c, Transferable t) {
                if (canImport(c, t.getTransferDataFlavors())) {
                    try {
                        String str = (String) t.getTransferData(DataFlavor.stringFlavor);
                        importString(c, str);
                        return true;
                    } catch (UnsupportedFlavorException ufe) {
                    } catch (IOException ioe) {
                return false;
            @Override
            public boolean canImport(JComponent c, DataFlavor[] flavors) {
                for (int ndx = 0; ndx < flavors.length; ndx++) {
                    if (DataFlavor.stringFlavor.equals(flavors[ndx])) {
                        return true;
                return false;
        class TableTransferHandler extends StringTransferHandler {
            private int dragRow;
            private int[] dragColumns;
            private BufferedImage[] image;
            private int row;
            private int[] columns;
            public JTable target;
            @Override
            protected Transferable createTransferable(JComponent c) {
                JTable table = (JTable) c;
                dragRow = table.getSelectedRow();
                dragColumns = table.getSelectedColumns();
                createDragImage(table);
                return new StringSelection(exportString(c));
            protected String exportString(JComponent c) {
                JTable table = (JTable) c;
                row = table.getSelectedRow();
                columns = table.getSelectedColumns();
                StringBuffer buff = new StringBuffer();
                for (int j = 0; j < columns.length; j++) {
                    Object val = table.getValueAt(row, columns[j]);
                    buff.append(val == null ? "" : val.toString());
                    if (j != columns.length - 1) {
                        buff.append(",");
                return buff.toString();
            protected void importString(JComponent c, String str) {
                target = (JTable) c;
                DefaultTableModel model = (DefaultTableModel) target.getModel();
                String[] values = str.split("\n");
                int colCount = target.getSelectedColumn();
                int max = target.getColumnCount();
                for (int ndx = 0; ndx < values.length; ndx++) {
                    String[] data = values[ndx].split(",");
                    for (int i = 0; i < data.length; i++) {
                        String string = data;
    if(colCount < max){
    model.setValueAt(string, target.getSelectedRow(), colCount);
    colCount++;
    public BufferedImage[] getDragImage() {
    return image;
    private void createDragImage(JTable table) {
    if (dragColumns != null) {
    try {
    image = new BufferedImage[dragColumns.length];
    for (int i = 0; i < dragColumns.length; i++) {
    Rectangle cellBounds = table.getCellRect(dragRow, i, true);
    TableCellRenderer r = table.getCellRenderer(dragRow, i);
    DefaultTableModel m = (DefaultTableModel) table.getModel();
    JComponent lbl = (JComponent) r.getTableCellRendererComponent(table,
    table.getValueAt(dragRow, dragColumns[i]), false, false, dragRow, i);
    lbl.setBounds(cellBounds);
    BufferedImage img = new BufferedImage(lbl.getWidth(), lbl.getHeight(),
    BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics2D graphics = img.createGraphics();
    graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
    lbl.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
    lbl.paint(graphics);
    graphics.dispose();
    image[i] = img;
    } catch (RuntimeException re) {
    class TableDropTarget extends DropTarget {
    private Insets autoscrollInsets = new Insets(20, 20, 20, 20);
    private Rectangle rect2D = new Rectangle();
    private TableTransferHandler handler;
    public TableDropTarget(TableTransferHandler h) {
    super();
    this.handler = h;
    @Override
    public void dragOver(DropTargetDragEvent dtde) {
    handler.dropAction = dtde.getDropAction();
    JTable table = (JTable) dtde.getDropTargetContext().getComponent();
    Point location = dtde.getLocation();
    int row = table.rowAtPoint(location);
    int column = table.columnAtPoint(location);
    table.changeSelection(row, column, false, false);
    paintImage(table, location);
    autoscroll(table, location);
    super.dragOver(dtde);
    public void dragExit(DropTargetDragEvent dtde) {
    clearImage((JTable) dtde.getDropTargetContext().getComponent());
    super.dragExit(dtde);
    @Override
    public void drop(DropTargetDropEvent dtde) {
    Transferable data = dtde.getTransferable();
    JTable table = (JTable) dtde.getDropTargetContext().getComponent();
    clearImage(table);
    handler.importData(table, data);
    super.drop(dtde);
    private final void paintImage(JTable table, Point location) {
    Point pt = new Point(location);
    BufferedImage[] image = handler.getDragImage();
    if (image != null) {
    table.paintImmediately(rect2D.getBounds());
    rect2D.setLocation(pt.x - 15, pt.y - 15);
    int wRect2D = 0;
    int hRect2D = 0;
    for (int i = 0; i < image.length; i++) {
    table.getGraphics().drawImage(image[i], pt.x - 15, pt.y - 15, table);
    pt.x += image[i].getWidth();
    if (hRect2D < image[i].getHeight()) {
    hRect2D = image[i].getHeight();
    wRect2D += image[i].getWidth();
    rect2D.setSize(wRect2D, hRect2D);
    private final void clearImage(JTable table) {
    table.paintImmediately(rect2D.getBounds());
    private Insets getAutoscrollInsets() {
    return autoscrollInsets;
    private void autoscroll(JTable table, Point cursorLocation) {
    Insets insets = getAutoscrollInsets();
    Rectangle outer = table.getVisibleRect();
    Rectangle inner = new Rectangle(outer.x + insets.left,
    outer.y + insets.top,
    outer.width - (insets.left + insets.right),
    outer.height - (insets.top + insets.bottom));
    if (!inner.contains(cursorLocation)) {
    Rectangle scrollRect = new Rectangle(cursorLocation.x - insets.left,
    cursorLocation.y - insets.top,
    insets.left + insets.right,
    insets.top + insets.bottom);
    table.scrollRectToVisible(scrollRect);
    Edited by: Andre_Uhres on Nov 18, 2007 10:03 PM

Maybe you are looking for