JTable: moving from cell to cell in a row

Hello,
in the following code the first cell is editable when the programme comes up.
To move to the next cell (no matter whether you entered some characters or
not), you have hit either <Enter>, <Tab> or <Right arrow> - but twice. To move
on to the third and fourth cell, only one hit is sufficient.
What actually happens becomes visible, when you change the code to make the 3rd
cell editable at programme start. Then you see that the first hit of <Enter>,
<Tab> or <Right arrow> goes back to the 1st cell. I would accept this for the
<Enter> key, but definitely not for <Tab> and <Right arrow>.
Any idea how this behaviour could be avoided?
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class ReadyForInput extends JFrame {
  public ReadyForInput() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(300, 100);
    setLocationRelativeTo(null);
    setTitle("ReadyForInput");
    Container cp = getContentPane();
    String headers[] = {"Key", "Value", "Description", "Comment"};
    JTable table = new JTable(1, headers.length);
    DefaultTableModel dtm= (DefaultTableModel)table.getModel();
    dtm.setColumnIdentifiers(headers);
    JScrollPane scrollPane = new JScrollPane(table);
    cp.add(scrollPane, BorderLayout.CENTER);
    table.getSelectionModel().setSelectionInterval(0,0);
    setVisible(true);
    table.editCellAt(0, 0);
//    table.editCellAt(0, 2); // 3rd cell editable
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
     new ReadyForInput();
}

table.changeSelection(0, 2, false, false);
table.editCellAt(0, 2); // 3rd cell editable

