Problem with JCheckBox in a JTable

Hello,
I have a JTable with JCheckBox as Editor for boolean values.
I added a ListSelectionListener on that JTable.
My problem is :
when I click on a cell which have a JCheckBoxEditor, there is only one event generated : the one which unselect the row previously selected.
So i can't answer the selection.
what could have append ?
thanks a lot.
fleur.

hi,
I have no custom editor for this table.
here is my code :
public VDEComposant(Locale langue,InterfaceModeleur listener,Composant composant,int largeur) {
super(langue,listener,largeur);
this.setLayout(new BorderLayout());
_modele=listener.getModele();
_composantCourant=composant;
this.addComposantsListener((ComposantsListener)listener.getGestionnaire());
construitBarreOutils();
setNbLigne1(this.listeComposant(composant).size());
int m=0;
if (composant==Composant.COMPOSANT){
_donCompPereApTM=this.creeModeleDonnee1(composant);
_donCompPereApTM.addTableModelListener(this);
setTableau1(new JTable(_donCompPereApTM));
m=1;
else{
if (composant.getPere()==Composant.COMPOSANT){
_donCompApTM=creeModeleDonnee1(composant);
_donCompApTM.addTableModelListener(this);
setTableau1(new JTable(_donCompApTM));
else {
_donCompUtTM=creeModeleDonnee1(composant);
_donCompUtTM.addTableModelListener(this);
setTableau1(new JTable(_donCompUtTM));
getTableau1().addMouseListener(((OngletDonnees)((OngletDonnees)getIHM().getOngletDonnees())).getOngletComposants());
MultipleComboBoxCellEditor editor = new MultipleComboBoxCellEditor(new JComboBox());
getTableau1().getColumnModel().getColumn(4+m).setCellEditor(editor) ;
getTableau1().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getTableau1().getSelectionModel().addListSelectionListener(this);
Dimension d1 = new Dimension(_largeur, getNbLigne1()*16);
JScrollPane sc1 = new JScrollPane(getTableau1());
sc1.setViewportView(getTableau1());
if((composant.getPere()!=null)&&(composant.getPere()!=Composant.COMPOSANT)){
this.add(_outils,BorderLayout.NORTH);
String s="";
if((composant.getPere()==null)||(composant.getPere()==Composant.COMPOSANT)){
String sc="";
if(composant==Composant.COMPOSANT_IMAGE){
sc=" "+_ressources.getString("images");
if(composant==Composant.COMPOSANT_LINEAIRE){
sc=" "+_ressources.getString("lineaires");
if(composant==Composant.COMPOSANT_METAD){
sc=" "+_ressources.getString("lotdonnees");
if(composant==Composant.COMPOSANT_NGS){
sc=" "+_ressources.getString("nongraphiques");
if(composant==Composant.COMPOSANT_SURFACIQUE){
sc=" "+_ressources.getString("surfaciques");
if(composant==Composant.COMPOSANT_SYMBOLIQUE){
sc=" "+_ressources.getString("symboliques");
s=_ressources.getString("liste_composant")+sc;
else{
s=_ressources.getString("description_composant");
JLabel lab = new JLabel(s,JLabel.CENTER);
JPanel inter = new JPanel(new GridLayout(1,1));
inter.add(lab);
inter.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),BorderFactory.createEtchedBorder()));
Box boite1 = Box.createVerticalBox();
boite1.add(inter);
boite1.add(sc1);
_inter.add(boite1);
//ajout du deuxieme tableau
_donAttCompTM=this.creeModeleDonnee2(composant);
_donAttCompTM.addTableModelListener(this);
setTableau2(new JTable(_donAttCompTM));
getTableau2().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getTableau2().getSelectionModel().addListSelectionListener(this);
getTableau2().addMouseListener(((OngletDonnees)((OngletDonnees)getIHM().getOngletDonnees())).getOngletComposants());
//ComboBox pour saisir le type de l'attribut
_typeA = new JComboBox();
_typeA.addItem(TypeEtendu.DATE.getNom());
_typeA.addItem(TypeEtendu.DOMAINE.getNom());
_typeA.addItem(TypePrimitif.ENTIER.getNom());
_typeA.addItem(TypePrimitif.LOGIQUE.getNom());
_typeA.addItem(TypePrimitif.REEL.getNom());
_typeA.addItem(TypePrimitif.TEXTE.getNom());
(getTableau2().getColumnModel().getColumn(3)).setCellEditor(new DefaultCellEditor(_typeA));;
//renderer pour la colonne des nom qui indique en gras l'attribut identifiant
getTableau2().getColumnModel().getColumn(1).setCellRenderer(new AttributTableCellRenderer(_composantCourant));
Dimension d2 = new Dimension(_largeur ,(getNbLigne2()*16));
JScrollPane sc2 = new JScrollPane(getTableau2());
sc2.setViewportView(getTableau2());
_inter.createVerticalStrut(16);
inter = new JPanel(new GridLayout(1,1));
lab = new JLabel(_ressources.getString("attributs"),JLabel.CENTER);
inter.add(lab);
inter.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),BorderFactory.createEtchedBorder()));
Box boite2=Box.createVerticalBox();
boite2.add(inter);
boite2.add(sc2);
_inter.add(boite2);
if((composant.getPere()!=null)&&(composant.getPere()!=Composant.COMPOSANT)){
this.add(_inter,BorderLayout.CENTER);
else{
this.add(_inter,BorderLayout.NORTH);
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm =(ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
else {
int ligneSel = lsm.getMinSelectionIndex();
if(e.getSource()==getTableau2().getSelectionModel()){
String alias = (String) _donAttCompTM.getValueAt(ligneSel,1);
attribut = composantCourant.getAttribut(alias);
else if(e.getSource()==getTableau1().getSelectionModel()){
VectorTableModel vtm = null;
int i = 0;
if(_donCompApTM != null){
vtm = _donCompApTM;
if(_donCompPereApTM != null){
vtm = _donCompPereApTM;
i =1;
if(vtm != null){
String alias = (String) vtm.getValueAt(ligneSel,i);
composantSelectionne= modele.getComposant(alias);
else{
composantSelectionne=composantCourant;
I hope it make sens,
thanks.

Similar Messages

  • Problem with the sorting of  JTable column

    Hi,
    I want to store the positions of the tablecolumns when my program closes and restore them when the program starts again. I store their column-index with their view positions.
    My problem comes when I want to restore them because I cant find a method to move the columns to their new position without compromising the ColumnModel() because then the you edit the model which with you are working with. See my example:
    for (int i = 0;i < getColumnModel().getColumnCount();i++)
    TableColumn tempColumn = getColumnModel().getColumn(i);
    //get it's position
    String position = (String) UserSettingsManager.getInstance().getItemFromMap(positionKey);
    if (position != null)
    getColumnModel().moveColumn(i, Integer.parseInt(position));
    How can I get a list of all the column without using getColumnModel().getColumn() .... or how do I fix this.
    Much thanks,
    Hugo

    See JTable's methods
    public int convertColumnIndexToView(int modelColumnIndex)
    public int convertColumnIndexToModel(int viewColumnIndex)
    for (int i = 0;i < getColumnModel().getColumnCount();i++)
    TableColumn tempColumn = getColumnModel().getColumn(i);
    //get it's position
    String position = (String) UserSettingsManager.getInstance().getItemFromMap(positionKey);
    if (position != null)
    int index=table.convertColumnIndexToView(i);
    getColumnModel().moveColumn(index, Integer.parseInt(position));
    best regards
    Stas

  • Problem with JPanel, JScroll and JTable

    Hi.
    On one of my Jframes, i have 3 Jpanels. There are two on one side, and one of the other which spans the height of the other two. However, it does more than span the height of the other two, it streches the height of the Jframe as it is about 300 pixels too heigh.
    I'm not sure which element is streching the JPanel, it might be either the Jpanel itself, the JScroll or the JTable. Theres alot of code, however i'm going to try and cut out the irrelevent parts.
    I call the Jpanel via:
    FarmList = new javax.swing.JPanel();
    FarmList.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Farm List", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11)));
    FarmList.add(new GetFarms());And the code for the GetFarms() class is:
    public class GetFarms extends JPanel {
         private final int COLUMNS = 4;
         private int ROWS = 2;
         private JTable sampleJTable;
         private String[][] cells = new String[ROWS][COLUMNS];
        public static void main(String[] args) throws Exception {
            JFrame frame = new JFrame("Covenant Farm List");
              frame.add(new GetFarms());
            frame.setSize(450,150);
            frame.setVisible(true);
         public GetFarms() throws Exception {
              URL theUrl = new URL("http://www.allydm.co.uk/Covenant/farm_list.php");
              BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        theUrl.openStream()));
              String inputLine = in.readLine();
              String[] lines = inputLine.split("<br>");
              for (int i = 0; i < ROWS; i++) {
                   String[] stuff = lines.split(" ");
                   for (int j = 0; j < COLUMNS; j++) {
                        cells[i][j] = stuff[j];
              in.close();
              String[] columnNames = {"Username", "DA", "Sentry", "Last Update"};
              sampleJTable = new JTable(cells, columnNames);
              JScrollPane tablePane = new JScrollPane(sampleJTable);
    add(tablePane, BorderLayout.CENTER);
    If anyone has any ideas, on how to limit the size of the Jpanel or JScroll it'd be greatly appreciated.

    did you implement setxxxSize() methods?
    see
    http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html

  • Problem with Jcheckbox

    Hi friends;
    I need a small help. I want to change the property of a button based on the checkbox selected or deselected value.
    My problem is :
    if checkbox is selected then disable the button else
    if checkbox is deselected then enable the button.
    if(createLoginCKB.setEnabled(true)
    button1.setEnabled(false)
    else
    button1.setEnabled(true)
    But i am getting an error in the first line saying cannot convert void to boolean.
    Please help
    thanks
    Ad

    Use the isSelected() method to check if your checkbox is selected:
        if( createLoginCKB.isSelected() )
        ...."How to Use Check Boxes":
    http://java.sun.com/docs/books/tutorial/uiswing/components/button.html#checkbox

  • Problem with Hiding Columns in JTable

    Hi.
    Who knows how to hide column in JTable.
    I try to get column:
    MyTab.getColumnModel().getColumn(i)But there is no methods like SetVisible(false)
    What to DO???

    http://www.google.com/search?hl=en&q=%2Bhide+%2Bcolumn+%2Bjtable&btnG=Google+Search

  • Problem with JTable and JPanel

    Hi,
    I'm having problems with a JTable in a JPanel. The code is basicly as follows:
    public class mainFrame extends JFrame
            public mainFrame()
                    //A menu is implemeted giving rise to the following actions:
                    public void actionPerformed(ActionEvent evt)
                            String arg = evt.getActionCommand();
                            if(arg.equals("Sit1"))
                            //cells, columnNames are initiated correctly
                            JTable table = new JTable(cells,columnNames);
                            JPanel holdingPanel = new JPanel();
                            holdingPanel.setLayout( new BorderLayout() );
                            JScrollPane scrollPane = new JScrollPane(holdingPanel);
                            holdingPanel.setBackground(Color.white);
                            holdingPanel.add(table,BorderLayout.CENTER);
                            add(scrollPane, "Center");
                            if(arg.equals("Sit2"))
                                    if(scrollPane !=null)
                                            remove(scrollPane);validate();System.out.println("ScrollPane");
                                    if(holdingPanel !=null)
                                            remove(holdingPanel);
                                    if(table !=null)
                                            remove(table);table.setVisible(false);System.out.println("table");
                            //Put other things on the holdingPanel....
            private JScrollPane scrollPane;
            private JPanel holdingPanel;
            private JTable table;
    }The problem is that the table isn't removed. When you choose another situation ( say Sit2), at first the table apparently is gone, but when you press with the mouse in the area it appeared earlier, it appears again. How do I succesfully remove the table from the panel? Removing the panel doesn't seem to be enough. Help is much appreciated...
    Best regards
    Schwartz

    If you reuse the panel and scroll pane throughout the application,
    instantiate them in the constructor, not in an often-called event
    handler. In the event handler, you only do add/remove of the table
    on to the panel. You can't remove the table from the container
    which does not directly contain it.
    if (arg.equals("Sit2")){
      holdingPanel.remove(table);
      holdingPanel.revalidate();
      holdingPanel.repaint(); //sometimes necessary
    }

  • Problem with fireTableDataChanged in JTable

    Hi everybody,
    i have a really frustrating problem with Jtable. I created a class to display the jtable and a class that extends AbstactTableModel to use as its model. I can update my table after a fireTableDataChanged method in the class that extend the AbstractTableModel, but after implementing a ListSelectionListener to the class that displays the jtable, it gives a big bunch of errors in the console of my ide, when i remove it, it went back to normal without any errors.
    Anyways, my program still can run without problem and the table still can refresh, just this bunch of errors when i clicked the button that calls the AbstactTableModel to perform a firetabledatachanged
    anybody got this problem? how did you guys solve it?
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
    at farm.EmployeesTblModel.getValueAt(EmployeesTblModel.java:58)
    at farm.EmployeesTblView.rowEditDelete(EmployeesTblView.java:131)
    at farm.EmployeesTblView$1.valueChanged(EmployeesTblView.java:106)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:147)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:194)
    at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:388)
    at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:398)
    at javax.swing.DefaultListSelectionModel.removeSelectionIntervalImpl(DefaultListSelectionModel.java:559)
    at javax.swing.DefaultListSelectionModel.clearSelection(DefaultListSelectionModel.java:403)
    at javax.swing.JTable.clearSelection(JTable.java:2040)
    at javax.swing.JTable.clearSelectionAndLeadAnchor(JTable.java:2048)
    at javax.swing.JTable.sortedTableChanged(JTable.java:4098)
    at javax.swing.JTable.tableChanged(JTable.java:4346)
    at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280)
    at javax.swing.table.AbstractTableModel.fireTableDataChanged(AbstractTableModel.java:182)
    at farm.EmployeesTblModel.updateData(EmployeesTblModel.java:42)
    at farm.EmployeesTblView.updateData(EmployeesTblView.java:59)
    at farm.EmployeesTbl.delete(EmployeesTbl.java:273)
    at farm.FarmView.delEmpBtnActionPerformed(FarmView.java:1823)
    at farm.FarmView.access$2200(FarmView.java:32)
    at farm.FarmView$18.actionPerformed(FarmView.java:823)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6038)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
    at java.awt.Component.processEvent(Component.java:5803)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

    just this bunch of errors when i clicked the button that calls the AbstactTableModel to perform a firetabledatachangedWell, you should never have a button that invokes fireTableDataChanged.
    The TableModel should be responsible for invoking those methods.
    I suggest you look at the code for the DefaultTableModel for the proper way to write a TableModel. Basically you create methods to update the model. The model in turn fires the events to notify the view to repaint itself.

  • Problem with setCursor for JButton in cell on JTable

    i have a problem with setCursor to JButton that is in a cell of the JTable}
    this is the code
    public class JButtonCellRenderer extends JButton implements TableCellRenderer {
    public JButtonCellRenderer() {
    setOpaque(true);
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    if (isSelected) {
    setForeground(table.getSelectionForeground());
    setBackground(table.getSelectionBackground());
    else {
    setForeground(table.getForeground());
    setBackground(Color.WHITE);
    setBorder(null);
    if(table.getValueAt(row,column) == null){
    setText("");
    if(isSelected){
    setBackground(table.getSelectionBackground());
    }else{
    setBackground(Color.WHITE);
    }else{
    if(table.getValueAt(row,column) instanceof JButton){
    JButton _button = (JButton)table.getValueAt(row,column);
    if(_button.getText().trim().equals("")){
    setText("<html>"+ "<font size=\"3\" COLOR=\"#0000FF\"><u><b>Ver...</b></u></font>"+"");
    }else{
    setText("<html>"+ "<font size=\"3\" COLOR=\"#0000FF\"><u><b>" + _button.getText() + "</b></u></font>"+"");
    return this;
    }

    Not quite sure I understand the problem, but I guess you have tried to call setCursor on your renderer and found it didn't work? The reason, I think, is that the renderer only renders a JButton. The thing that ends up in the table is in fact only a "picture" of a JButton, and among other things it won't receive and interact with any events, such as MouseEvents (so it wouldn't know that the cursor should change).
    There are at least two alternatives for you: You can perhaps use a CellEditor instead of a CellRenderer. Or you can add a MouseListener to the table and then use the methods column/rowAtPoint to figure out if the cursor is over your JButton cell and change the cursor yourself if it is.

  • 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);
    }

  • Problems with a JTable

    Hello folks,
    i got two problems with a JTable.
    1. how do I change the size of a table header???
    2. I know that it is possible to set different column-sizes. The problem in my table is that I don't know how long some cells are. In this case, I want to to get the biggest cell of one column and set its size as the default size of that specific column.
    Is that possilbe?
    Hopefully you can help me out,
    thank you

    A JTableHeader is just another Component, so you ought to be able to set its size like you would
    any other component; however, since its function is to act as a header for a table, it might constrain
    itself to fit the table.
    In order to size the column to fit the largest cell, for each row, go through each column and get the
    renderer component for that column (which configures the component for rendering) and get the width
    of that component. If that's bigger than the column's current width, set its width and preferred width.
    You'll also want to check the renderer component width for the header to make sure the header doesn't
    get truncated if the column doesn't have a cell whose value is longer than the header.
    : jay

  • Problem with Icon in JCheckBox

    I have a problem with a JCheckBox, when I assign an Icon to it, the checkBox dissapears and the only thing I see is the Icon. Is there a way to have the CheckBox and the Icon?
    Thanks
    Alejandro

    class MyCheckBox extends JPanel {
      JCheckBox jcb = new JCheckBox();
      JLabel jl;
      public MyCheckBox(String s, Icon i) {
        add(jcb);
        jl = new JLabel(s,i, JLabel.LEFT);
        add(jl);
      public boolean isSelected() { return jcb.isSelected(); }
      public void setSelected(boolean b) { jcb.setSelected(b); }
      public String getText() { return jl.getText(); }
      public void setText(String s) { jl.setText(s); }
      public Icon getIcon() { return jl.getIcon(); }
      public void setIcon(Icon i) { jl.setIcon(i); }
    }

  • Scrollbar problem with JTable.

    Hi,
    I have 45 columns in a JTable. Please remember this is customize, we can change the number of columns dynamically, at max they can be 2 columns.
    i was having a problem with display the columns names in my Frame. I posted at http://forum.java.sun.com/thread.jspa?threadID=5167358&messageID=9641265#9641265
    I got the solution. Thanks for that.
    But as i said these columns are customized.
    when i am having 2 columns in my JTable, table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF ); is behaving differently, it's not occupying the complete JFrame. Lots of space is left out beside these 2 columns.
    When i comment this line, then those 2 columns are occupying my complete Frame.
    these two colmns should occupy my complete Frame and if i select 45 columns i should get scroll bar at botton with complete column NAMES.
    Hope i am clear.
    My Snippet
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.util.*;
    public class SimpleTable extends JPanel {
        private boolean DEBUG = false;
        public SimpleTable() {
            super(new BorderLayout());
                        String[][] values = new String[10][];
            String[] columnNames = {
                                                                                    "First Name","Last Name","Sport","# of Years","Vegetarian","First Name","Last Name","Sport","# of Years","Vegetarian","First Name","Last Name","Sport","# of Years","Vegetarian","First Name","Last Name","Sport","# of Years","Vegetarian","First Name","Last Name","Sport","# of Years","Vegetarian","First Name","Last Name","Sport","# of Years","Vegetarian","First Name","Last Name","Sport","# of Years","Vegetarian","First Name","Last Name","Sport","# of Years","Vegetarian","First Name","Last Name","Sport","# of Years","Vegetarian"
            Object[][] data = {
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)},
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)},
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)},
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)},
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)},
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)},
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)},
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)},
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)}
                        DefaultTableModel defaulttablemodel = new DefaultTableModel(data,columnNames);
            final JTable table = new JTable(defaulttablemodel)
                 public boolean isCellEditable(int row,int column)
                                  return false;
                        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
                        //table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
                        JScrollPane scrollPane = new JScrollPane(table);
                        add(scrollPane);
        private static void createAndShowGUI() {
            JFrame frame = new JFrame("SimpleTable");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            SimpleTable newContentPane = new SimpleTable();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    Thank You camickr, it's serving my purpose.
    Just for a clarrification :
    table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
    table.setAutoscrolls(false);without using these lines also my purpose is serving.....then y do we need above two lines of code. r they necessary
    i mean, this snippet is sufficient.
    public boolean getScrollableTracksViewportWidth()
         return getPreferredSize().width < getParent().getWidth();
    }

  • Problems with JTable Renderer

    I have a problem with applying a custom renderer. I know the renderer works so thats not the problem. If I do like this:
    DefaultTableModel aDefaultTableModel = new DefaultTableModel(data, columnNames);
    it works. But if I do like this:
    DefaultTableModel aDefaultTableModel;
    aDefaultTableModel.setDataVector(data, columNames);
    is doesn't, why?

    I think maybe it's not the renderer at all. It may be my custom TableModel thats causing problems. Now this doesn't work:
    private JTable aTable;
    private CustomTableModel aTableModel;
    public MyProgram() {
    aTableModel = new CustomTableModel();
    aTable = new JTable(aTableModel);
    aTableModel.setData(data, columnNames);
    private class CustomTableModel {
    private String[] columnNames = null;
    private Object[][] data = null;
    public CustomTableModel() {
    columnNames = new String[0];
    data = new Object[0][0];
    ... snip
    public void setData(Object[][] data, String[] columnNames) {
    this.data = data;
    this.columnNames = columnNames;
    fireTableDataChanged();
    ... snip
    Now, why doesn't that setData method work??

  • Problem with JCheckBoxMenuItem/JCheckBox

    Hi guys, basically, I have this JCheckBoxMenuItem to set if another frame is always on top or not. But the problem is when I clicked that JCheckBoxMenuItem, the isSelected() method always returned false, even when it is selected. I think it might be I'm using the wrong event handler or there's some mechanism behind it that I'm not aware of. Or because the state is not updated instantly? I had the similar problem with my JCheckBox. Thanks very much for your help in advance!
        private void jCheckBoxMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
            //set up if robot view is always on top
            if(jRadioButtonMenuItem2.isSelected()){
                rvf.setAlwaysOnTop(true);
                System.out.println("true");
            } else{
                rvf.setAlwaysOnTop(false);
                System.out.println("false");
        }    Cheers,
    J
    Edited by: J.T on Jan 30, 2008 3:10 AM

    sorry guys i'm just being stupid hehe
    if(jRadioButtonMenuItem2.isSelected()){this should be jCheckBoxMenuItem2............. i'm sorry for posting a stupid question.
    thanks anyways.
    j.

  • I am really stuck with JCheckBox using it as a JTable cell editor...

    i need to focus next table cell, when user press a key on JcheckBox used in JTable as a cell editor.
    Especially i need to bind "ENTER" key with this action. I tried to addKeyListener do checkbox, tried to add action into input maps of jatble, and also to input map of checkbox. But really nothing works. Please help....
    Mathew, HSIGP

    and yes your code works well with any key, but when i want to assign something to "ENTER", it doesnt work. F.ex. if i assign something to "A" key
    like>
    InputMap m=table.getInputMap(WHEN_ANCETSTOR...);
    m.put(KeyStroke.get("A"),m.get(KeyStroke.get("TAB"));
    it works fine, and when i press "a" key it work as a "tab" key in table.
    But when i am doing same with "enter" instead of "a" it doesnt work.
    btw. there is action "actionselectNextCollumn..." assigned by default to enter
    why??

Maybe you are looking for

  • Skype for Windows Phone 8.1 crashes every time

    Hello, i'm having problems with skype on my wp. Whenever someone calls me, or sends me a message it crashes and I can't re-open it until I restart my wp. Also I don't receive calls, just sometimes and the tasks are so slow that I can't do anything wh

  • I lose carrier when i pick my i4S up.

    I'm on vodafone - when I pick my iphone 4S up I lose the carrier? Anybody else experienced this and fixed it? I know there was a similar problem on the iphone 4 and protective cases were supplied to prevent touching the metal antenna strip running ro

  • How can i get rid of an old email i used as an apple id

    I had an old  email address i used as an apple id. I have a new one now but occasioally the email and id which i no longer have keeps popping up. how can i get rid of it from my iphone and ipad?

  • Linksys and DW7000 sattelite receiver

    I cant seem to hook my Linksys WRT54G and DW700 Satellite Receiver together to enable port forwarding to occur. I have the pro plan which has a static IP. Any help would be greatly appreciated. Richard

  • Handling sessions in BDC

    Hi all,          What do we code to create a new session in BDC Call transaction method.          Let me explain the situation in brief.     I have an issue where in i need to upload 5000 records. As per requirement i am supposed to upload only 1000