JTable used as a JList

I am using a JTable as a JList (because it displays two columns). Above the JTable is an entry field when the user selects an item in the list with the mouse it adds it the entry field, I use a ListSelectionlistener This is fine.
I then tested it using the keyboard. As I scroll down the list with the up/down cursor keys it adds each entry to the entry field. This is not what I was expecting I thought you would be able to scroll down the list and then press Enter/Space to select the record and add it to the list.
I could add a button that the user has to select after selecting from the list before it is added to the entry field, but that creates an extra uneccessary stepo for mouse users. And one of my design goals for this project was to minimize the number of steps needed to complete any task.
Does anybody know how to do what i want, or its it a bad idea ?

Tables don't support the concept of an ActionEvent when you press the enter key. You could use a JList with a custom renderer to display two columns:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class ListMultiColumn extends JFrame
     public ListMultiColumn()
          String[] tabs =
               "123456\tone",
               "2\ta really really long description goes here",
               "3\tthree",
               "41\tfour"
          JList list = new JList( tabs );
//          list.setCellRenderer( new TextAreaRenderer() );
          list.setCellRenderer( new TextPaneRenderer() );
          list.setSelectedIndex(2);
          getContentPane().add( list );
     public static void main(String[] args)
          JFrame frame = new ListMultiColumn();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.pack();
          frame.setVisible( true );
     **  Tabs are easier to use in a JTextArea, but not very flexible
     class TextAreaRenderer extends JTextArea implements ListCellRenderer
          public TextAreaRenderer()
               setBackground(Color.blue);
               setTabSize(10);
          public Component getListCellRendererComponent(JList list, Object value,
               int index, boolean isSelected, boolean cellHasFocus)
               System.out.println(getBackground());
               setText(value.toString());
               setBackground(isSelected ? list.getSelectionBackground() : null);
               setForeground(isSelected ? list.getSelectionForeground() : null);
               return this;
     **  Tabs are harder to use in a JTextPane, but much more flexible
     class TextPaneRenderer extends JTextPane implements ListCellRenderer
          private final int TAB_COLUMN = 10;
          public TextPaneRenderer()
               setMargin( new Insets(0, 0, 0, 0) );
               FontMetrics fm = getFontMetrics( getFont() );
               int width = fm.charWidth( 'w' ) * TAB_COLUMN;
               TabStop[] tabs = new TabStop[1];
               tabs[0] = new TabStop( width, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE );
               TabSet tabSet = new TabSet(tabs);
               SimpleAttributeSet attributes = new SimpleAttributeSet();
               StyleConstants.setTabSet(attributes, tabSet);
               getStyledDocument().setParagraphAttributes(0, 0, attributes, false);
          public Component getListCellRendererComponent(JList list, Object value,
               int index, boolean isSelected, boolean cellHasFocus)
               setText( value.toString() );
               setBackground(isSelected ? list.getSelectionBackground() : null);
               setForeground(isSelected ? list.getSelectionForeground() : null);
               return this;
}