Similar Messages

  • What formula for finding sum of Time from cells in a row?

    Is there a template on Numbers or a simple Sum formula that i can use to add hours and minutes worked so that a cell will show total number of hours and minutes worked in a day? Thanks.

    In its bare form, the required formula would be :
    =(timeOut1-timeIn1)+(timeOut2-timeIn2)+(timeOut…-timeIn…)
    this said, you must understand that Numbers has no time items.
    It has date_time ones and, if it's Numbers '09, it has duration ones.
    A cell whose format is defined to display only a time value contains always a date component.
    Near the safari window in which I am writing is a Numbers document.
    If I type 13:58:20 in cell B2, the app starts displaying 13:58 because the contents parser which is in Automatic mode recognized that my entry was resembling to a time one. So it « decided » to display only the hours and minutes of the time component.
    If I enter the Cells Inspector and define the format to date time displaying the date and the time (with seconds), I get: 2012-04-12 13:58:20
    If the process whose start was just typed is supposed to end at 18:26, I may repeat the already described process to C2 but as quite everybody knows in this Discussions forum, I'm lazy.
    So, I select every cells supposed to receive a time value and define, temporarily, their format to date_time displaying date, time with seconds. This way I will not have to repeat that for every entry.
    In C2, I type 18:26.
    The app displays : 2012-04-12 18:26:00
    Leaving space for two other tasks, in H2, I type =C2-B2
    As I am running Numbers '09, I get 4h 27m 40s which is a duration value.
    Now, we will assume that the start time remains unchanged but that the task will end tomorrow at 5:55
    If I type this value immediately in C2, the cell will contain 2012-04-12 05:55:00 and H2 will contain -8h 3m 20s which is certainly not what you want to get.
    If I wait tomorrow before typing this end time in C2, the cell will contain 2012-04-13 05:55:00 and H2 will display the wanted value : 15h 56m 40s.
    CAUTION : the application made no error, it just did exactly what I wanted it to achieve.
    Third case, I decide to type the start and the end time when the task isfinished, say on 2012-04-14,
    B2 will contain : 2012-04-14 18:26:00
    C2 will contain : 2012-04-14 05:55:00
    and one more time we will get the infamous -8h 3m 20s which is certainly not what you want to get.
    So, it's clear that a more sophisticated formula is required.
    Here I will describe the one which I use. I guess that other helpers will describe other ones. It's the rule of the game.
    I use the function TIMEVALUE.
    =(TIMEVALUE(C2)-TIMEVALUE(B2)+IF(TIMEVALUE(C2)>TIMEVALUE(B2),0,1))*24
    which will return the durations expressed in decimal hours.
    This formula is OK as long as the task duration isn’t longer than 24 hours.
    If a task duration may be greater than 24 hours, the best scheme would be to enter full date_time values.
    For several tasks, the formula would be :
    =(TIMEVALUE(C2)-TIMEVALUE(B2)+IF(TIMEVALUE(C2)>TIMEVALUE(B2),0,1)+TIMEVALUE(E2)- TIMEVALUE(D2)+IF(TIMEVALUE(E2)>TIMEVALUE(D2),0,1)+TIMEVALUE(G2)-TIMEVALUE(F2)+IF (TIMEVALUE(G2)>TIMEVALUE(F2),0,1))*24
    Yvan KOENIG (VALLAURIS, France) jeudi 12 avril 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.3
    My Box account  is : http://www.box.com/s/00qnssoyeq2xvc22ra4k

  • JTable: RFC on good practice (SQL queries from cell editor)

    I usually add/remove/edit JTable data from an external panel. But in this scenario, my client would like to be able to click on the first column of an empty row and enter a product number. Within the cell editor, I must make an SQL query to the database in order to determine if the product number is valid and if so, use part of the SQL data to populate other cells of the current row (like product description).
    My problem is that this just doesn't seem right! Isn't the cell editor executed on the only Swing thread? Also, if the product number is not valid, I correctly implement the stopCellEditing() method but for some reason, you can still navigate the table (click on any other cell or press the TAB key, etc)... weird!!
    Does anyone have a good practice on how to perform the SQL query in a better place and force a cell to be selected until you enter a valid number or press the CANCEL key?
    I was looking at implementing the TableModelListener's tableChanged(...) method but I'm not sure if that would be a better place either.
    I personally would edit outside of the table, but good practice seems hard when the requirement is to edit from a cell editor!!
    Any suggestion would be greatly appreciated!
    Thanks!

    maybe you could write an input verifier for the column that does the query and rejects invalid entries.
    maybe you could send the query off in a worker thread.
    as far as making the table so you can't select any cells, hmm. not sure.
    you could disable
    .setEnabled(false);the table until the query comes back, something like that.

  • DATAGRID FOCUS ISSUE: Focus got lost, while moving from one cell to another cell using tab key.

    Problem: Focus got lost, while moving from one cell to another cell using tab key.
    Example: In an AdvanceDataGrid, there are three columns having custom ItemRenderer with Spark TextInput control (editable=true & focusEnabled=true).
    When I try to move the focus in with in 2nd, 3rd & 4th column using tab key, focus got lost. Most of the time it’s working, but some time it doesn’t work. There’s no clue as to how may rows/columns the focus has jumped to; or whether the focus has gone out of the data grid altogether.
    Observations: I am not sure whether this problem is because of custom component implementation or it is because of some issue related to Flex Component.
    It only occurs when we perform some actions like some server call, some complex logic execution etc. at the focus out event of itemrenderer.
    There is one property of datagrid i.e. editedItemPosition which contains row & column index of datagrid. On the focus out event, it gets null when focus got lost. We tried to set it, but it didn’t work.
    Steps Performed:-
    1. Currently focus is in 2nd column i.e. Apply to #.
    2. Once I press tab key from 2nd column, it goes to 3rd column which is correct.
    3. Now if I press tab key from 2nd column i.e. Payment #, focus should go to 3rd column, but it goes out of data grid and set the focus of button which is outside data grid.

    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2Bjtable+%2Btab+%2B%22enter+key%22&col=javaforums

  • Another JTable/buttons in cells query - event forwarding

    Hi Everyone.
    Apologies in advance for yet another thread on this subject. I realise this has been discussed a number of times but I can't find what seems like a definitive solution.
    I understand what the fundamental issue is with putting JComponents in table cells - i.e. that the cells are rendered essentially as static visual entities, that they're not "components" as such and will not receive events.
    I'd like to implement JButtons in table cells so that they behave as "normally" as possible - i.e. handle their own roll-over appearance, handle their own pressed appearance, and fire action events when pressed, with as little manual intervention in these mechanisms (e.g. in mouse listener code) as possible. I'm trying to do this by forwarding mouse events from the table to the button, but this doesn't seem to work as I'd hoped and I have various questions...
    (Background: I have implemented JButton objects in the data model, and the getTableCellRendererComponent() method returns *(JButton)value*.)
    My first question concerns the interception of mouse events. The usual technique would be to add a mouse listener and/or mouse motion listener to the table, and implement mouseClicked(), mousePressed() etc. However, can I override the table's processMouseEvent() and processMouseMotionEvent() methods instead, and from here forward events to buttons where appropriate, or process normally with super.processMouseEvent()? My motivation for doing this would be specifically not to invoke the super methods where events were forwarded to buttons - effectively consuming the event. Is this correct technique?
    My second question concerns attempts to reproduce button roll-over appearances. The JTable is of course considered a single entity as far as mouse events are concerned, and MOUSE_ENTERED and MOUSE_EXITED events aren't generated as the pointer moves from cell to cell. Merely forwarding mouse events to buttons - which will mostly be MOUSE_MOVED events - seems to be insufficient and presumably the roll-over appearance change relies upon ENTERED and EXITED events occurring at the proper times.
    I mimicked this behaviour in my override of processMouseMotionEvent() by calculating the value (i.e. JButton reference) of the cell under the mouse pointer, and if it wasn't the same as for the previous event, manually creating a MOUSE_ENTERED event and forwarding it to the new button. This seemed to work - the rollovers were happening (provided a table repaint() was performed), but it seemed to work without needing to explicitly sending a MOUSE_EXITED to the previous button before sending MOUSE_ENTERED to the new. I'm unclear why this is so - I was half-expecting both buttons to acquire the roll-over state, and they didn't.
    Also, I had assumed that having taken care of this, I should forward MOUSE_MOVED events occurring within the confines of a cell's area to the button verbatim, but this seems to instantly cancel out any roll-over (visually the button would briefly flash a roll-over appearance as the pointer moved into its cell bounds). Why might this be so?
    My last question is about the actual pressing of the button. I had hoped that forwarding MOUSE_CLICKED, MOUSE_PRESSED and MOUSE_RELEASED would cause the button to (a) acquire the button-pressed state, and (b) fire an action event to its action listeners. Neither of these things occur, and I don't understand why not.
    In summary, is interception and forwarding of events like this a viable technique for implementing table cell buttons? The various solutions that a Google trawl throws up all reproduce button-pressing mechanics in varying degrees, some just detecting a click and calling some user function, others manually manipulating the button model in the mouse handler etc. If possible I'd like to avoid this, and leave as much processing as possible to the button's native code.
    Thanks in advance for any suggestions received.
    Regards,
    A.

    try to look on this
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender

  • How to delete formula from cells and keep the values in Excel VBA

    Hi,
    In my Excel I have 15 columns. In column F which has a formula (INDEX MATCH), it has contains "RECEIVED" and "INTRANSIT". I need to filter the column F for all "RECEIVED" and then remove the formula from cells and
    retain or keep the values that are already in the cells. something tricky and i'm not sure on how to work on this in Excel VBA.
    Below is my initla VBA code:
    I already have the codes on how to filter. kindly please help me on how to do this. thank you in advance.
    Sub test_Click()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim rng As Range
    Dim lrow As Long
    Set wb = ThisWorkbook
    Set ws = wb.Sheets("Intransit_")
    Application.ScreenUpdating = False
    ws.AutoFilterMode = False
    With ws
    lrow = .Range("F" & Rows.Count).End(xlUp).Row
    Set rng = .Range("A1:R" & lrow)
    Debug.Print rng.Address
    rng.AutoFilter Field:=6, Criteria1:="RECEIVED"
    End With
    Application.creenUpdting = True
    End Sub

    Solved.
    Sub test_Click()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim rng As Range
    Dim lrow As Long
    Dim rRec As Range
    Dim btField As Byte
    Set wb = ThisWorkbook
    Set ws = wb.Sheets("Intransit_")
    btField = 6
    Application.ScreenUpdating = False
    ws.AutoFilterMode = False
    With ws
    lrow = .Range("F" & Rows.Count).End(xlUp).Row
    Set rng = .Range("A1:R" & lrow)
    With rng
    .AutoFilter Field:=btField, Criteria1:="RECEIVED"
    On Error Resume Next
    Set rRec = .SpecialCells(xlCellTypeVisible)
    On Error GoTo 0
    End With
    .AutoFilterMode = False
    If Not rRec Is Nothing Then
    With rRec
    .Columns(btField).Value = .Columns(6).Value
    End With
    End If
    End With
    Application.ScreenUpdating = True
    End Sub

  • Execute Stored Procedure SQL Statement with Parameter from Cell

    I would like to know if there is a way to pass the parameters to SQL Statement of Power Query. For example, I have a SQL Statement as follows:
    EXEC [dbo].[spReportBuilder]
    @Report = N'Revenue Summary',
    @Year = N'2014',
    @Period = N'11'
    I would like to know if it is possible to pass the @Report, @Year, @Period values from cells in the workbook, preferably without vba.
    Thanks

    rtisserand, 
    Here is the M code: 
    let
    IDValue = Excel.CurrentWorkbook(){[Name="YearTable"]}[Content],
    Source = Sql.Database("localhost", "AdventureWorks2012", [Query="EXEC [dbo].[spReportBuilder] @Report = N'Revenue Summary', @Year = N'" & Number.ToText(IDValue[ID]{0}) & "', @Period = N'11'"])
    in
    Source
    Some notes:
    You have to reference the excel query from another step in the query or you will get the following error: 
    Formula.Firewall: Query <>something<> references other queries or steps and so may not directly access a data source. Please rebuild this data combination.
    I only did the parameter for one value.
    Hope this helps.
    Reeves
    Denver, CO

  • How do you set defaults in pages such as font and moving between cells in a table?

    How do you set defaults in Pages such as font and moving between cells in a table?

    Default layout and styles can be set by setting up a sheet with your settings and saving as a user template (File > Save As Template).  I don't know of a way to set defaults for moving between cells in a table.

  • I am having a problem moving across cells in Microsoft Excel. When I use the arrow keys, the sheet moves, instead of moving to the next cell. Would anyone have any thoughts on this, please?

    I am having a problem moving across cells in Microsoft Excel. When I use the arrow keys, the sheet moves, instead of moving to the next cell. Would anyone have any thoughts on this, please?

    Hi,
    Did you find a way to solve your problem ? We have exactly the same for one application and we are using the same version of HFM : 11.1.2.1.
    This problem is only about webforms. We can correctly input data through Data Grids or Client 32.
    Thank you in advance for your answer.

  • Moving cells independent of rows, ie delete cell and move others up.

    This has to be easy but i can't figure it out. I have a document with 4 columns by 50 rows. All of the cells are independent of the rows they are in and from time to time i need to delete a cell and move the cells below it up. Its easy in excel, you just highlight the cell and it asks "move up" or "move down". I can't seem to find anything comparable in numbers. I seem to be only able to delete entire rows which would delete cells in other columns that I need. Is there a way to do this? Thanks.

    r,
    It's pretty easy in Numbers too, but it's not the same. Let's say you want to move all the cells below a certain cell up one row to eliminate that single cell. Select all the cells that you want to move, Edit > Mark for Move, click on the cell you want to eliminate, Edit > Move.
    Jerry

  • Re-name worksheet tabs from cell contents?

    Is is possible to re-name worksheet tabs automatically from cell contents in another sheet within the same workbook?
    I have a workbook with 30 sheets all feeding data into sheet 31 - the Master Worksheet where all the data is collated etc.
    There are occasions when I'll need to rename the individual sheets, but is there a way to change this in my 'master worksheet' without having to go back and individually re-name all the other sheets?

    General,
    At this time there is no way to do what you want.  If you can formulate a clear feature request you can post your idea to Apple using the menu item "Numbers > Provide Numbers Feedback".
    There is a way, however, to use a function called indirect() that can take input from a table to construct a cell reference.  Not know your specific setup it is hard to provide a specific suggestion. 

  • Method for leave cursor from cell

    Hi Experts,
    I need to implement action on leave cursor from cell .
    here If after enter data for one cell then relevant data populated for other cells .
    please suggest the solution without using button or llink.
    Regards,
    BBC

    Hi,
        To populate data in a cell depending on data entered in another cell, there must be some kind of user
         action like button clicks or press Enter. Without any action we cannot populate relevant data in the cell.
        And WDA does not have any events like leave cursor So we need some kind of action,Else its
        not possible.,

  • Jtable in the cell of parent jtable

    hi,
    i wans to make jtable whose all cell's contains jtable and all of these jtables should dynamically get different datas .suppose i needs to create a parent 10*3 jtable,now all the 30 cells again contains jtable of 1*2 and all these 1*2 jtables contains different datas at runtime how can i do that plz sujjest me.

    Implement the TableCellRenderer interface to return a JTable.
    How to use tables: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    Also worth asking yourself whether you really are better off with tables within tables, or if it's more appropriate to simply use a 10x6 table. Might be one, might be the other.

  • Is it possible to tab from cell to cell in New Numbers ver 3.0.1?

    Have a brand new iMac with the new version of Nombers 3.0.1 and cannot fins a way to single stroke the tab key to move across the sheet from cell to cell, it only seems to work in conjunction with clicking the mouse. ( when I used Windows/Excel I could use the tab key to move across or down the sheet) and I beleive it worked the same on Numbers ver 2.3, can anyone assist please?

    Not sure exactly what you are looking for and can't find, but on my machine Tab works as described here, the same or very similar to the way it works in Excel:
    You can find descriptions of keyboard shortcuts via Help > Keyboard Shortcuts, which takes you here.
    SG

  • Is an iPad 1 able to send and revive from cell phone number?

    Is an iPad 1 able to send and revive from cell phone number?

    Hamm77 wrote:
    Ok thank you .....but....it only gives me a place to enter emails and not send and recieve from a phone number....I appreciate your help Jonathan .... Thanks
    Exactly.
    Jonathan wrote:
    You can only send and receive iMessages on iPads-they do not do SMS
    The messages you send to phone numbers are known as SMS. The iPad cannot send those. Only iMessages through email addresses.

Maybe you are looking for

  • DSM Terminator problem

    Hi everyone, I am getting this DSM Terminator window popup when I close any of my WD application. I thought it was because those RFCs calls that I make but it isn't related. I created a simple HelloWorld project, created an iView and a Page. When I p

  • Does the "import library" function work?

    I'm a big fan of Apple and its Mac OS X, but let me tell you that the iTunes is not a good software. And I, as a big music fan, a person who has used a lot of software for managing music, I even believe that iTunes is one of the worst. I could discus

  • Installing Form, Reports 11g

    For the Last few weeks i have been reading all the documents on the internet, so i at last became able to install Oracle Databse 11g install RCU /installing Schemas, all of it, installling weblogic 1033 using identity Managment installed OID etc iden

  • Can compresed data in cube load upward.

    Hi I have a cube where data is all compressed, I tried to load this data to another cube but the DTP process is being stuck in extraction step for hrs. Is it possible to load data upward from a compressed cube. Thanks Amit

  • Regenerating the object after Transport

    Hi, We are seeing a issue which we had not seen earlier. If there is any user exit  changed, the object is not getting activated unless we regenerate the object in the target environment. Basically Include programs are not activated in the target sys