Ordering JTables with fixed column

I have 2 JTable. The first one is not scrollable and the second one yes. I want to order both tables? How can I do??

You haven't given any information which leads me to believe this is anything other than sorting a table. See [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#sorting]here.

Similar Messages

  • Horizontal scrolling in a JTable with fixed-size columns

    Hello,
    I have come to a roadblock concerning the following issue. Perhaps someone can share their ideas...
    I have a JTable with three fixed-size columns. I implemented a JScrollPane with vertical and horizontal scrolling. However, the text inserted into the last column is too long to fit in the specified column width. I would like to be able to scroll the table so that I can view all of the text in the last column. Right now, the text cuts off and ends with three dots (...). Is there a way in which a horizontal scroll bar can be implemented to view all the text in the last column?
    Here is a portion of my code:
    num_of_rows_Table2 = (int) Math.pow(3, num_of_vars);
    String[] colunmNames_Table2 = {"Decimal Identifier", "Ternary Identifier", "Cancellation of nonimplicants"};
    dataModel2 = new DefaultTableModel(colunmNames_Table2, num_of_rows_Table2);
    SpaceOfTermsTable = new JTable(dataModel2);
    for (int z = 0; z < num_of_rows_Table2; z++)
    SpaceOfTermsTable.setRowHeight(z, row_height);
    SpaceOfTermsTable.setBounds(new Rectangle(x1_Table2, y1_Table2, width_of_pane2, height_pane2));
    SpaceOfTermsTable.getTableHeader().setReorderingAllowed(false);
    for (int i = 0; i < 2; i++)
    TableColumn col = SpaceOfTermsTable.getColumnModel().getColumn(i);
    col.setMinWidth(colwidth_Table2);
    col.setMaxWidth(colwidth_Table2);
    col.setPreferredWidth(colwidth_Table2);
    TableColumn lastcol = SpaceOfTermsTable.getColumnModel().getColumn(2); lastcol.setMinWidth(lastcol_Table2);
    lastcol.setMaxWidth(lastcol_Table2);
    lastcol.setPreferredWidth(lastcol_Table2);
    SpaceOfTermsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    scrollPanel2 = new JScrollPane(SpaceOfTermsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPanel2.setAutoscrolls(true);
    scrollPanel2.setBounds(new Rectangle(x1_Table2, y1_Table2, width_of_pane2, height_pane2));
    Thanks in advance for all of the help!

    Hi, I hava a similar problem than yours - can you tell me how you sorted out yer's?

  • JTable with custom column model and table model not showing table header

    Hello,
    I am creating a JTable with a custom table model and a custom column model. However the table header is not being displayed (yes, it is in a JScrollPane). I've shrunk the problem down into a single compileable example:
    Thanks for your help.
    import javax.swing.*;
    import javax.swing.table.*;
    public class Test1 extends JFrame
         public static void main(String args[])
              JTable table;
              TableColumnModel colModel=createTestColumnModel();
              TestTableModel tableModel=new TestTableModel();
              Test1 frame=new Test1();
              table=new JTable(tableModel, colModel);
              frame.getContentPane().add(new JScrollPane(table));
              frame.setSize(200,200);
              frame.setVisible(true);
         private static DefaultTableColumnModel createTestColumnModel()
              DefaultTableColumnModel columnModel=new DefaultTableColumnModel();
              columnModel.addColumn(new TableColumn(0));
              return columnModel;
         static class TestTableModel extends AbstractTableModel
              public int getColumnCount()
                   return 1;
              public Class<?> getColumnClass(int columnIndex)
                   return String.class;
              public String getColumnName(int column)
                   return "col";
              public int getRowCount()
                   return 1;
              public Object getValueAt(int row, int col)
                   return "test";
              public void setValueAt(Object aValue, int rowIndex, int columnIndex)
    }Edited by: 802416 on 14-Oct-2010 04:29
    added                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    Kleopatra wrote:
    jduprez wrote:
    See http://download.oracle.com/javase/6/docs/api/javax/swing/table/TableColumn.html#setHeaderValue(java.lang.Object)
    When the TableColumn is created, the default headerValue  is null
    So, the header ends up rendered as an empty label (probably of size 0 if the JTable computes its header size based on the renderer's preferred size).nitpicking (can't resist - the alternative is a cleanup round in some not so nice code I produced recently <g>):
    - it's not the JTable's business to compute its headers size (and it doesn't, the header's the culprit.) *> - the header should never come up with a zero (or near-to) height: even if there is no title shown, it's still needed as grab to resize/move the columns. So I would consider this sizing behaviour a bug.*
    - furthermore, the "really zero" height is a longstanding issue with MetalBorder.TableHeaderBorder (other LAFs size with the top/bottom of their default header cell border) which extends AbstractBorder incorrectly. That's easy to do because AbstractBorder itself is badly implemented
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6459419
    Thanks for the opportunity to have some fun :-)
    JeanetteNo problem, thanks for the insight :)

  • RH 10 issue with Fixed Column width

    Hi,
    Is anybody else having issues with setting a fix width for a column in a table?  In RH v.10 the "fixed widths" are not staying "fixed" as I have them manually set.
    I've recently been upgraded from Robohelp (html) v.8 to v.10. 
    In a "Design" view in v.8.0 when I set a column width from the right click menu (AutoFit > Fixed Column Width), the width of the column would be whatever width I'd set it to.  Now, in v.10, the width is whatever width the Robohelp window is set to!  For example, I have a large monitor and I've got Robohelp open in Full Screen mode, the table (a 1-cell table) gets set to the width of the window rather than the particular width I want to use!  I want the cell to be a particular width (much less than my monitor or the open window's width).  Can someone please tell me what I am doing wrong?
    OS=Windows7.
    Browser=IE9
    Robohelp is installed locally (it is not being run over a network).
    Thanks!
    P.S. So far this is the only issue I've had after upgrading from RH v.8 to RH v.10.

    Hi William,
    In a "Design" view in v.10, the table (which is 1 cell) looks like a big rectangular box.  I've turned off the border (cell or table border), so the border appears in gray. 
    Put mouse focus on this 1-cell table, then grab an edge with the mouse. 
    Move the table inward to make the column narrower in the view.
    Then from the right click menu, choose AutoFit > Fixed Column Width.
    Voilá - the width is back to the width of the display window.
    Did that make sense to you?   Thank you for your help and ideas.
    Cheers,
    Julia

  • Data table with fixed column with

    I have a data table bound to a row set , and I would like the table to have fixed column widths to avoid unpleasant display shifts when paging through it.
    The column component does not have too many properties I can work with (maybe this can be fixed in a future release??). Therefore I tried setting the style property of the output text object inside the column. The result looks good in the IDE, but reverts to variable column widths in the browser. I even tried setting the style property at runtime, with no luck.
    Unfortunately I can't pad the column header with spaces, because output text has the annoying habit of converting any group of more than one blank space character to one char only (by the way, any remedy to that?). Trying to drop a grid or group panel in place of the column header and pad the column title with invisible (i.e. color: white) output texts did not work either...
    Any ideas??
    Thanks,
    Luca

    I took a look at the html encoder for data table and here's a trick you can use:
    Go to your stylesheet (by default resources/stylesheet.css: open the Resources node in the project navigator and double click on stylesheet.css).
    Let's say you want three columns - so add something like the following to the stylesheet:
    .colwidth1 { width: 200px }
    .colwidth2 { width: 400px }
    .colwidth3 { width: 300px }
    Save the stylesheet (ctrl-S).
    Now, back in the designer, right click and select "Refresh" to ensure that the new stylesheet edits are discovered.
    Then go to the designer surface, and select the data table (make sure it's selected, not one of its children like columns or output texts - if so hit Escape to pop to parent, or just click on it directly in the app outline.)
    Go to the "columnClasses" property in the property sheet - and enter "colwidth1, colwidth2, colwidth3". Note - no dots here. If you have more than 3 columns you would obviously add additional columns here.
    The table should now use the desired column widths - including the browser.

  • Scrollable table with fixed column headings problem

    Dear list members,
    A while ago I asked on this forum for a way to code a
    scrollable table with fixed headings and I was kindly given the
    HTML and CSS code to do that. Using the method I was given I coded
    the following simple test case. It works under IE but under
    Netscape the column headings scroll up instead of remaining fixed.
    The code works fine in IE. Can anyone tell me what I'm doing wrong
    or if there is a workaround.
    Thanks,
    Harry

    The method you were given will only work in IE because only
    IE understands
    "expression" in CSS rules.
    I'm afraid things are going to be a little more complicated
    for you, but
    it's not impossible.
    Give this method a shot:
    http://www.imaputz.com/cssStuff/bulletVersion.html
    "harryspier" <[email protected]> wrote in
    message
    news:e53s1a$dv9$[email protected]..
    > <style>
    > div .headings {position:relative;
    > top:expression(this.offsetParent.scrollTop);}
    > </style>

  • Creating a JTable with resizeable columns and Horizontal Scrollbar

    Hi,
    I would like to create a JTable with about 24 columns in it. The problem is, my ViewPort in my JScrollPane is about 3-400pixels wide, and the JTable tries to cram itself into the ViewPort. This makes the columns too tiny to read. I'd like it to do something a little more sensible, like use the PreferredSize of the columns. Can anyone point me in the right direction to keep JTable from creating scrunched up little columns, so that it creates columns that are at least partially readable? Thanks.
    BTW, I suppose I could set NO_AUTO_RESIZE but I would rather not do that. I like being able to resize columns. Basically what I want to do is control the JTable's width and not worry about the ViewPort's width.

    This made it impossible to resize columns. Works fine for me:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableHorizontal extends JFrame
        public TableHorizontal()
            JTable table = new JTable(5, 10);
            table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
            JScrollPane scrollPane = new JScrollPane( table );
            getContentPane().add( scrollPane );
            table.getColumnModel().getColumn(0).setPreferredWidth(10);
            table.getColumnModel().getColumn(1).setPreferredWidth(20);
            table.getColumnModel().getColumn(2).setPreferredWidth(30);
            table.getColumnModel().getColumn(3).setPreferredWidth(40);
            table.getColumnModel().getColumn(4).setPreferredWidth(50);
        public static void main(String[] args)
            TableHorizontal frame = new TableHorizontal();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setVisible(true);
    }

  • ALV printed in batch with fixed columns

    Hi,
    I am trying to print an ALV List report in a batch job. Fixed column widths and a filter on the layout was a requirement, so I have a layout variant as part of the initial selection screen and my batch variant.
    When I print online, it looks great. When I print through batch, the font is much bigger and the rows wrap. Is there a way to print using a layout variant for ALV list in batch?
    Thanks!

    Hi,
    When you execute an ALV List through a Job, the Output Settings are determined by the Printer settings that are set for the Output device that you have selected while creating the backgorund job. so i suggest you will have to look at those settings and make the changes occordingly or change the output device that you select.
    regards,
    Mahesh

  • PDF Export with fixed column widths ignores page break on Analysis item

    Hi experts,
    we use the column width modification to define fixed column width in a analysis item. On the same Web template we want to export the whole template including the analysis item to PDF format. First of all everything worked properly, but the fixed widths have not been applied to the PDF. According to [SAP Support Note 1336188|https://service.sap.com/sap/support/notes/1336188] and additional explainations from [SDN Thread 1558536|Column Width Modification not working in Print Version; we solved the problem.
    Unfortunately another problem arises. Our Analysis item delivers a big number of rows which extent multiple pages. By applying the export fix width parameter all page breaks are ignored, meaning that the analysis item is never shown completely in the PDF. We tried all parameter options of the Export Function without success. It seems that the EXPORT_FIX_WIDTH is just working for analysis items, which fit on one single page by length.
    Any ideas how to solve this?
    FYI, our XHTML code (Version SAP BW 7.0 SP 19):
    <bi:ANALYSIS_ITEM name="ANALYSIS_ITEM_1">
    <bi:DATA_PROVIDER_REF value="DP_1" />
    <bi:MODIFICATION type="CHOICE" value="MOD_SINGLE_MODULE" >
      <bi:MOD_SINGLE_MODULE type="COMPOSITE" index="1" >
      <bi:ACTIVE value="X" />
      <bi:MOD_SELECT type="CHOICE" value="MOD_GENERIC_MODULE" >
      <bi:MOD_GENERIC_MODULE type="COMPOSITE" >
      <bi:MOD_REFERENCE value="com.sap.ip.bi.rig.ColumnWidth" />
      <bi:MOD_PARAMETER_LIST type="ORDEREDLIST" >
        <bi:MOD_PARAMETER type="COMPOSITE" index="1" >
          <bi:MOD_PARAM_NAME value="COLUMN_DEFAULT" />
          <bi:MOD_PARAM_VALUE type="CHOICE" value="INTEGER" >
            <bi:INTEGER value="50" />
          </bi:MOD_PARAM_VALUE>
        </bi:MOD_PARAMETER>
        <bi:MOD_PARAMETER type="COMPOSITE" index="2" >
          <bi:MOD_PARAM_NAME value="EXPORT_FIX_WIDTH" />
          <bi:MOD_PARAM_VALUE type="CHOICE" value="BOOLEAN" >
            <bi:BOOLEAN value="X" />
          </bi:MOD_PARAM_VALUE>
        </bi:MOD_PARAMETER>
      </bi:MOD_PARAMETER_LIST>
      </bi:MOD_GENERIC_MODULE>
      </bi:MOD_SELECT>
      </bi:MOD_SINGLE_MODULE>
    </bi:MODIFICATION>
    </bi:ANALYSIS_ITEM>
    Any help and comments will be appreciated. Thank you!
    Best regards,
    Sebastian

    Thank you!
    Unfortunately I didn't find any work around.
    Thanks,
    Federico

  • Internal Order settlment with Fixed amount

    Hi. I'm having hard time. Please help me out.
    Requirement:
    I need to create settlement rule for Internal order.
    When I do so, I need to define Fixed amount in OBJECT CURRENCY.
    Given Condition:
    Object Currency and Contorolling Area Currency is DIFFERENT.
    (Controlling area currency is EURO, while Object currency is country local currency.)
    Problem that I'm facing now:
    When I try to create a settlement rule, it allows only Controlling area currency
    for fixed amount, even though I need to create it with Object currency.
    (Directly, the Field name is indicated as "Amount in EUR".
    You know, usually we have 2 fields; 1 for value, 1 for currency. But in this case,
    it seems that we have only 1 field for 1 fixed currency, which is Controlling area currency)
    Is there any way to solve this issue?
    I've looked into Settlement profile and Investment profile (for AuC order),
    but both of configuration just had an indicator to enable fixed amount settlement,
    but nothing about currency.

    There is not a perfect solution, however you can check OSS note 769818 for some helpful hints.  It sounds like you want to use this for settlment of investment measures.  If that's the case, you may want to consider using line item settlment intead of summary settlement.  You have a little more flexible with that type of settlement and it may get you closer to what you want.
    thanks,

  • Grid with fixed column widths

    Hi Folks,
    I have a grid in which I want to prevent the user to move the set column widths, because this grid has a separate graphik on top of it which would then cease to correspond with the grid columns.
    My question: is there any means of difining a grid with <u><b>non-resizeble columns</b>?</u>
    Thanks & Regards
    Fouad
    Message was edited by: Fouad Sebbane

    Hi
    In the below structure ,set bold field as 'X' for columns u wish to keep fixed.
    Fieldcat
    types: begin of slis_fieldcat_main0,
             row_pos        like sy-curow, " output in row
             col_pos        like sy-cucol, " position of col
             fieldname      type slis_fieldname,
             tabname        type slis_tabname,
             currency(5)    type c,
             cfieldname     type slis_fieldname, " currency
             ctabname       type slis_tabname,   " and table
             ifieldname     type slis_fieldname, " initialcol
             quantity(3)    type c,
             qfieldname     type slis_fieldname, " qty
             qtabname       type slis_tabname,   " and table
             round          type i," round in write statement
             exponent(3)       type c,  " exponent for floats
             key(1)         type c,   " column with key-color
             icon(1)        type c,        " as icon
             symbol(1)      type c,        " as symbol
             checkbox(1)    type c,        " as checkbox
             just(1)        type c,  " (R)ight (L)eft (C)ent.
             lzero(1)       type c,        " leading zero
             no_sign(1)     type c,        " write no-sign
             no_zero(1)     type c,        " write no-zero
             no_convext(1)  type c,
             edit_mask      type slis_edit_mask,            
             emphasize(4)   type c,        " emphasize
       <b>fix_column</b>(1)   type c,       " Spalte fixieren
             do_sum(1)      type c,        " sum up
             no_out(1)      type c,   " (O)blig.(X)no out
             tech(1)        type c,        " technical field
             outputlen      like dd03p-outputlen,
             offset         type dd03p-outputlen,     "offset
             seltext_l      like dd03p-scrtext_l, " long key
             seltext_m      like dd03p-scrtext_m, " middle
             seltext_s      like dd03p-scrtext_s, " short
             ddictxt(1)     type c,        " (S)hort (M)
             rollname       like dd03p-rollname,
             datatype       like dd03p-datatype,
             inttype        like dd03p-inttype,
             intlen         like dd03p-intlen,
             lowercase      like dd03p-lowercase,
           end of slis_fieldcat_main0.
    Regards,
    Raj

  • Scroll option with fixed column

    Dear Friends,
                            Here i have a table which contains more than 37 column to display the employee attendance and shift details in MSS application ,
    Im facing a problem with Scrollable  option . first four column of the table is basic details that field should be fixed position rest of the field need to be Scrollable . This is existing application they have used normal table elements instead of ALV , how i can bring this Scrollable option in norma table UI elements itself . Please view my attached image for better understanding .
    Thank you Guys

    Hi,
    Click on the table UI, and under properties, set the scrollableColCount to 10 ( or any value, so that the first 10 values will  be displayed and enables a scroll bar for remaining columns).
    Then click on the column and set the fixedPosition to 'Left', for the columns you want to freeze. so that those will be fixed and will allow other columns to scroll.
    hope this helps,
    Regards,
    Kiran

  • Prob with fixed column widths and word wrapping in viewer

    i have a report where each record has a very long paragraph of text in it.
    In desktop and plus, the text column is at a fixed width and the text just wraps nicely according to the column width.
    But in Viewer, the column widths do not stay fixed, the text does not wrap, and the long text is displayed in a single line that completely stretches the column width off the page and requires a horizontal scroll bar.
    is there anyway to fix the column width in viewer, have the text naturally wrap, and prevent the column stretching. All word wrapping settings are on, but seem to have no effect. I can't seem to find any solution to this.
    Thanks...

    Hi Pritam,
    Per my understanding that you can't see the vertical scrollbar of the ReportViewer controls 2012 to scroll for the grid rows, but can see the vertical scrollbar of the web application, you also can't fix the headers while scrolling, right?
    I have tested on my local environment and can't reproduce your issue, but you have an alternative way to add some css  to the web form's source code to display the vertical scrollbar.
    Details information below for your reference:
    Please check below properties setting of the reportviewer which control the visibility of the scrollbar:
    AsyncRendering="true"
    SizeToReportContent="false"
    Please check if this problem also occur on other version of IE and other type of browser.
    Please check if you have done correct setting of the Fix data to freeze the table header as the step of below:
    http://technet.microsoft.com/en-us/library/bb934257(v=sql.100).aspx
    If step1 doesn't work, please click the source of webform.aspx and add below CSS to add the vertical scrollbar manually:
    #ReportViewer1 {
              overflow-y: scroll;
    Run the application you will see it display as below:
    Similar thread for your reference:
    https://social.msdn.microsoft.com/forums/sqlserver/en-US/f96b3b56-e920-411b-82ea-40467c922e66/reportviewer-control-vertical-scroll-bars
    If you still have any problem, please feel free to ask.
    Regards
    Vicky Liu

  • JTable with JComboBox/JSpinner problem

    The following code has a JTable with 2 columns.The lst column has JComboBoxes, the 2nd column has JSpinners.I want to set the spinner range of values based on the selection of JComboBox. The JComboBox selections are "small" and "large". For "small" the spinner should range from 0..49, for "large" from 50..99. When a selection is made, MyTable.itemStateChanged() is called, which in turn calls SpinnerEditor.setValueRange(). This sets an array with the desired values and then sets the model with this array. However, it sets the range not only for the row in which the combo box was clicked, but all rows.
    So in MyTable.setCellComponents(), there is this:
    spinnerEditor = new SpinnerEditor(this, defaultTableModel);
    modelColumn.setCellEditor(spinnerEditor);
    If the table has n rows, are n SpinnerEditors created, or just 1?
    If 1, do n need to be created and if so, how?
    public class MyTable extends JTable implements ItemListener {
         private DefaultTableModel defaultTableModel;
         private Vector<Object> columnNameVector;
         private JComboBox jComboBox;
         private SpinnerEditor spinnerEditor;
         private final int COMBO_BOX_COLUMN = 0;
         final static int SPINNER_COLUMN = 1;
         public static String SMALL = "Small";
         public String LARGE = "Large";
         private final String[] SMALL_LARGE = {
                   SMALL,
                   LARGE };
         public MyTable(String name, Object[][] variableNameArray, Object[] columnNameArray) {
              columnNameVector = new Vector<Object>();
              // need column names in order to make copy of table model
              for (Object object : columnNameArray) {
                   columnNameVector.add(object);
              defaultTableModel = new DefaultTableModel(variableNameArray, columnNameArray);
              this.setModel(defaultTableModel)     ;
              setCellComponents();
              setListeners();
         private void setCellComponents() {
              // combo box column -----------------------------------------------
              TableColumn modelColumn = this.getColumnModel().getColumn(COMBO_BOX_COLUMN);
              jComboBox = new JComboBox(SMALL_LARGE);
              // set default values
              for (int row = 0; row < defaultTableModel.getRowCount(); row++) {
                   defaultTableModel.setValueAt(SMALL_LARGE[0], row, COMBO_BOX_COLUMN);
              modelColumn.setCellEditor(new DefaultCellEditor(jComboBox));
              DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
              renderer.setToolTipText("Click for small/large"); // tooltip
              modelColumn.setCellRenderer(renderer);
              // index spinner column ------------------------------------------------------------
              modelColumn = this.getColumnModel().getColumn(SPINNER_COLUMN);
              spinnerEditor = new SpinnerEditor(this, defaultTableModel);
              modelColumn.setCellEditor(spinnerEditor);
              renderer = new DefaultTableCellRenderer();
              renderer.setToolTipText("Click for index value"); // tooltip
              modelColumn.setCellRenderer(renderer);
         private void setListeners() {
              jComboBox.addItemListener(this);
         @Override
         public void itemStateChanged(ItemEvent event) {
              // set spinner values depending on small or large
              String smallOrLarge = (String)event.getItem();
              if (this.getEditingRow() != -1 && this.getEditingColumn() != -1) {
                   spinnerEditor.setValueRange(smallOrLarge);
         public static void main(String[] args) {
              try{
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              catch (Exception e){
                   e.printStackTrace();
              String[] columnNameArray = {"JComboBox", "JSpinner"};
              Object[][]  dataArray = {
                        {"", "0"},
                        {"", "0"},
                        {"", "0"},
              final MyTable myTable = new MyTable("called from main", dataArray, columnNameArray);
              final JFrame frame = new JFrame();
              frame.getContentPane().add(new JScrollPane(myTable));
              frame.setTitle("My Table");
              frame.setPreferredSize(new Dimension(200, 125));
              frame.addWindowListener(new WindowAdapter(){
                   @Override
                   public void windowClosing(WindowEvent e) {
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setLocation(800, 400);
              frame.pack();
              frame.setVisible(true);
    public class SpinnerEditor extends AbstractCellEditor implements TableCellEditor {
         private JComponent parent;
         private DefaultTableModel defaultTableModel;
         private final JSpinner spinner = new JSpinner();
         private String[] spinValues;
         private int row;
         private int column;
         public SpinnerEditor(JTable parent, DefaultTableModel defaultTableModel ) {
              super();
              this.parent = parent;
              this.defaultTableModel = defaultTableModel;
              setValueRange(MyTable.SMALL);
              // update every time spinner is incremented or decremented
              spinner.addChangeListener(new ChangeListener(){
                   public void stateChanged(ChangeEvent e) {
                        String value = (String) spinner.getValue();
                        System.out.println ("SpinnerEditor.stateChanged(): " + value);
                        setValue(value);
         private void setValue(String value) {
              // save to equation string
              System.out.println ("SpinnerEditor.setValue(): " + value + " at (" + row + ", " + MyTable.SPINNER_COLUMN + ")");
              ((JTable) parent).setValueAt(spinner.getValue(), this.row, this.column);
         @Override
         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)      {
              System.out.println ("SpinnerEditor.getTableCellEditorComponent(): row: " + row + "\tcolumn: " + column);
              System.out.println ("SpinnerEditor.getTableCellEditorComponent(): value: " + value);
              this.row = row;
              this.column = column;
              return spinner;
         @Override
         public boolean isCellEditable(EventObject evt) {
              return true;
         // Returns the spinners current value.
         @Override
         public Object getCellEditorValue() {
              return spinner.getValue();
         @Override
         public boolean stopCellEditing() {
              System.out.println("SpinnerEditor.stopCellEditing(): spinner: " + spinner.getValue() + " at (" + this.row + ", " + this.column + ")");
              ((JTable) parent).setValueAt(spinner.getValue(), this.row, this.column);
              return true;
         public void setValueRange(String smallOrLarge) {
              System.out.println ("SpinnerEditor.setValueRange for " + smallOrLarge);
              final int ARRAY_SIZE = 50;
              if (MyTable.SMALL.equals(smallOrLarge)) {
                   final int MIN_SPIN_VALUE = 0;               
                   final int MAX_SPIN_VALUE = 49;
                   //System.out.println ("SpinnerEditor.setValueRange(): [" + MIN_SPIN_VALUE + ".." +  MAX_SPIN_VALUE + "]");
                   spinValues = new String[ARRAY_SIZE];
                   for (int i = MIN_SPIN_VALUE; i <= MAX_SPIN_VALUE; i++) {
                        spinValues[i] = new String(Integer.toString(i));
              else { // large
                   final int MIN_SPIN_VALUE = 50;               
                   final int MAX_SPIN_VALUE = 99;
                   //System.out.println ("SpinnerEditor.setValueRange(): [" + MIN_SPIN_VALUE + ".." +  MAX_SPIN_VALUE + "]");
                   spinValues = new String[ARRAY_SIZE];
                   for (int i = 0; i <ARRAY_SIZE; i++) {
                        spinValues[i] = new String(Integer.toString(MIN_SPIN_VALUE + i));
                   //for (int i = 0; i <ARRAY_SIZE; i++) {
                   //     System.out.println ("spinValues[" + i + "] = " + spinValues);
              System.out.println ("SpinnerEditor.setValueRange(): [" + spinValues[0] + ".." + spinValues[ARRAY_SIZE-1] + "]");
              // set model
              spinner.setModel(new SpinnerListModel(java.util.Arrays.asList(spinValues)));

    However, it sets the range not only for the row in which the combo box was clicked, but all rows. Yes, because a single editor is used by the column.
    One solution is to create two editors, then you override the getCellEditor(...) method to return the appropriated editor. Something like:
    If (column == ?)
        if (smallOrLarge)
          return the small or large spinner editor
        else
           return the large spinner editor
    else
        return super.getCellEditor(...);

  • JTable without headers - column resizing

    I have a simple problem: a JTable with 3 columns, and NO HEADERS.
    I want the middle column ONLY to be resized when the WINDOW is resized. The other two columns should remain of fixed size.
    Is there a simple answer?
    Many thanks for any help,
    george33

    Thank you Thomas for your prompt reply. I have eliminated the headers and automatic resizing using:
    myTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    JTableHeader th=myTable.getTableHeader();
    th.setReorderingAllowed(false);
    th.setResizingAllowed(false);
    jth.setPreferredSize(new Dimension(0, 0)); //remove headers
    This works fine as far as eliminating resizing of all columns and removing the headers.
    What I cannot work out is how to ensure that only the middle column is resized when the window is resized.
    You refer to a component listener. Which componenent should I attach the listener to?
    How can I make two columns of fixed size and one of variable size, and only when the window is resized?
    thanks for your help
    George33

Maybe you are looking for

  • When downloading, a RED astrick appears as file catches download WHAT IS THIS????

    NOT JUST FIREFOX anything i try to download! i am no expert thats for sure so HELP!!

  • TRYING TO REPLY TO PREVIOUS ANSWER TO MY PROBLEM

    I have been trying to reply to an answer I got to a question I posted the first of the month.  When I replied to the message "eidnolb" sent me on March 5, it came back No Such Address."  I have been unable to find my question in the forum list anywhe

  • Preventing the stupid itunes folder!

    I love everything about itunes, except the fact the it duplicates your music and puts the duplicates in an own itunes folder in my music. I don't want this, so how can I prevent it?

  • Swc files not loading after Air overlay

    I needed to update air to 3.6 for use with Flash Builder. I overlayed the newest Air SDK with a copy of Flex 4.6.0. Now, when I try to create any new Flex projects, none of the core swc files will load. For example this error: "unable to load SWC ._a

  • Adding Flash animation to dreamweaver

    Hi, I've created a Flash animation as the first thing to show on my webpage in the index page. And it takes the whole screen. And it contains links in the flash animation. How can I link the links in Flash to the pages in dw? Thanks a lot! Esther