How do I get at a JTable on a JInternalFrame?

I've been working on this Multiple Document Interface application, and things have been great up to this point. The user chooses to run a "report" and then selects an entity to get the info for. I then hit the database. Each row returned from the database query goes into it's own data object, which is added to an ArrayList in my custom table model, and that ArrayList is used to generate the JTable, which is then added to a ScrollPane, which is then added to the JInternalFrame, which is then added to the JDesktop pane. Good stuff, right?
I'm now trying to add Print functionality, and I'm at a loss. What I want to do is have the user do the standard File->Print, which will print out the JTable on the currently selected inner frame. I can get a JTable to print using JTable.print(). What I can't do is find a way to get the JTable from the selected frame.
I can get the selected frame using desktop.getSelectedFrame(), but I'm at a loss as to what to do next. I've played around with .getComponent, but I'm not having any luck. the components returned don't seem to do me any good...for example, JViewPort?
Am I going about this the wrong way? Have I poorly designed this? Am I missing the obvious?
Thanks,
-Adam

Well, if you only have a single component on the internal frame then you can use getComponent(0). But then you need to go up the parent chain to get the actual table. You will initially get the JScrollPane, then use that to get the JViewport and then use that to get the viewport component.
Another option is to extend the JInternalFrame class and insted using the add method to add a component you create get/setTable(...) methods. Then you can save the table as a class variable before adding it the scrollpane and adding the scrollpane to the internal frame.