Similar Messages

  • Deleting a row from a JTable using AbstractTableModel

    Hi,
    Can someone please help me on how should i go about deleting a row in a jtable using the AbstractTableModel. Here i know how to delete it by using vector as one of the elements in the table. But i want to know how to delete it using an Object[][] as the row field.
    Thanks for the help

    Hi,
    I'm in desperate position for this please help

  • Sorting Columns in JTable Using Different Comparators

    Is there any way to sort each column in a JTable using different comparators?

    you'll have to write your own tableSorter

  • Updating a JTable using a JTable

    I am looking to update an empty JTable using the data from a JTable containing a set of data.
    I am aware that addRow can be used with the DefaultTableModel from previous discussions on this forum, but I have found this call isn't available when using AbstractTableModel.
    The reason I have been having some problems with this as it is necessary for the AbstractTableModel to be used in the context of the GUI, and I am asking if there is a way to solve this using the AbstractTableModel?
    I am using an AbstractTableModel for both the data table and the table showing all currently and previously selected rows.

    I am using an AbstractTableModel for both the data table and the table showing all currently and previously selected rows.No you aren't. You can't create an Abstract class because not all the methods are implements. You are using a class that extends AbstractTableModel.
    So why not use the DefaultTableModel and make your life simple?

  • Stopping cell editing in a JTable using a JComboBox editor w/ AutoComplete

    Hi there! Me again with more questions!
    I'm trying to figure out the finer parts of JTable navigation and editing controls. It's getting a bit confusing. The main problem I'm trying to solve is how to make a JTable using a combo box editor stop editing by hitting the 'enter' key in the same fashion as a JTextField editor. This is no regular DefaultCellEditor though -- it's one that uses the SwingX AutoCompleteDecorator. I have an SSCCE that demonstrates the issue:
    import java.awt.Component;
    import java.awt.EventQueue;
    import javax.swing.AbstractCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JTable;
    import javax.swing.WindowConstants;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellEditor;
    import javax.swing.table.TableModel;
    import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
    public class AutoCompleteCellEditorTest extends JFrame {
      public AutoCompleteCellEditorTest() {
        JTable table = new JTable();
        Object[] items = {"A", "B", "C", "D"};
        TableModel tableModel = new DefaultTableModel(2, 2);
        table.setModel(tableModel);
        table.getColumnModel().getColumn(0).setCellEditor(new ComboCellEditor(items));
        getContentPane().add(table);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        pack();
      private class ComboCellEditor extends AbstractCellEditor implements TableCellEditor {
        private JComboBox comboBox;
        public ComboCellEditor(Object[] items) {
          this.comboBox = new JComboBox(items);
          AutoCompleteDecorator.decorate(this.comboBox);
        public Object getCellEditorValue() {
          return this.comboBox.getSelectedItem();
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
          comboBox.setSelectedItem(value);
          return comboBox;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          public void run() {
            new AutoCompleteCellEditorTest().setVisible(true);
    }Problem 1: Starting to 'type' into the AutoCompleteDecorate combo box doesn't cause it to start editing. You have to hit F2, it would appear. I've also noticed this behaviour with other JComboBox editors. Ideally that would be fixed too. Not sure how to do this one.
    Problem 2: After editing has started (say, with the F2 key), you may start typing. If you type one of A, B, C, or D, the item appears. That's all good. Then you try to 'complete' the edit by hitting the 'enter' key... and nothing happens. The 'tab' key works, but it puts you to the next cell. I would like to make the 'enter' key stop editing, and stay in the current cell.
    I found some stuff online suggesting you take the input map of the table and set the Enter key so that it does the same thing as tab. Even though that's not exactly what I desired (I wanted the same cell to be active), it didn't work anyway.
    I also tried setting a property on the JComboBox that says that it's a table cell editor combo box (just like the DefaultCellEditor), but that didn't work either. I think the reason that fails is because the AutoCompleteDecorator sets isEditable to true, and that seems to stop the enter key from doing anything.
    After tracing endless paths through processKeyBindings calls, I'm not sure I'm any closer to a solution. I feel like this should be a fairly straightforward thing but I'm having a fair amount of difficulty with it.
    Thanks for any direction you can provide!

    Hi Jeanette,
    Thanks for your advice. I looked again at the DefaultCellEditor. You are correct that I am not firing messages for fireEditingStopped() and fireEditingCancelled(). Initially I had copied the behaviour from DefaultCellEditor but had trimmed it out. I assumed that since I was extending AbstractCellEditor and it has them implemented correctly that I was OK. But I guess that's not the case! The problem I'm having with implementing the Enter key stopping the editing is that:
    1) The DefaultCellEditor stops cell editing on any actionPerformed. Based on my tests, actionPerformed gets called whenever a single key gets pressed. I don't want to end the editing on the AutoCompleteDecorated box immediately -- I'd like to wait until the user is happy with his or her selection and has hit 'Enter' before ending cell editing. Thus, ending cell editing within the actionPerformed listener on the JComboBox (or JXComboBox, as I've made it now) will not work. As soon as you type a single key, if it is valid, the editing ends immediately.
    2) I tried to add a key listener to the combo box to pick up on the 'Enter' key and end the editing there. However, it appears that the combo box does not receive the key strokes. I guess they're going to the AutoCompleteDecorator and being consumed there so the combo box does not receive them. If I could pick up on the 'Enter' key there, then that would work too.
    I did more reading about input maps and action maps last night. Although informative, I'm not sure how far it got me with this problem because if the text field in the AutoCompleteDecorator takes the keystroke, I'm not sure how I'm going to find out about it in the combo box.
    By the way, when you said 'They are fixed... in a recent version of SwingX', does that mean 1.6.2? That's what I'm using.
    Thanks!
    P.S. - Maybe I should create a new question for this? I wanted to mark your answer as helpful but I already closed the thread by marking the answer to the first part as correct. Sorry!
    Edited by: aardvarkk on Jan 27, 2011 7:41 AM - Added SwingX versioning question.

  • Is it posiible to paging up paging down in Jtable using Default Table Model

    Hi All!
    Is it possible to do Page up and Page down in JTable using Default Tble Model?
    Kindly reply!

    yes
    it is posiible to paging up paging down in Jtable using Default Table Model. just go thru the JAVA API you will get the results.

  • Displaying JTable using GridBagLayout

    Hii Javaties
    I am displaying all my GUI using GridBagLayout Manager.
    But i dont know , how to add a JTable using GridBagLayout manager.
    I[b] want tht each column of the JTable be displayed in each cell .
    i.e column 1 should be displayed at position 1,4
    Can anybody guide me .
    Thanx

    Perhaps what you are looking for is Custom Editors or Renderers?

  • Sorting JTable using keyboard

    Hi all,
    Is it possible to sort JTable using keyboard? There is a key to get the focus to a column header by clicking the key F8. I don't find any key to sort the table based on the column which is in focus. Is there any solution for this?
    Thanks,
    Ganesh

    You miss the point of that link, there is no need to write any custom code.
    I have already tried to implement Keyboard listener of JTableHeader which must be similar to using Key Bindings.You should NOT use a KeyListener, Swing was designed to use KeyBindings
    The problem I am facing is that I am unable to find the column which got the key strokeYou don't have to write any code, the functionality you want is already supported with a Key Binding. Just use the "space" key.
    If you don't like the space key, then you can assign the Action to any other KeyStroke. The link shows you how to do that in 3-4 lines of code.

  • StackOverflowError in JTable using DefaultTableModel

    Hi:
    I have a JTable using DefaultTableModel. I also have a tableChanged function that puts values into columns based on values from other columns. Initially, I set up the table with one row, then a popup will call the addRow function on DefaultTableModel. Here's my addRow function:
    private void addRow() {
    try {
    String [] newString = new String[10];
    for (int i=0; i<10; i++)
    newString[i] = "";
    defaultTableModel.addRow(newString);
    } catch (java.lang.StackOverflowError seiou){
    As you can see from my catch statement, I keep getting a problem with a StackOverflowError when I enter values into the table; when I add a row, it kicks me out of the program. I am currently changing and checking values in the table with:
    defaultTableModel.setValueAt(); and
    defaultTableModel.getValueAt();
    Any suggestions?

    Hi:
    I have a JTable using DefaultTableModel. I also have a tableChanged function that puts values into columns based on values from other columns. Initially, I set up the table with one row, then a popup will call the addRow function on DefaultTableModel. Here's my addRow function:
    private void addRow() {
    try {
    String [] newString = new String[10];
    for (int i=0; i<10; i++)
    newString[i] = "";
    defaultTableModel.addRow(newString);
    } catch (java.lang.StackOverflowError seiou){
    As you can see from my catch statement, I keep getting a problem with a StackOverflowError when I enter values into the table; when I add a row, it kicks me out of the program. I am currently changing and checking values in the table with:
    defaultTableModel.setValueAt(); and
    defaultTableModel.getValueAt();
    Any suggestions?

  • How to assign values to JTable using mysql database

    how to assign value to JTable using mysql...

    Search the forum. You use the values of the "ResultSet" to create a "DefaultTableModel" which you then add to the "JTable".
    I'll let you pick the search keywords to use, which I've suggested above. You can also throw in my userid if you want to specifically look for my solution.

  • Can JTable cell acts as JList?

    I was planning to create an Event Calendar view in Monthly. Currently my jTable cell extends JTextArea. My problem is that, for example, today I got 2 events display in one cell, when a user double-click the "today" cell, an edit form will pop out, if there are 2 events in one cell, how I know which events to be edit? In this case I was thinking to use JList instaed of jTextArea. so i can choose which event to be edit. Is there any example showing how to implement jTable with jList cell? or is there any other method to overcome it?

    I haven't used a JList in a JTable so far, but for a JComboBox you find a working example in the tutorial. That may give you some ideas.
    What I did use is a (read only) JTable in a JTable. So if you don't achieve your goal with JList there are alternatives.
    But wait for our table specialists to come along.

  • Headache: Data Xchange from JDialog to JTable using JButton

    My head is spinning about how to get this to work. What is really confusing me is the data exchange from the JDialog.
    I have a JTable where one of the columns uses a JButton as the cell editor for each cell in that column. That part seems to be no problem. The JButton is labeled "Define Staff..."
    When the user clicks on the JButton, a JDialog containing a JList is to appear. If the user clicks cancel, the JDialog is disposed and nothing happens. If the user clicks OK, the selected items are to be returned to the cell in some way and the label of the JButton is to change to "Modify Staff..."
    How can I return the list from the JDialog to the "cell" so that when I access the cell using getValueAt() I get the list of values, and not the JButton object?

    Thanks.
    The actual JButton is inside a JTable cell though.
    Where would I add the event handler for the button? In the editor? In the renderer?
    Excerpt from the JTable file:
         PositionTable.getColumn("Staff").setCellRenderer(new ButtonRenderer());
         PositionTable.getColumn("Staff").setCellEditor(new ButtonEditor(new JCheckBox()));ButtonEditor.java
    public class ButtonEditor extends DefaultCellEditor {
      protected JButton button;
      private String    label;
      private boolean   isPushed;
      public ButtonEditor(JCheckBox checkBox) {
        super(checkBox);
        button = new JButton();
        button.setOpaque(true);
        button.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fireEditingStopped();
      public Component getTableCellEditorComponent(JTable table, Object value,
                       boolean isSelected, int row, int column) {
        if (isSelected) {
        } else{
          button.setForeground(table.getForeground());
          button.setBackground(table.getBackground());
        label = (value ==null) ? "" : value.toString();
        isPushed = true;
        return button;
      public Vector<String> getCellEditorValue() {
        Vector<String> staff = new Vector<String>();
        if (isPushed)  {
          staffSelector temp = new staffSelector(null,true,"Building Supervisor");
          temp.setVisible(true);
          staff = temp.getSelectedStaff(true);
        isPushed = false;
       // return new String( label ) ;
       //Return vector people selected.
       return staff;
      public boolean stopCellEditing() {
        isPushed = false;
        return super.stopCellEditing();
      protected void fireEditingStopped() {
        super.fireEditingStopped();
    }ButtonRenderer.java
    public class ButtonRenderer extends JButton implements TableCellRenderer {
      public ButtonRenderer() {
        setOpaque(true);
      public Component getTableCellRendererComponent(JTable table, Object value,
                       boolean isSelected, boolean hasFocus, int row, int column) {
        if (isSelected) {
          setForeground(table.getForeground());
          setBackground(table.getBackground());
        } else{
          setForeground(table.getForeground());
          setBackground(UIManager.getColor("Button.background"));
        setText( (value ==null) ? "Define Staff..." : "Modify Staff..." );
        return this;
    }Message was edited by:
    AsymptoticCoder
    Made an error.

  • Deleting a row from a JTable using a custom TableModel

    Before I waste any of your time I would like to go ahead and just say that I have searched through the forum using "delete row from Jtable" as the search keywords and while I have found very closely related issues, they have not solved my problem. I have found code postings by carmickr and his arguments as to why we should use DefaultTableModel instead of having created our own custom TableModel, and while I do agree, I just am not quite confident enough in applying it to my scenario. See I am reading from a file a bunch of Contractor objects and I am stuffing it into an arraylist which I am using in the following code posting to populate my TableModel which the JTable object in the gui then uses.
    My problem is that everything works except when I delete and when I delete I understand that the index is changing because I just removed a row from the arraylist object. Suppose I have 33 rows displaying in the GUI. Now after I delete say row #23, the delete function works and dutifuly the row disappears from the table, but if I try to delete a row say...the last row, it does not work and throws me an IndexOutOfBoundsException which totally makes sense. My question is how do I go about fixing it? Do I have to do something with the setRowCount method?
    Any help is appreciated.
    Cheers,
    Surya
    * ContractorTableModel.java
    * Created on January 12, 2006, 11:59 PM
    package code.suncertify.gui;
    import java.util.ArrayList;
    import java.util.logging.Logger;
    import javax.swing.table.AbstractTableModel;
    import code.suncertify.db.Contractor;
    * @author Surya De
    * @version 1.0
    public class ContractorTableModel extends AbstractTableModel {
         * The Logger instance. All log messages from this class are routed through
         * this member. The Logger namespace is <code>sampleproject.gui</code>.
        private Logger log = Logger.getLogger("code.gui");
         * An array of <code>String</code> objects representing the table headers.
        private String [] headerNames = {"Record Number", "Contractor Name",
        "Location", "Specialties","Size", "Rate",
        "Owner"};
         * Holds all Contractor instances displayed in the main table.
        private ArrayList <Object> contractorRecords = new ArrayList<Object>(5);
         * Returns the column count of the table.
         * @return An integer indicating the number or columns in the table.
        public int getColumnCount() {
            return this.headerNames.length;
         * Returns the number of rows in the table.
         * @return An integer indicating the number of rows in the table.
        public int getRowCount() {
            return this.contractorRecords.size();
         * Gets a value from a specified index in the table.
         * @param row An integer representing the row index.
         * @param column An integer representing the column index.
         * @return The object located at the specified row and column.
        public Object getValueAt(int row, int column) {
            Object [] temp = (Object[]) this.contractorRecords.get(row);
            return temp[column];
         * Sets the cell value at a specified index.
         * @param obj The object that is placed in the table cell.
         * @param row The row index.
         * @param column The column index.
        public void setValueAt(Object obj, int row, int column) {
            Object [] temp = (Object []) this.contractorRecords.get(row);
            temp [column] = obj;
         * Returns the name of a column at a given column index.
         * @param column The specified column index.
         * @return A String containing the column name.
        public String getColumnName(int column) {
            return headerNames[column];
         * Given a row and column index, indicates if a table cell can be edited.
         * @param row Specified row index.
         * @param column Specified column index.
         * @return A boolean indicating if a cell is editable.
        public boolean isCellEditable(int row, int column) {
            return false;
         * Adds a row of Contractor data to the table.
         * @param specialty
         * @param recNo The record number of the row in question.
         * @param name The name of the contractor.
         * @param location Where the contractor is located
         * @param size Number of workers for the contractor
         * @param rate The contractor specific charge rate
         * @param owner Name of owner
        public void addContractorRecord(int recNo, String name,
                String location, String specialty,
                int size, float rate, String owner) {
            Object [] temp = {new Integer(recNo), name,
            location, specialty, new Integer(size),
            new Float(rate), owner};
            this.contractorRecords.add(temp);
            fireTableDataChanged();
         * Adds a Contractor object to the table.
         * @param contractor The Contractor object to add to the table.
        public void addContractorRecord(Contractor contractor) {
            Object [] temp = {new Integer(contractor.getRecordNumber()),
            contractor.getName(), contractor.getLocation(),
            contractor.getSpecialties(), new Integer(contractor.getSize()),
            new Float(contractor.getRate()), contractor.getCustomerID()};
            this.contractorRecords.add(temp);
            fireTableDataChanged();
         * Deletes a row of Contractor data to the table.
         * @FIXME Now that I deleted a row then I will have to reset the internal structure so that I can delete again
         * @param recNo The record number of the row in question.
        public void deleteContractorRecord(int recNo) {
            contractorRecords.remove(recNo - 1);
            fireTableRowsDeleted(recNo -1, recNo - 1);
    }

    Wow that was a very quick response. Thanks camickr. I am only trying to delete a single row. I do not know how to go about posting a test program for the code I have posted above because honestly the gui itself is 800 lines of code, and then the file reading class is quite funky in itself. I can maybe email you the entire Netbeans project including code so if you are using Netbeans 5 RC2 you can run the code and see for yourself, but that would not be considerate of me.
    See I am trying to delete any row at any time...but only one at a time not multiple rows...so if a user decides to delete row 23 and then tries to delete the last row which happens to be row 33 in my case, my setup should be smart enough to still allow to delete the row.

  • Problem in calling a Panel while calling a cell in a JTable using Mouse.

    Hai there
    I am working in swing and trying to create an application that is displaying data using Table. Now, I have a requirement where in upon click on one of the column in the table i wish to display a panel which contains JTable. I am unable to get this functionality. The same functionality is successfully handled if i call it from a text field instead of a cell in JTable.
    Can any one suggest what the error could be??

    What data are you wanting to display in the JPanel? You can have the setColumnSelectionAllowed() method to true and that will allow you to select a column. Then you can use the getSelectedColumn() method to get the column number, then get all the row data for that column using the getValueAt(int row, int column) method and load it into your JPanel anyway you choose.

  • Can't get Single selection to work in jtable using Netbeans

    I used the GUI editor to create a jTable to play around and I can't get the single selection to work as it should
    I have it set like this:
    jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);The table still selection the rows as if they were set as Multi Interval selection. Anyone could explain why?
    Here is the full source
    To change this template, choose Tools | Templates
    *and open the template in the editor.*
    Tableframe.java
    Created on Jun 7, 2009, 6:57:57 PM
    *package examples;*
    @author ME
    *public class Tableframe extends javax.swing.JFrame {*
    *    /** Creates new form Tableframe */*
    *    public Tableframe() {*
    *        initComponents();*
    *    /** This method is called from within the constructor to
    *initialize the form.*
    WARNING: Do NOT modify this code. The content of this method is
    *always regenerated by the Form Editor.*
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4"
            jTable1.setOpaque(false);
            jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
            jTable1.setShowHorizontalLines(false);
            jTable1.setShowVerticalLines(false);
            jTable1.getTableHeader().setReorderingAllowed(false);
            jScrollPane1.setViewportView(jTable1);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(13, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(25, Short.MAX_VALUE))
            pack();
        }// </editor-fold>
    *@param args the command line arguments*
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Tableframe().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        // End of variables declaration
    }

    I used the GUI editor to create a jTable to play around and I can't get the single selection to work as it should
    I have it set like this:
    jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);The table still selection the rows as if they were set as Multi Interval selection. Anyone could explain why?
    Here is the full source
    To change this template, choose Tools | Templates
    *and open the template in the editor.*
    Tableframe.java
    Created on Jun 7, 2009, 6:57:57 PM
    *package examples;*
    @author ME
    *public class Tableframe extends javax.swing.JFrame {*
    *    /** Creates new form Tableframe */*
    *    public Tableframe() {*
    *        initComponents();*
    *    /** This method is called from within the constructor to
    *initialize the form.*
    WARNING: Do NOT modify this code. The content of this method is
    *always regenerated by the Form Editor.*
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4"
            jTable1.setOpaque(false);
            jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
            jTable1.setShowHorizontalLines(false);
            jTable1.setShowVerticalLines(false);
            jTable1.getTableHeader().setReorderingAllowed(false);
            jScrollPane1.setViewportView(jTable1);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(13, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(25, Short.MAX_VALUE))
            pack();
        }// </editor-fold>
    *@param args the command line arguments*
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Tableframe().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        // End of variables declaration
    }

Maybe you are looking for

  • Accessing a public method from javascript in an applet!!!

    Hi!! I'm have an applet (named say applet.class) in an html page that has a public method like this.... public void doShowFrame()           Frame frame = new frame();      frame.setVisible (true); What I want to do is to call that method with javascr

  • My mail is not updating in notification center, I cant receive the mail in notification center, help?

    Hi, I recently purchased a copy of Mac OS X Mountain Lion, after playing around with notification center I realized that if I get new mail I have to open my mail in the application so that it can appear in the notification center, why cant it just ap

  • Please chek my modify code.

    Hi all My code for modifying the rows in my internal table is not working. **MODIFY STATEMENT *wa_scarr-carrid = 'RG1'. *wa_scarr-carrname = 'RG Airlines1'. *loop at it_scarr into wa_scarr. *wa_scarr-currcode = 'USD'. *modify it_scarr index 3 from wa

  • Data Refresh on .swf file without Xcelsius installation.

    Hi This is the case: I have made a dashboard for my Boss with Xcelsius 2008. He was impressed. I put the .swf and the .xls files in a folder on his pc's desctop. Now he wants to be able to refresh the .swf on demand with a button or something else, w

  • No Notes mailbox icon in Mail

    I have an icon for creating Notes, but none for the storage and retrieval of Notes (or to-do list, for that matter). How do I get an icon and where does it belong? Thanks, peggy