Set default cell on JTable

How do I set the default cell on my JTable to be the first cell? Everytime my table gets the TAB or SHIFT-TAB key event, the last cell added to the table gets focus. Is there any way that I can change this to force cell(0,0) to always get focus on receiving the TAB or SHIFT-TAB key?

TableColumn tc = table.getColumnModel().getColumn(0);
tc.setMaxWidth(25);
[\code]                                                                                                                                                                               

Similar Messages

  • Default cell values for column not properly saved in uir file in labwindows 2009 (9.1.0 427)?

    I've run into a strange problem with the table control.  Basically, even though I set default cell values for a particular column as numeric, when I try to add items to the list it tries to add them as strings, and returns an error message that it is expecting *char instead of int.  Furthermore, when I open the uir file that contains the table in question in 2010, it appears as if the default cell values for that column are still set as strings, even though in 2009 when I open the uir file it shows as numbers.  I tried converting the uir to C code, and sure enough the C code indicated that the column still is a string type.
    I've gone ahead and made a small project to show the issue.  If you open this project in labwindows 2009 and click on the table in the table_bug.uir, and edit default cell values for column 1, you will see that the cell settings have type as numeric and data type as int.  When you run the project, however, it will fail with an error message saying that it is looking for a *char.  When this same project is loaded into labwindows 2010, clicking on the table in table_bug.uir and edit default cell values (column 1) shows the type as string.  When I change this to numeric (and change numeric attribute to int), this runs fine in 2010.  I tried simply changing the uir in 2010, and then using it in 2009, but 2009 complains that the uir is from a newer version (understandable).  If there is any workaround that would let me continue to use 2009 for the time that would be great.
    Any help would be greatly appreciated.
    thanks,
    Alex Corwin
    Solved!
    Go to Solution.
    Attachments:
    table_bug.zip ‏324 KB

    I opened the UIR in 2009 (but I have 2009 SP1) and it still showed that the default value for the first column was a string. I didn't have any problems changing it to a numeric int, and then building and running the project without error.
    Here are a few things you can try:
    1) Change the default value to a string. OK out of the dialog, re-enter the dialog, and change it back to Numeric int. Resave and see if the problem has gone away.
    2) You said you get a ".UIR is from a newer version" error when opening the 2010 UIR in 2009. Does the UIR still open if you click okay? Often times this will work just fine. Assuming you don't have any problems with this, make a minor change to the UIR in 2009, such as moving the table to the left, and then back to the right and then re-save. See if your program works now.
    Kevin B.
    National Instruments

  • HELP!! set the cell color in jTable

    I need to set the color of a specific cell in jTable, but, I need to retain the old color in the jTable. It must not reset the whole table.
    would anyone help me in this problem... PLSSSSS its urgent

    A flexible variation on this is to specify formatting options in the JTable's client properties:
    // Use some sort of special "key" to indicate the cell and that you want to set the background color
    String key = "background:" + row + "," + column;
    table.putClientProperty(key, Color.green);You can then write a general table cell renderer that looks for these special formatting options and it doesn't disrupt your existing TableModel in any way:
    public class FormattingTableCellRenderer extends DefaultTableCellRenderer
      public Component getTableCellRendererComponent(JTable table, Object value, int row, int column, ...)
        Component component = super.getTableCellRendererComponent(table, value, row, column, ...);
        // See if the JTable specifies any properties to override the default format
        Color backgroundColor = (Color)table.getClientProperty("background:" + row + "," + column);
        if(backgroundColor != null)
          component.setBackground(backgroundColor);
        return component;
    }Any custom cell renderers you have then simply need to extend FormatTableCellRenderer instead of DefaultTableCellRenderer.
    It's very easy to add formatting options other than background, such as font, to the list of recognised attributes. You'll probably need to make some alterations to get it to recognise selection/focus but hopefully you get the idea.
    Hope this helps.

  • Dynamically set font in a JTable cell

    Hi there,
    i have a JTable, and a JTCombo box containing all the system fonts available. The JTable is made up of my own class called myCell which can be seen below. I have also implemented my own custom renderer. What i would like to do is when the user selects a new system font, the text that is then typed into the JTable to be of that font. If the system font is changed again, i would like any new text to be of the new font, and the old fonts remain the same (i hope that makes sense!) Anyway, im quite stuck about this - i have tried messing around with the cellrenderer but all the text in all the cells changes to the new font. Does anyone know how to do this? many thanks, Rupz
         public myCell(int aRow,int aCol,Object someValue, TreeSet somecells, String aFormula){
              row = aRow;
              col = aCol;
              value = someValue;
              expression = aFormula;
              references = somecells;
         }

    First of all the Java standard for class names us to use upper case characters for the first letter of each word. So your class should be MyCell.
    Now your MyCell class need to keep the Font as one of its properties. Maybe you would override the JTable getCellEditor(...) method such that if the Font property for the cell is null, then set the cell Font to the current default Font. The renderer would then use the Font from the cell when it is non-null.

  • Setting Focus to a particular cell in JTable

    Hi, can i know how to set the focus to a particular cell in JTable.
    Say I have a table with 2 rows and 10 columns. The focus now is at position (1, 9) which is the last cell in the table. But I want to set the focus to (1, 3). How can i achieve this ? Pls help. Thanks

    OK. It's partially working. The right methods to use are setRowSelectionInterval and setColumnSelectionInterval. Jeanette was right. Mine didn't work because of a thread issue. I put the those two methods in a block such as:
    SwingUtilities.invokeLater(new Runnable(){
    public void run()
    table.setRowSelectionInterval(tblLineItem.getRowCount()-1,
    table.getRowCount()-1);
    table.setColumnSelectionInterval(0,0);
    Then it worked.
    But after I finished editing the first cell of the newly created row and press ENTER, the selection went back to the cell that's next to the originally editing cell on the first(old) row, instead of staying at the current row and going to the second cell.
    Can anybody shed a light on what I'm missing?

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

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

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

  • How to set default value and bg color of cross tab cell?

    Hi all
    Which way can I set default value and background color for a crosstab cell where there are no any data?
    I try to pass it in following way
    if isnull(CurrentFieldValue) then
    But is has no effect.

    Hi,
    If your field is numeric
    if currentfieldvalue =0 then cryellow else crnocolor
    if the field is numeric but you don't see the 0 check check if : Suppress if zero is ticked in the Number format tab.
    Regards

  • What component is placed default in each cell of JTable?

    Hi,
    What component is placed default in each cell of JTable?

    It depends on the content, see How to Use Tables - Concepts: Editors and Renderers for details.

  • How to set a cell editable at runtime for jtable

    Hi evry body
    i need to set a cell as editable during runtime and set some value for the cell and make it non editable after setting value
    how can i do it? urgent help appreciated
    regards
    anil

    You could override the methods isCellEditable(...) and setValueAt(...) in your JTable's TableModel to get the effect desired
    // Assuming that each element of the array will be false initially
    boolean[][] valueSet = new boolean[noRows][noCols];
    public boolean isCellEditable(int row, int col) {
      return !valueSet[row][col];
    public void setValueAt(Object obj, int row, int col) {
      super.setValueAt(obj, row, col);
      valueSet[row][col] = true;
    }

  • Setting two JTextFields inside JTable cell

    hi,
    I am really stick trying to figure out how to set two cells inside a JTable cell. This needs to be done because if there is a value already inside the cell then i want to drop another value - this new value should be displayed inside another cell but along with the other value already in the cell.
    I assume that i would need to create two JTextFields.
    But can anyone help me further please.

    That should be a simple issue of customizing table cell editor and renderer.
    See tutorials.

  • Setting table cell background

    Friends,
    I have a JTable with 5 rows and 4 columns now I want to set the Background color of cells as I select the set of cells it changes the background color.
    the problem in the below code is I have to select the individual cells to set the bg. can anyone tell what I should add to set bg of all the selection + I am unable to see the cell selection.
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    * This is like TableDemo, except that it substitutes a
    * Favorite Color column for the Last Name column and specifies
    * a custom cell renderer and editor for the color data.
    public class TestClass extends JPanel implements MouseListener {
         private boolean DEBUG = false;
         private JTable table;
         private Color defColor = Color.WHITE;
         private Color selColor = Color.GRAY;
         private Color[][] color = {
              {defColor, defColor, defColor, defColor, defColor},
              {defColor, defColor, defColor, defColor, defColor},
              {defColor, defColor, defColor, defColor, defColor},
              {defColor, defColor, defColor, defColor, defColor},
              {defColor, defColor, defColor, defColor, defColor}
         public TestClass() {
              super(new GridLayout(1,0));
              table = new JTable(new MyTableModel());
              table.setRowSelectionAllowed(false);
              table.setCellSelectionEnabled(true);
              table.addMouseListener(this);
              table.setPreferredScrollableViewportSize(new Dimension(500, 70));
              //Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);
              //Set up renderer and editor for the Favorite Color column.
              table.setDefaultRenderer(String.class,
                                             new ColorRenderer(color));
              //Add the scroll pane to this panel.
              add(scrollPane);
         class MyTableModel extends AbstractTableModel {
              private String[] columnNames = {"First Name",
                                                      "Favorite Color",
                                                      "Sport",
                                                      "# of Years",
                                                      "Vegetarian"};
              private Object[][] data = {
              public int getColumnCount() {
                   return columnNames.length;
              public int getRowCount() {
                   return data.length;
              public String getColumnName(int col) {
                   return columnNames[col];
              public Object getValueAt(int row, int col) {
                   return data[row][col];
               * JTable uses this method to determine the default renderer/
               * editor for each cell.  If we didn't implement this method,
               * then the last column would contain text ("true"/"false"),
               * rather than a check box.
              public Class getColumnClass(int c) {
                   return getValueAt(0, c).getClass();
              public boolean isCellEditable(int row, int col) {
                   return false;
              public void setValueAt(Object value, int row, int col) {
                   if (DEBUG) {
                        System.out.println("Setting value at " + row + "," + col
                                               + " to " + value
                                               + " (an instance of "
                                               + value.getClass() + ")");
                   data[row][col] = value;
                   fireTableCellUpdated(row, col);
                   if (DEBUG) {
                        System.out.println("New value of data:");
                        printDebugData();
              private void printDebugData() {
                   int numRows = getRowCount();
                   int numCols = getColumnCount();
                   for (int i=0; i < numRows; i++) {
                        System.out.print("    row " + i + ":");
                        for (int j=0; j < numCols; j++) {
                             System.out.print("  " + data[i][j]);
                        System.out.println();
                   System.out.println("--------------------------");
          * Create the GUI and show it.  For thread safety,
          * this method should be invoked from the
          * event-dispatching thread.
         private static void createAndShowGUI() {
              //Make sure we have nice window decorations.
              JFrame.setDefaultLookAndFeelDecorated(true);
              //Create and set up the window.
              JFrame frame = new JFrame("TableDialogEditDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //Create and set up the content pane.
              JComponent newContentPane = new TestClass();
              newContentPane.setOpaque(true); //content panes must be opaque
              frame.setContentPane(newContentPane);
              //Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              //Schedule a job for the event-dispatching thread:
              //creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();
         /* (non-Javadoc)
          * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
         public void mouseClicked(MouseEvent e) {
              if (table.getSelectedColumn() > 0) {
                   if (color[table.getSelectedRow()][table.getSelectedColumn()] == selColor) {
                        color[table.getSelectedRow()][table.getSelectedColumn()] = defColor;
                   } else {
                        color[table.getSelectedRow()][table.getSelectedColumn()] = selColor;
              } else {
              ((MyTableModel)table.getModel()).fireTableStructureChanged();
         /* (non-Javadoc)
          * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
         public void mouseEntered(MouseEvent e) {
         /* (non-Javadoc)
          * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
         public void mouseExited(MouseEvent e) {
         /* (non-Javadoc)
          * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
         public void mousePressed(MouseEvent e) {
         /* (non-Javadoc)
          * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
         public void mouseReleased(MouseEvent e) {
    import javax.swing.JLabel;
    import javax.swing.JTable;
    import javax.swing.border.Border;
    import javax.swing.table.TableCellRenderer;
    import java.awt.Color;
    import java.awt.Component;
    public class TableCellColorRenderer extends JLabel
                               implements TableCellRenderer {
        Color[][] colorBG = null;
        public TableCellColorRenderer(Color[][] color) {
            this.colorBG = color;
            setOpaque(true); //MUST do this for background to show up.
        public Component getTableCellRendererComponent(
                                JTable table, Object color,
                                boolean isSelected, boolean hasFocus,
                                int row, int column) {
              setBackground(colorBG[row][column]);
            return this;

    I would guess that it's because you set the background to Color.WHITE
    I'm not sure why you're passing in an array of Color objects ... typically you'd either pick the color based on the value of the cell, or use standard colors.
    Finally, your getTableCellRendererComponent() should check the isSelected argument, and use a different color to highlight the selection.

  • How to make a cell in JTable a different colour?

    Hi, i've been playing with JTables with a custom CellRenderer, which I'm trying to make so that in the JTable, when two values down a column are found to be the same, the back ground colour changes to something same (hoping that there is a way to randomize the colour values) the code i have atm is
    In the main program :
                        find.addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent ae) {
                                  datahome = cC.data;
                                  TableColumnModel colModel = cC.jtable.getColumnModel();
                                  TableColumn column = colModel.getColumn(0);
                                  column.setCellRenderer(new RedCellRenderer(new int[] {1,2}));
    in the cellrenderer:
    package packageSolo;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.*;
    import java.awt.*;
    public class SetCellColour extends DefaultTableCellRenderer {
         private int arrVerifyColumns[] = null;
         public SetCellColour(int iTestColumns[]) {
              arrVerifyColumns = iTestColumns;
         public Component getTableCellRendererComponent(JTable table, Object value,
                   boolean isSelected, boolean hasFocus, int row, int column) {
              this.setBackground(Color.RED); // All columns verified were empty - set
              // our background RED
              return this;
    }any my problem is that this cellrenderer will change the column and not just the cell, i've tried to pass where the cell is (the x and y of the cell) to the cellrenderer, but there is no way for me to interpret this value in cellrenderer and set that cell to that colour i'm not sure if there is a cell model instead of column model and be able to pass that onto the cellrenderer

    ell after several tries, i have determined that it may be something wrong with that my jtable is part of a JPanel, that is attached to a container with scroll pane that is then added to a JFrame's center... and somewhere here it freezes the display...
    my code for the actual JFrame:
    package packageSolo;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    public class ConflictCheckerGUIIntialization extends JFrame {
          * debugger
          * @param x
          *            takes in an int and prints a debug line when enabled to the
          *            console
         private void debug(int x) {
              // System.out.print("Flag: "+ x);
         private static int flag1 = 0;
         private static int flag2 = 0;
         private static int flag3 = 0;
         private static int flag4 = 0;
         private static int flag5 = 0;
         private static int flag6 = 0;
         private static int flag7 = 0;
         private static int flag8 = 0;
         private static int flag9 = 0;
         private Object[][] datahome;
         private JButton cConflict = new JButton("Check Conflict");
         private JButton find = new JButton("Find");
         private JButton quit = new JButton("Exit");
         // private JButton northavg = new JButton("North's Average");
         // private JButton eastavg = new JButton("East's Average");
         // private JButton largest = new JButton("Largest Percepitation");
         // private JButton totalPercepitation = new JButton("Total Percepitation");
         private ConflictCheckerGUI cC = new ConflictCheckerGUI();
         private JFrame jf = new JFrame();
         private JFrame jf1 = new JFrame();
         // Get the size of the default screen
         private static Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
         private int screensizex = (int) (dim.width * 0.8);
         private int screensizey = (int) (dim.height * 0.75);
         private static int gcsizex = (int) (dim.width * 0.625);
         private static int gcsizey = (int) (dim.height * 0.1953125);
         private static GUIConsole gc = new GUIConsole("Output", gcsizex, gcsizey);
         public ConflictCheckerGUIIntialization() {
              boolean RunOnce = false;
              while (RunOnce == false) {
                   if (cC.finished == true) {
                        System.out.println("he");
                        Container c1 = jf.getContentPane();
                        c1.setLayout(new FlowLayout());
                        Container c = this.getContentPane();
                        Container c2 = jf1.getContentPane();
                        JPanel jp = new JPanel();
                        jp.add(cC);
                        cConflict.addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent ae) {
                                  datahome = cC.data;
                                  // System.out.print(datahome
                                  // [0][0].toString().compareTo(datahome
                                  // [1][0].toString()));
                                  // System.out.print(datahome
                                  // [0][0].toString().equals(datahome
                                  // [1][0].toString()));
                                  for (int conflictCounter2 = 1; conflictCounter2 < 3; conflictCounter2++) {
                                       int conflictCounter4 = 0;
                                       for (int conflictCounter1 = 0; conflictCounter1 <= cC.Classroomint; conflictCounter1++) {
                                            conflictCounter4++;
                                            for (int conflictCounter3 = 1; conflictCounter3 <= (cC.Classroomint - conflictCounter4); conflictCounter3++) {
                                                 if (datahome[conflictCounter2][conflictCounter1]
                                                           .toString()
                                                           .equals(
                                                                     datahome[conflictCounter2][conflictCounter1
                                                                               + conflictCounter3]
                                                                               .toString())) {
                                                      System.out.println("error at "
                                                                + conflictCounter2 + " "
                                                                + conflictCounter1);
                                   * for (int counter1 = 0; counter1 < pg.monthint;
                                   * counter1++) { for (int counter2 = 0; counter2 < 5;
                                   * counter2++) {
                                   * System.out.print(datahome[counter1][counter2] +
                                   * "\t"); } System.out.println(); }
                        quit.addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent ae) {
                                  try {
                                       System.exit(0);
                                  } catch (SecurityException ea) {
                                       System.out.println("Cannot exit");
                        find.addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent ae) {
                                  datahome = cC.data;
                                  Object value = null;
                                  cC.jtable.getCellRenderer(0, 0)
                                            .getTableCellRendererComponent(cC.jtable,
                                                      value, false, true, 0, 0).setFont(new Font(
                                                      "Serif", Font.BOLD, 14));
                                  System.out.println(cC.data[0][0].toString());
                                  // .setFont(new Font("serif", Font.BOLD, 12));
                        gc
                                  .println("There is a known bug with this program that if you enter any information in the table,");
                        gc
                                  .println("then not confirming it by not going to another cell, then the data you've entered it not valid and not considered to be input,");
                        gc
                                  .println("this will be fixed in future revisions if possible");
                        gc.show();
                        gc.setLocation(0, screensizey);
                                    *bold*
                                   *bold* c2.add(jp, "Center");
                        *bold*c2.add(new JScrollPane(jp,
                                  *bold*ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                  *bold*ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED),
                                  *bold*"Center");
                        c1.setLayout(new GridLayout(2, 5));
                        c1.add(cConflict);
                        c1.add(find);
                        c1.add(quit);
                        c1.setVisible(true);
                        c2.setVisible(true);
                        c.add(c1, "South");
                        c.add(c2, "Center");
                        c.setVisible(true);
                        this.pack();
                        this.setTitle("Lancer's Class Conflict Checker");
                        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
                        this.setSize(screensizex, screensizey);
                        RunOnce = true;
                        // ! this.pack(); //this tries to set the size of the thing to a
                        // perferred size, and if used will not alow the dynamic sizing
                        // of
                        // the
                        // main JTable window based on the user's screensize
         public static void main(String[] args) {
              ConflictCheckerGUIIntialization x = new ConflictCheckerGUIIntialization();
              x.setVisible(true);
    }here, the JPanel with the jtable is added to c2 and c2 is added to c and c's parent is the JFrame of this whole class
    and the code for the jtable JPanel is:
    package packageSolo;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FileNotFoundException;
    import javax.swing.*;
    import javax.swing.table.*;
    public class ConflictCheckerGUI extends JPanel {
         private void debug(int x) {
              // System.out.println(x);
         protected static boolean finished = false;
         protected static DefaultTableModel[][] data;
         protected static int Classroomint = 0;
         protected static JTable jtable;
         protected static String[] columnNames = { "Classroom", "Period One",
                   "Period Two", "Period Three", "Period Four" };
         protected static int GoAheadFlag = 0;
         SetCellColour renderer;
         public ConflictCheckerGUI() {
              // super(new GridLayout(1, 0));
              JFrame Choose = new JFrame();
              Choose.setDefaultCloseOperation(Choose.EXIT_ON_CLOSE);
              JButton ImportFromFile = new JButton("Impoort From File");
              JButton New = new JButton("New Planner");
              ImportFromFile.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        String[] North;
                        String[] East;
                        String[] South;
                        String[] West;
                        String[] Month;
                        // JFileChooser fc = new JFileChooser();
                        // fc.show();
                        // int returnVal = fc.showOpenDialog(fc);
                        // File file = null;
                        // if (returnVal == JFileChooser.APPROVE_OPTION) {
                        // file = fc.getSelectedFile();
                        java.util.Scanner parse = null;
                        File file = new File(
                                  "E://Documents and Settings//TheHolyLancer//My Documents//java - old//Eclipse workspace//Precipitation//packageSolo//datasave.txt");
                        try {
                             parse = new java.util.Scanner(file);
                        } catch (FileNotFoundException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        Classroomint = Integer.parseInt(parse.next());
                        North = new String[Classroomint];
                        East = new String[Classroomint];
                        South = new String[Classroomint];
                        West = new String[Classroomint];
                        Month = new String[Classroomint];
                        for (int counter1 = 0; counter1 < Classroomint; counter1++) {
                             Month[counter1] = "n/a";
                        for (int counter2 = 0; counter2 < Classroomint; counter2++) {
                             North[counter2] = "n/a";
                             East[counter2] = "n/a";
                             South[counter2] = "n/a";
                             West[counter2] = "n/a";
                        data = new DefaultTableModel[Classroomint][5];
                        jtable = new JTable(new DefaultTableModel(Classroomint,5));//columnnames
                        jtable.setPreferredScrollableViewportSize(new Dimension(800,
                                  600));
                        finished = true;
              New.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        String input;
                        String[] North;
                        String[] East;
                        String[] South;
                        String[] West;
                        String[] Month;
                        int flag2 = 0;
                        int flag4 = 0;
                        int flag5 = 0;
                        int flag8 = 0;
                        input = JOptionPane
                                  .showInputDialog("How many classromms are there?");
                         * see if the user wantes to quit at this point
                        if (input == null) {
                             debug(4);
                             int exitint = 0;
                             exitint = JOptionPane.showConfirmDialog(null,
                                       "Do you want to exit?", "Exit?",
                                       JOptionPane.OK_CANCEL_OPTION);
                             if (exitint == 0) {
                                  try {
                                       System.exit(1);
                                  } catch (SecurityException eb) {
                                       System.out.println("exit");
                        while (flag4 == 0) {
                              * this while loop with flag2 is for checking if the thing
                              * is of int class
                             while (flag2 == 0) {
                                   * try to get a integer, check for a bad input class
                                  try {
                                        * parse, and if success set flag2 to 1 and break
                                        * out this while loop
                                       Classroomint = Integer.parseInt(input);
                                       flag2 = 1;
                                       debug(2);
                                  } catch (NumberFormatException ec) {
                                       debug(3);
                                        * ops user input was not a integer class
                                       JOptionPane.showMessageDialog(null,
                                                 "Enter a positive integer only",
                                                 "Number Format is Wrong",
                                                 JOptionPane.ERROR_MESSAGE);
                                       input = JOptionPane
                                                 .showInputDialog("How many months are there?");
                                        * see if the user wantes to quit at this point
                                       if (input == null) {
                                            debug(4);
                                            int exitint = 0;
                                            exitint = JOptionPane.showConfirmDialog(null,
                                                      "Do you want to exit?", "Exit?",
                                                      JOptionPane.OK_CANCEL_OPTION);
                                            if (exitint == 0) {
                                                 try {
                                                      System.exit(1);
                                                 } catch (SecurityException eb) {
                                                      System.out.println("exit");
                              * this while loop sees if the integer is smaller than 0 so
                              * the array cannot be a real one
                             while (flag5 == 0) {
                                  // numamountint = Integer.parseInt(numamount);
                                  if (Classroomint < 0) {
                                       debug(5);
                                       JOptionPane.showMessageDialog(null,
                                                 "Enter a positive integer",
                                                 "Number Format/Size is Wrong",
                                                 JOptionPane.ERROR_MESSAGE);
                                       input = JOptionPane
                                                 .showInputDialog("How many months are there?");
                                       if (input == null) {
                                            int exitint = 0;
                                            exitint = JOptionPane.showConfirmDialog(null,
                                                      "Do you want to exit?", "Exit?",
                                                      JOptionPane.OK_CANCEL_OPTION);
                                            if (exitint == 0) {
                                                 try {
                                                      System.exit(1);
                                                 } catch (SecurityException eb) {
                                                      System.out.println("exit");
                                        * this while loop check for number format again
                                       while (flag8 == 0) {
                                            try {
                                                 debug(6);
                                                 Classroomint = Integer.parseInt(input);
                                                 flag8 = 1;
                                            } catch (NumberFormatException ec) {
                                                 debug(7);
                                                 JOptionPane.showMessageDialog(null,
                                                           "Enter a positive integer only",
                                                           "Number Format is Wrong",
                                                           JOptionPane.ERROR_MESSAGE);
                                                 input = JOptionPane
                                                           .showInputDialog("How many months are there?");
                                                 if (input == null) {
                                                      int exitint = 0;
                                                      exitint = JOptionPane
                                                                .showConfirmDialog(
                                                                          null,
                                                                          "Do you want to exit?",
                                                                          "Exit?",
                                                                          JOptionPane.OK_CANCEL_OPTION);
                                                      if (exitint == 0) {
                                                           try {
                                                                System.exit(1);
                                                           } catch (SecurityException eb) {
                                                                System.out.println("exit");
                                  } else {
                                        * here the input is greater than 0 so it sets flag5
                                        * and 4 then break out of the while loops
                                       debug(8);
                                       flag5 = 1;
                                       flag4 = 1;
                        North = new String[Classroomint];
                        East = new String[Classroomint];
                        South = new String[Classroomint];
                        West = new String[Classroomint];
                        Month = new String[Classroomint];
                        for (int counter1 = 0; counter1 < Classroomint; counter1++) {
                             Month[counter1] = "n/a";
                        for (int counter2 = 0; counter2 < Classroomint; counter2++) {
                             North[counter2] = "n/a";
                             East[counter2] = "n/a";
                             South[counter2] = "n/a";
                             West[counter2] = "n/a";
                        DefaultTableModel tableModel = new DefaultTableModel(Classroomint, 0);
                        tableModel.addColumn("Classroom");
                        tableModel.addColumn("Period One");
                        tableModel.addColumn("Period Two");
                        tableModel.addColumn("Period Three");
                        tableModel.addColumn("Period Four");
                        /*protected static String[] columnNames = { "Classroom", "Period One",
                             "Period Two", "Period Three", "Period Four" };*/
                        // /jtable = new JTable(data, columnNames);
                        jtable = new JTable(tableModel) {
                             private static final long serialVersionUID = 1L;
                             public TableCellRenderer getCellRenderer(int row, int col) {
                                  return renderer;
                        jtable.setRowSelectionAllowed(true);
                        jtable.setPreferredScrollableViewportSize(new Dimension(800,
                                  600));
                        finished = true;
              Container ButtonHolder = new Container();
              ButtonHolder.setLayout(new GridLayout(1, 2));
              ButtonHolder.add(New);
              ButtonHolder.add(ImportFromFile);
              Choose.add(ButtonHolder);
              Choose.setSize(200, 300);
              Choose.setVisible(true);
              boolean RunOnce = false;
              while (RunOnce == false) {
                   if (finished == true) {
                        //JScrollPane scrollPane = new JScrollPane(jtable);
                        this.add( jtable, BorderLayout.CENTER );
                        Choose.setEnabled(false);
                        RunOnce = true;
    }but upon start, and select start new table, the windows come up, but on where the large JFrame is and where the jtable is, nothing appears, and it acts like a screen cap and the thing just stucks like what is on the background of the computer... i think in all this linking i may have screwed something up, and the examples given were not designed for JPanels, but rather for JFrames... maybe i could implement all this into one class, since the buttons for choosing from load from file and all that can be in the first file as another JFrame, that is first visible, then when user chose one, something becomes visible, or something
    but anyone knows how to fix all this?

  • How to disable a particular cell in JTable ?

    I having a problem on how to set disable a particular cell in JTable. At the first place to load the JTable, I want to set some of the cell to disabled, it only will run at the first time, is there anyway to do it ?

    This is the function that disable/enable cells in JTables.
    Are you looking for this?
    public boolean isCellEditable(int row, int col)
      if(((new Integer((String)(getValueAt(row,0)).toString()).intValue()>9))&&(col==1))
        return true;
      if(row!=4&&col!=5)
        return true;
      return false;
         this metod belong to the TableModel function
    and what I gave you is only an example of what you can do with it.
    if it return false it disable and if true it enable the cell...but I think this you allready know!
    Regards Amnon

  • How to set default values in matrix combo

    hai everybody.
    i want to set default values in a matrix combo box. how to do that
    pls.......

    Hi Priya,
    Public Sub comboload1()
            Try
                ds = oform.DataSources.DBDataSources.Add("OUSR")
                oitem = oform.Items.Item("pm7")
                omatrix = oitem.Specific
                ocolumns = omatrix.Columns
               ocolumn = ocolumns.Item("V_2")
               ocombo = ocolumn.Cells.Item(r).Specific (r = row number)
                LoadEroToCombo1(ocombo)
            Catch ex As Exception
                oapp.MessageBox(ex.Message)
            End Try
        End Sub
    load to combo function is below
        Public Sub LoadEroToCombo1(ByRef ocombo As SAPbouiCOM.ComboBox)
            Dim rset As SAPbobsCOM.Recordset
            Dim querystring As String
            Dim rcount As Long
            Dim rindex As Long
            Try
                rset = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                querystring = "SELECT T0.U_NAME FROM OUSR T0"
                rset.DoQuery(querystring)
                rcount = rset.RecordCount
                rset.MoveFirst()
                ocombo.ValidValues.Add("0", "Select")
                For rindex = 0 To rcount - 1
                    ocombo.ValidValues.Add(rset.Fields.Item(0).Value, rindex)
                    rset.MoveNext()
                Next rindex
                ocombo.Select("0")
                rset = Nothing
                System.GC.Collect()
            Catch ex As Exception
                oapp.MessageBox(ex.Message)
            End Try
        End Sub
    try this code if it helps please reward points
    Regards
    Cool Ice
    Edited by: Cool Ice on Jul 28, 2008 1:43 PM

  • Problem with select all cells in JTable

    Hi guys! I get some problem about selecting all cells in JTable. I tried to used two methods:
    1> table.selectAll()2> changeSelection(firstcell, lastcell,false,true)
    firstcell:[0,0], lastcell[rowcount-1,colcount-1]
    Result: only the first row selected when i use both methods.
    Note: i set up the selection model as following:
    this.dataSheet.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                    this.dataSheet.setCellSelectionEnabled(true);
                    this.dataSheet.setRowSelectionAllowed(true);
                    this.dataSheet.setColumnSelectionAllowed(true);Thanks !

    What selection properity should be changed in order to enable selectAll() method work properly? Is there Any constraints? Here is the TableModel I am using. And i set up selection mode use the following code:
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setCellSelectionEnabled(true);
    table.setRowSelectionAllowed(true);
    table.setColumnSelectionAllowed(true);
    import java.util.Vector;
    import javax.swing.table.*;
    import javax.swing.JTable;
    public class DataSheetModel extends AbstractTableModel{
              private Vector data = new Vector();//Store data
              private Vector columnNames = new Vector();//Store head
              public DataSheetModel(){}
              public DataSheetModel(Vector headVector, Vector dataVector){
                   if(headVector != null) this.columnNames = headVector;
                   if(dataVector != null) this.data = dataVector;
              public int getColumnCount(){
                   return columnNames.size()+1;
              public int getRowCount(){
                   return data.size()+1;
              public String getColumnName(int col){
                   if(col==0) return "";
                   else return (String)columnNames.get(col-1);
              public Object getValueAt(int row, int col){
                   if(col==0) {
                        if(row != data.size()) return String.valueOf(row);
                        else return "*";
                   else{
                        if(row != data.size()){
                             Vector rowVector = (Vector)data.elementAt(row);
                             return rowVector.elementAt(col-1);
                        }else return null;
              public void setValueAt(Object value, int row, int col){
                   if(row != this.data.size()){
                        Vector rowVector = (Vector)data.elementAt(row);
                        rowVector.set(col-1,value);
                        this.data.set(row,rowVector);
                        this.fireTableDataChanged();
                   }else{
                        Vector rowVector = new Vector();
                        for(int i=0; i<this.getColumnCount()-1; i++) rowVector.add(null);
                        rowVector.set(col-1,value);
                        this.data.add(rowVector);
                        this.fireTableDataChanged();
              public Class getColumnClass(int c){
                   return getValueAt(0,c).getClass();
              public boolean isCellEditable(int row, int col){
                   if(col == 0) return false;
                   else return true;
              public void setDataVector(Vector head, Vector data){
                   if(head != null) this.columnNames = head;
                   if(data != null) this.data = data;
    }

Maybe you are looking for

  • Can I certify a document with Acrobat Reader ?

    Hi, I would like to know if it is possible to certify a document with Acrobat Reader. The sign toolbar button "Certify" in Reader is always disabled even if the document has not been signed. Thanks in advance.

  • Return back the stock in a cross company stock transfer environment

    Hi all, I have a question in reagrds to Standard SAP Stock transport order with SD and billing (i.e. cross company stock transfer) For example: Ordering plant (issue Stock transport PO)---- > Supplying plant (create DO) - > Supplying Plant (PGI) - >

  • Itunes Freezing with iPod sync

    Hi There, So when I plug my iPod into the computer and load up itunes. I get prompted with a unauthorization of a few songs (due to an older itunes account; I merged with my girlfriend) Secondly, it then proceeds to update all the songs on my iPod(al

  • Song replays from beginning after waking from sleep

    I've tried searching for a solution with no luck. Heres what happens. 1. I'm playing music. 2. Midway into the song, I get a call. 3. I answer phone 4. as soon as I answer, I lock the phone with the sleep button so I safely put it back into my pocket

  • Assigment of alternative items in Routing

    Hello All, In a BOM, Material A and B are alternative items with same item no. (grp-01,prior -1, strategy-1, usage prob A=100, B=0). In routing, material A is assigned to operation 0010 and B assigned to operation 0020. But when prod order is created