Similar Messages

  • How do I get Integer in JTable cell to be selected when edit using keyboard

    I have some cells in a JTable, when I double-click on the cell to edit it the current value (if any) is selected and is replaced by any value I enter, which is the behaviour I want. But when I use the keyboard to navigate to the cell and start editing, new values are added to the end of the current value which is not what I want.
    I have created my own IntegerCellEditor (see below) and added a focus event or the textfield used when editing to select all the current text but it has no effect, any ideas please ?
    public class IntegerCellEditor extends DefaultCellEditor
        public IntegerCellEditor( JTextField textfield )
            super( textfield );    
            //Ensure old value is always selected, when start editing
            ((JTextField)getComponent()).addFocusListener(new FocusAdapter()
                    public void focusGained(FocusEvent fe){
                        ((JTextField)getComponent()).selectAll();
            ((JTextField)getComponent()).setHorizontalAlignment(JTextField.RIGHT);
         * Return as Integer (because delegate converts values to Strings).
        public Object getCellEditorValue()
            return Integer.valueOf((String)delegate.getCellEditorValue());
    }

    But when I use the keyboard to navigate to the cell and start editing,
    new values are added to the end of the current value which is not what I want.How does the use know that typing will replace the text and not append? Usually if text is to be deleted, it is highlighted to give the user a visual cue.
    Here is a renderer that does this, in case your interested:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=752727

  • How can I get the edited value from the editor in JTable

    I have a JTextField added as an editor to a cell in JTable.
    I value gets changed when I press enter.
    but in actionPerformed of the JTextField when I say
    String txtEditorValue = txtEditor.getText();
    I am getting the old value. How can I get the edited value? Thanks.

    Hi,
    I guess, your understanding of how JTable works together with its models is not good enough - for example the method getTableCellEditorComponent(...) of the TableCellEditor interface is used to get the component, that should be used as editing component - its second parameter is a value that should be used to setup the editing component - it is normally not the editing component itself.
    JTable uses an underlying TableModel to store the cell values - if you have edited a cell, JTable gets the value of the editing component by itself and stores it in the TableModel using its setValueAt(...) method. To retrieve this data you only need to query the TableModel using row and column of this cell as parameters
    say jt is your JTable, and row and column are the row and column of the cell - so to get the value, simply use
    Object obj = jt.getModel().getValueAt(row,column);
    if you know, that there is a String in this cell use
    String str = (String) jt.getModel().getValueAt(row,column);
    The editor component is used for the view of the JTable - you only want the data, which is stored in the model - you don't have to deal with the GUI components in this case.
    greetings Marsian

  • How can I get right data in a cell of JTable when table  enter editing

    how can I get right data in a cell of JTable when table enter editing

    how can I get right data in a cell of JTable when table enter editing

  • How can I get the JCheckBox value in JTable?

    I have a JTable with JCheckBox inside. How can I get the value when the user turn on or off the check? I need to do this when the user change the value.
    Thanks for any help.
    Renato

    Hi again,
    no - the datamodel is a class that implements the TableModel-interface - if you do not use your own model in JTable, an instance of DefaultTableModel is used - you can subclass DefaultTableModel and overwrite its setValueAt(...)-method. When you instantiate your JTable do it by passing your DefaultTableModel subclass to the constructor or in the way you do it right now and replace the default model with your model using the setModel(...)-method of JTable.
    greetings Marsian

  • (JTable) How can i get the first columns cell in a selected row?

    Hello. I am trying to figure out how i can get the first columns cell within a selected row no matter what cell is selected in that row. I have a class that extends AbstractTableModel which represents the table. Now i have another class that extends DefaultSelectionModel. Each model is added to the JTable via setModel(TableModel dataModel), setSelectionModel(ListSelectionModel newModel). Now i don't understand what i have to return from getMaxSelectionIndex(). Any ides? Thanks.
      class xTableModel extends AbstractTableModel{
         private static String[] cols;
         private Object[][] data;
            public void setTableModel(Object data[][], String[] cols){
             this.cols = cols;
             this.data = data;
            public String getColumnName(int col){
             return cols[col];
            public int getRowCount() {
             return data.length;
            public Object getValueAt(int row, int col) {
             return data[row][col];           
            public void setValueAt(Object value,int row,int col){
             data[row][col]=value;
            public int getColumnCount(){
             return cols.length;
    class ColumnListenerModel extends DefaultListSelectionModel{
         public int getMaxSelectionIndex(){}

    int row = table.getSelectedRow();
    Object data = table.getValueAt(row, 0);

  • How can I get a Row in a JTable?

    I want to get the Last row in a JTable. How can I get it? Thanks.

    something like
    TableModel tm = table.getModel();
    int rows = tm.getRowCount();
    Object col0Value = tm.getValueAt(rows, 0);
    Object col1Value = tm.getValueAt(rows,1);
    ...

  • How can i get all values from jtable with out selecting?

    i have one input table and two output tables (name it as output1, output2). Selected rows from input table are displayed in output1 table. The data in output1 table is temporary(means the dat wont store in database just for display purpose).
    Actually what i want is how can i get all values from output1 table to output2 table with out selecting the data in output1 table?
    thanks in advance.
    raja

    You could set the table's data model to be the same:
    output2.setModel( output1.getModel() );

  • Question for BasicComboBoxEditor use in JComboBox  How can I get right ce

    I use a JComboBox as the editor for JTable.Now I met a problem In use object that BasicComboBoxEditor as the editor for JComboBox that in JTable.
    I can't get the cell data rightly.I can't get the editing row and column when system call getEditorComponent() . Mouse event process is after getEditorComponent().
    How can I get right cell data when then getEditorComponent calling?

    Sorry,I am english is poor.
    I use a component of JComboBox as editor of JTable. then
    I want to konw that how can I get right data in a cell of JTable when table enter editing

  • How to select a row in JTable

    Hello,
    I have a problem selecting a row in a JTable.
    I use
    mytable.getSelectionModel().setSelectionInterval(row, row);
    to select a row, but after that this row is only highlighted. After calling this method I cannot change the selection using the arrow keys.
    Can anybody give me a hint, how I can get the row selected, so that I can use the arrow keys immediately after selecting the row?
    Any help is welcome.
    Thanks,
    Fritz

    Hello,
    I got the solution:
    final int pRow = row;
    final int pCol = column;
    final JTable myTable = mytable;
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    myTable.requestFocusInWindow();
    myTable.changeSelection(pRow, pCol, true, true);

  • I am having macbook air recently my iphotos did not open and was showing report apple and reopen but i came to know that by pressing alt and iphotos i open an new photo library and stored the pics but now how can i get the pics which i had in the earlier

    i am having macbook air recently my iphotos did not open and was showing report apple and reopen but i came to know that by pressing alt and iphotos i open an new photo library and stored the pics but now how can i get the pics which i had in the earlier photo please help me to recover my photos

    Well I'll guess you're using iPhoto 11:
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Repair Database. If that doesn't help, then try again, this time using Rebuild Database.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. (In early versions of Library Manager it's the File -> Rebuild command. In later versions it's under the Library menu.)
    This will create an entirely new library. It will then copy (or try to) your photos and all the associated metadata and versions to this new Library, and arrange it as close as it can to what you had in the damaged Library. It does this based on information it finds in the iPhoto sharing mechanism - but that means that things not shared won't be there, so no slideshows, books or calendars, for instance - but it should get all your events, albums and keywords, faces and places back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.  
    Regards
    TD

  • TS3989 My 5th gen ipod touch was stolen.  I removed the device from my iTunes account, but their pictures still show up on the photostream on the one I purchased to replace it.  How do I get this to stop, the cops have no interest in their faces, nor do I

    My 5th gen iPod touh was stolen a month ago.  I immediately removed that device from my account and yet today I looked at my photostream and there are tons of pics of these people on my photostream.  How do I get this to stop?!?

    Change your iCloud ID password: http://support.apple.com/kb/HT5624.  After doing so, go to Settings>iCloud, tap Delete Account, then sign back in with the new password.

  • How do I get more text options in photoshop??

    How do I get more text options in Photoshop?  I have the basic package, but I would like more script options.
    Thank you,
       Maureen

    I don't suppose you have a full CC subscription?  It comes with a feature called Typekit which I love. Along with an ever increasing range of top quality fonts, it has the best font manager I have used, and excellent search facility.
    The web is full of additional font sites like dafont
    http://www.dafont.com/
    Otherweise, Google is your friend
    If you want Text Effects then Google will help you out there as well

  • How can i get the all values from the Property file to Hashtable?

    how can i get the all values from the Property file to Hashtable?
    ok,consider my property file name is pro.PROPERTIES
    and it contain
    8326=sun developer
    4306=sun java developer
    3943=java developer
    how can i get the all keys & values from the pro.PROPERTIES to hashtable
    plz help guys..............

    The Properties class is already a subclass of Hashtable. So if you have a Properties object, you already have a Hashtable. So all you need to do is the first part of that:Properties props = new Properties();
    InputStream is = new FileInputStream("tivoli.properties");
    props.load(is);

  • When I login on my When I sign in to a site on my ipad using my email address as ID a short cut of my email address comes up. How can I get rid of it?

    When I sign in to a site on my iPad using my email address as ID a short cut of my email address comes up. How can I get rid of it?

    You can edit keyboard shortcuts in Settings>General>Keyboard>Shortcuts>Edit.

Maybe you are looking for