JTable problem.  Two JTables sharing one Selection Listener.

So heres my problem. Any help would be much appreciated.
I have two JTables each displayed inside a JSplitPane. If table A has a row selected and the user selects a row from table B, I want table A to become deselected. I want the two tables to act as one. Only one rwo from either of the tables can be selected at a time.
I currently have two different table models for the tables but the data is coming from the same source. It is just grouped into two categories so I divided them up into two different tables in a splitpane. Thanks for your help.

Hi,
You have to use the clearSelection() m�thode on the ListSelectionModel of your JTable
tableA.addMouseListener(new MouseAdapter(){
          public void mouseClicked(MouseEvent e_) {                    
               tableB.getSelectionModel().clearSelection();
});

Similar Messages

  • Why ListSelectionListener receives two ListSelectionEvent at one selection?

    I use ListSelectionListener to listen the selection of a JList to perform other task related with the selected item in the list. but the following code exucuted twice at one selection:
        public void valueChanged(ListSelectionEvent e) {
             System.out.println(tablelist.getSelectedIndex());
        }the printed result is two of the same index.
    Anyone has a good solution about it? Thanks

    There are really two events. The first is where the
    currently selected item becomes deselected, and the
    second is where the newly selected item becomes
    selected.
    Check out the getValueIsAdjusting() method of
    ListSelectionEvent.If it's so, the first tablelist.getSelectedIndex()
    and the second tablelist.getSelectedIndex() may get
    different result. but why they get the same result?The first event is fired with valueIsAdjusting true and it is fired on mousePressed.
    When you release the mouse button the second event will be fired this time with valueIsAdjusting false.

  • Jtable problem in changing the row selected

    hi,
    I am displaying the oracle database information in JTable...user can make changes to a row...once he presses either ENTER,UP OR DOWN ARROW...the changes should be updated into the database...if there is some SQL exception,i am displaying JOptionPane to show the exception message ...i need to keep the selected row to be the one with errors...
    my problems are:
    i have written a function to update the change to the database...
    when should i call that...right now i am calling that in tableChanged method... is there any method to dissable the predefined keys and actions? becaz once user makes changes to a row and presses some key like up/down or enter,the control is getting transfered to the next row...
    plz give me the solution...
    here is part of my code....
    I am adding data later....
         model= new DefaultTableModel((Vector)null,columnNames);
         table = new JTable(model)
         public void tableChanged(TableModelEvent e)
              int firstRow = e.getFirstRow();
         if (e.getType()==TableModelEvent.UPDATE &&(firstRow!=TableModelEvent.HEADER_ROW))
              updateChangesToDatabase(row);
    /********in my update method i am setting the focus to the same row
    if i get exception....like this....
    JOptionPane.showMessageDialog (thisPanel,sb,"Error in UPDATING...",JOptionPane.ERROR_MESSAGE);
    table.requestFocusInWindow();
    table.setRowSelectionInterval(currentRow,currentRow);
         super.tableChanged(e);
              setUpTableData(); // method to add data...to table..
              table.setDragEnabled(false);
              table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              JScrollPane scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
              add(scrollPane,BorderLayout.CENTER);
    // this i am doing to reset keyboard action but not working....
              table.resetKeyboardActions();

    ye rammohan,
    you can change the data-element of the field or char of the data-element.
    if you try to change the name of the field, it deletes.
    so what you can do is, keep the field unchanged, add another field of your choice, using ABAP program, move the data from old field to new field, and then you can delete your old field.
    thx
    rams

  • Two iphones sharing one icloud with one Apple ID

    I know this type of question has been posted in the past but i couldn't find a specific answer for my situation.
    My wife and i share one Apple ID (AID), but we are wanting to have seperate ID's, we currently share one iCloud and have iTunes on a PC.
    I accept that i will have to download a load of Apps again onto her iphone but there weren't that many that we had to pay for most were free - so that point isn't really an issue.
    What i do want to do is back up her phone to include contacts, photos, etc to the current single icloud account. Her phone has been backed up to iTunes in the past but not iCloud.
    Is this something that can be done whilst still keeping both sets of Contacts, Photos etc seperate.
    Once it is backed up i'm going to create restore the phone and create a new AID and restore the Contacts etc from the original iCloud account - again is this the right way of doing this.
    Then finally i'll have to re-install the Apps, but hey ho at least once it's done its done.
    Any advice of guidance would be very much appreciated.

    You do not have to go through all that. You can keep your "itunes store" id the same and it will allow you to share apps, music etc. All you need to do is on your wife's phone delete (YOUR) icloud account. Even better if she didn't sign in yet. WHEN you delete that account you will see prompts that will ask you what do you want to keep on the phone and delete from the phone- choose accordingly. Once you out of your account, just sign in by creating new apple id for your wife. It is going to be new, her own icloud appleid.
    All of that has to be done on her phone in settings- icloud.
    And in Settings - itunes and app store you will share your old id, by that sharing apps and the stuff that you buy from store. You can also use her own id in facetime and imessage, allowing you guys to facetime each other, but you probably already do with phone numbers - so those changes are not necessary, unless you have problem now.

  • Two people sharing one iMac with two Apple ID's software and app download question

    I'm new to Apple computers finally had enough with Dell.  I share the iMac with another person so we have our separate ID's.  Is it possible to download software from the App Store once and use it between two people? I noticed when we updated Apps last night it didn't carry over to the second person.  Thank you in advance.

    Setup another user account on your Mac. You use your Apple ID on your account and the other person on theirs.
    Open System Preferences > Users & Groups then select the Password tab.
    Click the gold padlock icon bottom left corner of the window. You will be prompted for your admin password.
    Now click + to create a new acocunt.
    Select:  Show fast user switching menu as and make a selection.
    You should see an account name top right corner of your screen. From there you can switch accounts.

  • Can i have two devices sharing one itunes account

    i currently have my iphone synced with my itunes account, i have just bought a ipod and want it to share the same itunes account, library etc, how do i do this without wiping it off my phone when ading the new ipod ??

    This won't be a problem, iTunes will see the new device as a separate device, it will have its own settings under iTunes, you can set it up to sync the same content or different content to the first device, it will have no effect on how the first device syncs with iTunes.

  • I have two phones sharing one icloud account. How do I keep the phones for sharing stock application information?

    I have two iphones and three macbook pros. Instead of using my ical server to sync my calendar I am now using icloud to sync the calendars. Since I implemented this the stocks on each phone which were different are now same when the phone syncs. How do I break the syncing between the iphone stock applications?

    Welcome to the Apple community.
    Ideally you should each have your own iCloud account, providing you with your own contacts, calendars etc, not doing so will result in exactly what you have experienced. The contacts have likely been lost due to the options you have chosen at the login stage on each device.
    Unless you have the missing contacts in a backup file, they won't be recoverable unfortunately. You can add them manually to the contracts that already exist and continue to share the iCloud account if you wish, but I suggest that you each have your own iCloud account.
    Note, you can each have your own iCloud account, but continue to share an iTunes account for purchases of apps, books, music, TV shows etc etc.

  • Two users sharing one email account?

    My son and I uses the same email address account to purchase music on a iMac . We bought a windows machine and he wants to use iTunes on windows with different account. How to separate the music on one machine?
    Thank you
    Luis

    I strongly suggest you get the whole profile in the same folder hierarchy before you even consider moving to windows 7.
    Windows XP has Program File
    Windows 7 has Program Files and Program Files (X86) your executable goes in the x86 one.
    XP has applications data
    Windows 7 has appdata
    In windows XP Thunderbird's profile is in application data in windows 7 it is in appdata/roaming
    If you open explorer the old locations appear to be there, but they will not work to locate Thunderbird's disparate parts of it's profile
    And so the list goes on. Hence none of the locations you know will probably exist under windows 7 so if parts of the profile are pointing to locations that have changed, only grief awaits you.

  • Xorg.conf doesn't keep configuration of two screens sharing one corner

    I explained my situation in this thread.
    Trilby recommended do set up the screens like this (thanks!):
    +---------------------------+
    | |
    | |
    | |
    | |
    +---------------------------+
    +-----------------+
    | |
    | |
    | |
    +------------------+
    So using nvidia-settings (I know it's bad), I made this:
    Section "Screen"
    Identifier "Screen0"
    Device "Device0"
    Monitor "Monitor0"
    DefaultDepth 24
    Option "Stereo" "0"
    Option "nvidiaXineramaInfoOrder" "DFP-1"
    Option "metamodes" "DFP-0: 1366x768_60 +1920+1080, DFP-1: 1920x1080_60 +0+0"
    SubSection "Display"
    Depth 24
    EndSubSection
    EndSection
    After setting up everything in nvidia-settings and applying it, the monitors are in right position. The problem is that after a reboot, the smaller screen moves up, so it's not +1920+1080, but +1920+0.
    Can it be connected with this issue?

    ravicious wrote:but I really want to find a solution to this problem :C
    Doesn't mean that you muddy up the forum. Do some researching on the issue while waiting for someone to answer. Post what else you have tried which hasn't worked so others don't waste time giving you the same solution.

  • Two people sharing one iWeb-site and contributing?

    Is there any possiblities in iWeb for me and my brother to create an photoalbum with iWeb and share the same photoalbum from different .mac-accounts?
    Tip me of other solutions if not possible Thnx.

    Not easily without some extra messing around with files behind the scenes.
    Have you tried flickr? http://www.flickr.com Many people swear by this site and, since it's internet based instead of being based on a file in your computer, you can place photos there from multiple users logging into the same account.

  • Essential problem with JTable Selections?

    As far as I noticed a JTable actually consists of multiple Lists.
    For example; If I want to navigate horizontal and vertical (diagnal) from one cell to another I have to use two ListSelectionListeners.
    One ListSelectionListener to determine row-selection changes and the second ListSelectionListener to determine column-selection changes.
    table.getSelectionModel().addListSelectionListener(listener);
    table.getColumnModel().getSelectionModel().addListSelectionListener(listener);Due to this way the valueChanged(ListSelectionEvent e) method defined by the ListSelectionListener interface is called two times when navigating in two directions and called once when navigating in one dimension.
    Can this problem easily be solved or is this an idea for improvement?
    P.S. I don't need the solving of this issue to help me progress with my current dev. It's just something that cracks my mind at four o'clock in the night.

    You're completly right. I did not formulate the question good enough (ahh well.. my first post). What I meant was the detection of selection events, by a mouse click for example.
    The JTable.changeSelection(row, column, toggle, extend) is used to programmatically change the selection itself. In matter of fact, I believe the mouse and/or keyboard actions even use this method to peform their tasks when clicking on a cell.
    In my case, the row and column index of the cell being clicked have to be passed when a user clicks it in the Jtable.
    I've made a JFrame program that shows an image when a cell is clicked. When the cell that is being clicked is in the same row or in the the same column as the previous selected cell, the picture is loaded once. When the newly clicked cell is in a different row and in a different column, the picture is loaded twice.
    I've made an executable. I would like to post it, but I don't know whether that is common in this community.
    Code in DistanceFinder which extends JFrame:
    MySelectionListener listener = new MySelectionListener(cityTable, imageLabel);
            cityTable.getSelectionModel().addListSelectionListener(listener);
            cityTable.getColumnModel().getSelectionModel()
                .addListSelectionListener(listener);
    MySelectionListener:
    package gui;
    import gui.MyLabel;
    import java.awt.Toolkit;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTable;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    * @author Iwan
    public class MySelectionListener implements ListSelectionListener {
         private JTable jtable;
         private MyLabel imageLabel;
         public MySelectionListener(JTable jtable, MyLabel imageLabel) {
              // TODO Auto-generated constructor stub
              this.jtable = jtable;
              this.imageLabel = imageLabel;
         /* (non-Javadoc)
          * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
         @Override
         public void valueChanged(ListSelectionEvent e) {
              // If cell selection is enabled, both row and column change events are fired
            if ((e.getSource() == jtable.getSelectionModel() || e.getSource() == jtable.getColumnModel().getSelectionModel())
                      && !e.getValueIsAdjusting()
                      && jtable.getSelectedColumn() != jtable.getSelectedRow()
                      && jtable.getSelectedColumn() != 0
                      && jtable.getSelectedRow() != 0 ){
                 imageLabel.setImage(getSelectedCell(jtable));
         private int[] getSelectedCell(JTable jtable){
              int[] selectedCell = {jtable.getSelectedColumn(), jtable.getSelectedRow()};
              return selectedCell;
         private void showInfoBox(JTable jtable, ListSelectionEvent e){
              JOptionPane.showMessageDialog(null, "Row changed to: " + jtable.getSelectedRow()
                        + "\n Column changed to: " + jtable.getSelectedColumn()
                        + "\nFirst: " + e.getFirstIndex()
                        + "\nLast: " + e.getLastIndex());
    }So the question remains:
    The valueChanged(ListSelectionEvent e) method defined by the ListSelectionListener interface is called two times when navigating in two directions and called once when navigating in one dimension.
    Can this problem easily be solved or is this an idea for improvement?

  • Selection Problem with JTable

    Hello,
    i have a selection problem with JTable. I want to allow only single cell selection and additionally limit the selection to the first column.
    I preffered the style from MS Outlook Express where you can select the email accounts to edit.
    It is a table like this:
    Account name  |   Type  |   ...
    --------------|---------|---------------------
    Hotmail       |   POP3  |
    GMX           |   IMAP  |The selection should be only avaibable at 'Hotmail' or 'GMX' - not at 'POP3', 'IMAP' or as complete row selection.
    Please help me!
    Thanks.
    Warlock

    Maybe this will helpimport java.awt.*;
    import javax.swing.*;
    public class Test3 extends JFrame {
      public Test3() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        String[] head = {"One", "Two"};
        String[][] data = {{"R1-C1", "R1-C2"}, {"R2-C1", "R2-C2"}};
        JTable jt = new JTable(data, head);
        jt.getColumnModel().setSelectionModel(new MyTableSelectionModel());
        content.add(new JScrollPane(jt), BorderLayout.CENTER);
        jt.setCellSelectionEnabled(true);
        jt.setRowSelectionAllowed(false);
        jt.setColumnSelectionAllowed(false);
        setSize(300, 300);
        setVisible(true);
      public static void main(String[] arghs) { new Test3(); }
    class MyTableSelectionModel extends DefaultListSelectionModel {
      public void setSelectionInterval(int index0, int index1) {
        super.setSelectionInterval(0, 0);
    }

  • Help Please, Problem in displaying same  JTables on two JPanels

    Problem in displaying same JTables on two JPanels. In an application, I have a dynamic display of JTables on one JPanel. After a print preview button action, I have to bring same JTables on another JPanels, while taking this the previous JPanels content(JTables) become invisible? Why this happened? may be single component. Is the Cloning process nedded?

    Hi,
    you can add a component to one container only. If you try to add it to a second container, it will be removed from the first.
    You could try holding one member of the TableModel and set that one to both tables.
    Greets,
    Christian

  • I have two Iphones with different email addresses sharing one Apple ID. Will that cause problems with using messaging and FaceTime?

    I have two Iphones 5 with different email addresses sharing one Apple ID account.Both are using IOS 8.
    I would like to set up a new Apple Id for one of the phones and remove it from the old account.
    If I do that, can I move all of the purchased apps and songs to the new Apple account?
    Also, will sharing one Apple ID account with two devices cause problems with using messaging and FaceTime?

    Sharing an iCloud account between two devices can be done without causing issues with iMessage and FaceTime, just go into Settings for each of these functions and designate separate points of contact (i.e. phone number only, or phone number and unique email address).  While that works, you'll then face the problem where a phone call to one iPhone will ring both if on the same Wi-Fi network -- but again, that can be avoided by changing each phone's settings.
    Rather than do all that, don't fight it -- use separate IDs for iCloud.  You can still use a common ID for iTunes purchases (the ID for purchases and iCloud do not have to be the same) or you can use Family Sharing to share purchases from a primary Apple account.

  • JTable problem (Tuff one)...

    I cannot get the headings to display in my jtable.
    Can someone please look at this code and tell me what I did wrong. Thanks :0)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.util.Calendar;
    import javax.swing.border.*;
    import java.util.*;
    import javax.swing.JTable;
    import javax.swing.JComponent;
    import java.lang.Object;
    import javax.swing.table.AbstractTableModel;
    public class FrameSelectClass extends JDialog {
    // For non-editable table
    MyTableModel myModel = new MyTableModel();
    JTable jTable1 = new JTable(myModel);
    JScrollPane jScrollPane1 = new JScrollPane(jTable1);
    JButton jButtonSelect = new JButton();
    JButton jButtonCancel = new JButton();
    public FrameSelectClass() {
    try {
    jbInit();
    jTable1.setSelectionMode(ListSelectionModel .SINGLE_SELECTION);
    catch(Exception e) {
    e.printStackTrace();
    class MyTableModel extends AbstractTableModel {
    Object [] columnNames = {"col1","col2","col3","col4","col5"};
    Object [][] data = {{"data1","data2","data3","data4","data5"}};
    public int getColumnCount() {
    return columnNames.length;}
    public int getRowCount() {
    return data.length;}
    public Object getValueAt(int row, int col) {
    return data [row][col];}
    public Class getColumnClass(int c) {
    return getValueAt(0,c).getClass();}
    public boolean isCellEditable(int row, int col) {
    return false;}
    public void setColumnNames(Object [] newColumnNames) {
    columnNames = newColumnNames;}
    public void setData(Object [][] newData) {
    data = newData;}
    public FrameSelectClass(Frame parent) {
    super(parent);
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    TableSetup();
    catch(Exception e) {
    e.printStackTrace();
    pack();
    private void jbInit() throws Exception {
    Object [][] data = {
    {"H1", "H12", "H1", "Art 12H", "HA"},
    {"H2", "H13", "H2", "Art 12H", "HA"},
    {"H3", "H14", "H3", "Art 12H", "HA"},
    {"H4", "H34", "H4", "Art 12H", "HA"},
    {"H5", "H55", "H5", "Art 12H", "HA"}
    Object[] columnNames = {" ", "Crs", "Sec", "Class", "Pd"};
    MyTableModel myModel = new MyTableModel();
    myModel.setColumnNames(columnNames);
    myModel.setData(data);
    JTable jTable1 = new JTable(myModel);
    JScrollPane jScrollPane1 = new JScrollPane(jTable1);
    jButtonSelect.setNextFocusableComponent(jButtonCancel);
    jButtonSelect.setText("Select");
    jButtonSelect.setBounds(new Rectangle(48, 257, 113, 34));
    this.getContentPane().setLayout(null);
    jButtonCancel.setNextFocusableComponent(jTable1);
    jButtonCancel.setText("Cancel");
    jButtonCancel.setBounds(new Rectangle(262, 257, 103, 35));
    jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButtonCancel_actionPerformed(e);
    this.setDefaultCloseOperation(3);
    jScrollPane1.setForeground(Color.white);
    jScrollPane1.setBounds(new Rectangle(7, 8, 386, 246));
    jTable1.setBorder(BorderFactory.createRaisedBevelBorder());
    jTable1.setMaximumSize(new Dimension(500, 500));
    jTable1.setMinimumSize(new Dimension(75, 80));
    jTable1.setNextFocusableComponent(jButtonSelect);
    jTable1.setPreferredSize(new Dimension(375, 80));
    jTable1.setToolTipText("Select you class from the list.");
    jTable1.setTableHeader(null);
    this.getContentPane().add(jButtonSelect, null);
    this.getContentPane().add(jButtonCancel, null);
    this.getContentPane().add(jScrollPane1, null);
    jScrollPane1.getViewport().add(jTable1, null);
    //Cancel button | Close dialogue box
    void jButtonCancel_actionPerformed(ActionEvent e) {
    cancel();
    public void TableSetup(){ 
    }

    This line of codejTable1.setTableHeader(null);looks to me like it means "Don't display any headers."

Maybe you are looking for