Row-based table in Swing

I'm looking for a table that has a different class per row instead of per column, so when I pull in the data I can check what class it is and store it as such. I've been trying to override the table model, but I can't see any easy way to do this using the getColumnClass(int columnIndex) method in DefaultTableModel.

Internally, JTable only considers the possibility that a column will hold only one class.
Fortunately, JTable uses the method getCellEditor(int, int) to determine a TableCellEditor
for a particular cell. Here is a tip, how we can override that method to extend the functionality
and allow TableCellEditors to be based on the row index:
[Java Tip 102: Add multiple JTable cell editors per column|http://www.javaworld.com/javaworld/javatips/jw-javatip102.html]

Similar Messages

  • Insert new rows based on user selection on a table display on the screen

    Hi..
    In my requirement i need to display the line items of a PO# to the user on the screen for specific fields. Each row should also include an additonal checkbox when displayed for the user. When the user checks this check box or clicks on it a new row should be inserted below to that row with the existing data of that row being copied to newly inserted row and allowing the user to make any changes.
    The newly inserted row should also include a check box , so that when the user checks it again a new row should get inserted. Finally what ever data user enters on the screen, i should be able to update my internal table with those new values and records.
    Appreciate if anyone can guide me on how to proceed on this or any alternative approaches.
    Will reward helpful answers.
    Thanks.

    Hi ..
    Can you please be more detailed. First I need to know how to create the initial table display for the existing line items and then the techniques for inserting the new rows based on the check marks and finally add those news rows to my existing internal table..
    Appreciate ur help.
    Thanks.

  • Add row based on previous row in table control?

    Dear all,
    I have a table control with some rows. Every row contains one button. On button click i want to add another row with dirrerent data. I want to add content based on button text or another columns (ex text views text,) based on this text view, I have to add row. One button can click any no of times. On every click i want to add row, but desired position and content should be based on button click.  Any help in doing this??
    Cheers,
    Venkys.

    Refer to these old threads referring this table and button problem.
    Adding rows to table
    How to create different rows in table or in ALV?
    and for the current scenario what you can do is ...
    in the eventhandler of the button click .
    find out the row number by using the code to read index.
    then based upon that add the element in the node at the desired position.
    finding the row number
      data indx type i.
          DATA lo_el TYPE REF TO if_wd_context_element.
          lo_el = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).
    indx = lo_el->get_index( ).
    and the adding the element at the desired position say n
        DATA lo_nd_zdealer TYPE REF TO if_wd_context_node.
        lo_nd_zdealer = wd_context->get_child_node( name = 'DEALER' ).
    data ls_str type  wd_this->element_dealer.
       ls_str-id = '00023445'.
       ls_str-name = 'sarbjeet'.
       ls_str-location = 'hosiarpur'.
       ls_str-status = '0001'.
       lo_nd_zdealer->bind_structure( new_item = ls_str
       set_initial_elements = abap_false
       index = n
    thanks
    sarbjeet singh

  • Why there is a huge difference between a row size on a disk based table and a row size in memoptimized table of SQL 2014?

    Hi All,
    I have two table with similar structure and data, one is on disk and the other is in memory. I somehow calculated the difference between a row size of on disk and in memory table and found that the row size of in memory is 700 Bytes more than the disk based
    tables.
    aa

    As others mentioned, memory optimized tables and disk based tables have different structures in SQL Server 2014.
    For memory optimized tables, the number of indexes on table also contribute to the size. You can calculate the exact size of rows and thus the table size using the formula given in the below articles
    Table and Row Size in Memory-Optimized Tables
    Estimate the Size of a Table
    Krishnakumar S

  • Coloring individual table rows based on a condition

    Hi Experts,
    I have a table bound to a node in the context via datasource property.
    I was trying to color an individual row based on a certain value in the context node.
    Can anyone help my achieve this please?
    For example:
    for( int i=0; i<table.size(); i++)
        if(wdContext.tableNode().getTableElementAt(i).getFieldA().equals("Y"))
            // then color the table row
    Any suggestions?
    M

    Solved.

  • Table Control - Input Enabling/Diabling of Rows based on Condition.

    Hi,
    In the TC, I want to Input Enable/Disable the rows based on Conditions. The First row is input enabled always. But the other rows, (2nd onwards) need to be Input Enabled/Disabled based on some conditions. It is possible to make this working. Can you please provide me a suitable solution for this?
    Appreciate Your Help.
    Thanks,
    Kannan

    Hi Kannan...
    If we are talking about "Rows"...
    then identify based on some conditions the row numbers and in PBO...loop at screen with screen name..set thier input properties and modify screen (make them input only)
    If we are taking into consideration "columns"
    There is an internal structure COLS where we can identify column number of screen name ...or we can take except for one particular column..
    if some condition satisfied....
    loop at screen where screen-name <> "Column which is input'.
    Loop at screen...and make other columns display only.
    modify screen
    endif.
    Regards
    Byju

  • Deleting rows from table based on value from other table

    Hello Members,
    I am struck to solve the issue said below using query. Would appreciate any suggestions...
    I have two tables having same structures. I want to delete the rows from TableA ( master table ) with the values from TableB ( subset of TableA). The idea is to remove the duplicate values from tableA. The data to be removed are present in TableB. Catch here is TableB holds one row less than TableA, for example
    Table A
    Name Value
    Test 1
    Test 1
    Test 1
    Hello 2
    Good 3
    TableB
    Name Value
    Test 1
    Test 1
    The goal here is to remove the two entries from TableB ('Test') from TableA, finally leaving TableA as
    Table A
    Name Value
    Test 1
    Hello 2
    Good 3
    I tried below queries
    1. delete from TestA a where rowid = any (select rowid from TESTA b where b.Name = a.Name and a.Name in ( select Name from TestB ));
    Any suggestions..
    We need TableB. The problem I mentioned above is part of process. TableB contains the duplicate values which should be deleted from TableA. So that we know what all values we have deleted from TableA. On deleted TableA if I later insert the value from TableB I should be getting the original TableA...
    Thanks in advance

    drop table table_a;
    drop table table_b;
    create table  table_b as
    select 'Test' name, 1 value from dual union all
    select 'Test' ,1 from dual;
    create table table_a as
    select 'Test' name, 1 value from dual union all
    select 'Test' ,1 from dual union all
    select 'Test' ,1 from dual union all
    select 'Hello' ,2 from dual union all
    select 'Good', 3 from dual;
    /* Formatted on 11/23/2011 1:53:12 PM (QP5 v5.149.1003.31008) */
    DELETE FROM table_a
          WHERE ROWID IN (SELECT rid
                            FROM (SELECT ROWID rid,
                                         ROW_NUMBER ()
                                         OVER (PARTITION BY name, VALUE
                                               ORDER BY NULL)
                                            rn
                                    FROM table_a a
                                   WHERE EXISTS
                                            (SELECT 1
                                               FROM table_b b
                                              WHERE a.name = b.name
                                                    AND a.VALUE = b.VALUE))
                           WHERE rn > 1);
    select * from table_a
    NAME     VALUE
    Test     1
    Hello     2
    Good     3Edited by: pollywog on Nov 23, 2011 1:55 PM

  • Jtable row-based renderer

    Hi,
    I have a JTable with 6 columns and several rows, and I want to paint the rows depending on the value of a cell in that row.
    I looked at the tutorials, and it seems to me that it's easy to paint a whole column, but not a whole row.
    How can I do this ?
    Thanks

    This was from a project I did. It is a renderer for a sortable/Drag and dropable JTable. Rather specialized but it works for me. You should be able to pull out what you need. It actually will color rows based on two different column values.
    package dndjtable;
      import java.awt.Color;
      import java.awt.Component;
      import java.util.*;
      import java.util.ArrayList;
      import javax.swing.JLabel;
      import javax.swing.JTable;
      import javax.swing.table.TableCellRenderer;
        public class dndTableCellRenderer implements TableCellRenderer {
          private JLabel alabel = new JLabel();
          private final long DAY = 1000 * 60 * 60 * 24;
          private final long FOURDAY = DAY * 4;
          private final long WEEK = DAY * 7;
           * Creates a new dndTableCellRenderer object.
          public dndTableCellRenderer() {
              alabel.setHorizontalAlignment(JLabel.LEFT);
              alabel.setOpaque(true);
          public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                                                         boolean hasFocus, int row, int column) {
              DndTableModel dtm = (DndTableModel)table.getModel();
              if(value == null) {
                  alabel.setText("");
              } else {
                  alabel.setText(String.valueOf(value));
              if(dtm != null) {
                  Object[] data = (Object[])((ArrayList)dtm.getListData()).get(row);
                  if(data != null) {
                      long val = (new Date(String.valueOf(data[7]))).getTime();
                      long now = System.currentTimeMillis();
                      if((now - val) > this.WEEK) {    // one week
                          if(isSelected) {
                              alabel.setBackground(DndJTable.REDCELL);
                              alabel.setForeground(table.getSelectionForeground());
                          } else {
                              alabel.setBackground(DndJTable.LIGHTREDCELL);
                              alabel.setForeground(table.getForeground());
                      } else if( ((String)data[4]).compareTo("0") != 0  ) {    // 4 days
                          if(isSelected) {
                              alabel.setBackground(DndJTable.YELLOWCELL);
                              alabel.setForeground(Color.blue);
                          } else {
                              alabel.setBackground(DndJTable.LIGHTYELLOWCELL);
                              alabel.setForeground(table.getForeground());
                      } else {
                          if(isSelected) {
                              alabel.setBackground(DndJTable.SELECTCOLOR);
                              alabel.setForeground(table.getSelectionForeground());
                          } else {
                              alabel.setBackground(table.getBackground());
                              alabel.setForeground(table.getForeground());
                      if(data[9] != null) {
                          if(isSelected) {
                              alabel.setBackground(DndJTable.GREENCELL);
                              alabel.setForeground(table.getSelectionForeground());
                          } else {
                              alabel.setBackground(DndJTable.LIGHTGREENCELL);
                              alabel.setForeground(table.getForeground());
                      if(column == 4 && ((String)data[4]).compareTo("0") != 0){
                          if(isSelected){
                              alabel.setForeground(Color.lightGray);
                          }else{
                              alabel.setForeground(Color.red);
              return alabel;
      }The colors are only my own versions of light colors. They can be changed to anything you wish.
    I hope this helps. I will answer any questions.
    I also gave a link on your other post to some good example JTable demos.
    regards,
    jarshe

  • Issues while migrating data from a disk based table to a memory optimized table

    Hi All,
    I have a Disk based table with 400000000 rows in it, We are trying to convert it into a memory optimized table.
    We have  already created a memory optimized table with similar structure and trying to import data into this mem optimized table using 'insert into' from the disk table.
    I am trying to Migrate around 10000000 rows at a time,  but I am getting an error 'There is insufficient system memory in resource pool 'default' to run this query.' Altough we have 128 GB RAM on the server and SS is utilizing more than 120 GB RAM.
    Altough the query has been cancelled.
    Wanted to Know how could we migrate the table with the available RAM or do we have increase our RAM?
    aa

    Josh,
    Microsoft's documentation on this subject isn't at its best right now (I believe there will be incremental improvements for better understanding), but here is what I read so far.
    http://msdn.microsoft.com/en-us/library/dn133190.aspx
    "A hash index consists of a collection of buckets organized in an array. A hash function maps
    index keys to corresponding buckets in the hash index."
    Judging by this statement, a hash index is a hash table just like the ones used as work tables for hash operators in queries (hash matching or grouping). Doesn't contain (or include) other columns, i. e. it doesnt store any data.
    "Multiple index keys may be mapped to the same hash bucket."
    This means there is some kind of mapping, but this is not explained in the article above. However...
    http://msdn.microsoft.com/en-us/library/dn282389.aspx
    "For each hash index in the table, each row has an 8-byte address pointer to the next row in the index. Since there are 4 indexes, each row will allocate 32 bytes for index pointers (an 8 byte pointer for each index)."
    Each row (in the table) has a pointer (for every index, 1:1 ratio) that points to a row (also known as bucket) in the hash index. So that is how the aforementioned mapping works huh!
    > What happens if you include a column in two or three different indexes, or is that not allowed?
    My conclusion is that the hash indexes works the same way as a hash worktable, with the addition of the column in the base table that is added to store pointers to the hash index.
    When you create a new index, even if you use the same column twice, a hash table is created, hash calculations are distinctly made for each key and stored on it, and while this is done, the column that is exclusively used for this new index is populated
    with pointers to this index. You can add a given column to the set of keys of different hash indexes as many times as you want. Correct if i'm wrong, I'm also new on this subject :D

  • Count the number of rows based on the values!!!

    Hi all,
    What I am using:
    I am working with a multidimensional database in Visual Studio 2010 using its Data source view and calculation member and dimension usage.
    What I want to do:
    I have a fact table that has five columns(leg(s),hand(s), Head and body,overall) that shows the category of how severe the injury is. Let say for the records all columns never have an empty value(no injury is stated with 'No injury' ) . These five columns
    are connected with a dimension that has all the available values (Category A-E of injury).The overall has the most severe from the other four columns. I want to create a bar chart with five different measure
    values, one for each column, and count the values in those columns. 
    For example : I have a slicer in the excel and a bar chart and the slicer has all the values of the Category of the injury ( Cat a,Cat B, Cat C, ... Cat E, No injury ) and when i select one of them, lets say
    Cat C,  the bar chart should update and show how many Cat C each measurement column has. 
    Example FACT table:
    ID      LEG      HAND    HEAD   BODY OVERALL
    1        No         A           No        No        A
    2        No        D            C          C         C
    3    E         C            D           A         A
    4         E          E           B            C         B
    So if i selected C the bar chart will count   (Leg = 0, Hand = 1, Head = 1, body = 2 and Overall = 1).
    Any ideas ?
    Thanks for the help and the time :) 

    Hi DBtheoN,
    According to your description, you want to create a chart on excel worksheet to count the rows based on the value, right? If in this case, I am afraid this issue is related to Office forum, I am not the expert of Office, you can post the issue on the corresponding
    forum.
    However, this requirement can be done easily on SQL Server Reporting Services. You can using the expression below to count the rows.
    =COUNT(IIF(Fields!LEG.Value=Parameters!TYPE.Value,1,NOTHING))
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to query a row based on its rownum

    Dear all,
    what is the easiest way to query a row based on its rownum? Suppose I have the following query:
    select first_name from employees where rownum<5;
    FIRST_NAME
    Ellen
    Sundar
    Mozhe
    DavidSo Ellen has rownum 1, Sundar 2 and so on. How can I do it if I just want to query a row where Mozhe is the first_name, which is rownum 3?
    Best regards,
    Val

    JS1 wrote:
    Valerie Debonair wrote:
    I was thinking how oracle assign a rownum in a table is by how it populates the rows in the table.Hence a statement "based on its availability". Maybe my way of thinking it's not accurate?
    You are correct, your way of thinking is wholly innaccurate. Something that can easily be confirmed simply by reading the documentation:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns009.htm#i1006297
    okie doke... thanks for the correction

  • Color report rows based on a value in that row

    I would like to Color report rows based on a value in that row.
    For examplle with the "EMP" table:
    I would like job=MANAGER to be red and job=CLERK to be green etc etc
    The other example I found only had the option of one color either the highlight or the default color.
    I am looking for a way to do multiple colors.

    Hi,
    In the row template, you can use #1#, #2#, etc to indicate where a field in the report needs to be output. This does not have to be plain text - ie, you can use it within style tags if you like.
    So, take a query like:
    SELECT EMPNO,
    ENAME,
    DEPTNO,
    DECODE(DEPTNO, 10, 'green', 20, 'red', 30, 'cyan', 'white') BG_COLOUR
    FROM EMPYou get columns 1=empno, 2=ename, 3=deptno and 4=bg_colour. In the row template, you can then do:
    Before Rows setting (sets up the table):
    &lt;table&gt;
    &lt;tr&gt;&lt;td&gt;ID&lt;/td&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Dept&lt;/td&gt;&lt;/tr&gt;After Rows setting (closes the table):
    &lt;/table&gt;Row Template 1 (used for ALL rows):
    &lt;tr style="background-color:#4#;"&gt;&lt;td&gt;#1#&lt;/td&gt;&lt;td&gt;#2#&lt;/td&gt;&lt;td&gt;#3#&lt;/td&gt;&lt;/tr&gt;Then, for every row, the colour that has been calculated using the DECODE function will be used in the style tag to colour the background for the entire row.
    How you determine the colours is up to you. I've used DECODE here, but you could use a field on the DEPT table to hold this and use this in your SQL statement.
    Andy

  • How to show 10 bottom rows instead of showing 10 top rows of table as defau

    A table was created with JTable class and JScrollPane class. If you run the following code, it always shows you the top 10 rows, the scrollbar stays at the right-top by default. However, what I want the program to show is the bottom 10 rows (The table has 30 rows totally) and the scrollbar should stay at the right-bottom as default. I should greatly appreciate it if anybody could tell me how to implement this scenario.
    import javax.swing.JTable;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JComponent;
    import java.awt.*;
    import java.awt.event.*;
    //import java.lang.string.*;
    public class SimpleTableDemo extends JFrame {
    private boolean DEBUG = true;
    public SimpleTableDemo() {
    super("SimpleTableDemo");
    Object[][] data = {
    {"Mary", "Campione",
    "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Huml",
    "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Walrath",
    "Chasing toddlers", new Integer(2), new Boolean(false)},
    {"Mark", "Andrews",
    "Speed reading", new Integer(20), new Boolean(true)},
    {"Mary", "Campione",
    "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Huml",
    "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Walrath",
    "Chasing toddlers", new Integer(2), new Boolean(false)},
    {"Mark", "Andrews",
    "Speed reading", new Integer(20), new Boolean(true)},
    {"Mary", "Campione",
    "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Huml",
    "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Walrath",
    "Chasing toddlers", new Integer(2), new Boolean(false)},
    {"Mark", "Andrews",
    "Speed reading", new Integer(20), new Boolean(true)},
    {"Mary", "Campione",
    "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Huml",
    "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Walrath",
    "Chasing toddlers", new Integer(2), new Boolean(false)},
    {"Mark", "Andrews",
    "Speed reading", new Integer(20), new Boolean(true)},
    {"Mary", "Campione",
    "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Huml",
    "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Walrath",
    "Chasing toddlers", new Integer(2), new Boolean(false)},
    {"Mark", "Andrews",
    "Speed reading", new Integer(20), new Boolean(true)},
    {"Mary", "Campione",
    "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Huml",
    "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Walrath",
    "Chasing toddlers", new Integer(2), new Boolean(false)},
    {"Mark", "Andrews",
    "Speed reading", new Integer(20), new Boolean(true)},
    {"Angela", "Lih",
    "Teaching high school", new Integer(4), new Boolean(false)}
    String[] columnNames = {"First Name",
    "Last Name",
    "Sport",
    "# of Years",
    "Vegetarian"};
    final JTable table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(650, 150));
    if (DEBUG) {
    table.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    printDebugData(table);
    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this window.
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    private void printDebugData(JTable table) {
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    System.out.println("Value of data: ");
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + model.getValueAt(i, j));
    System.out.println();
    System.out.println("--------------------------");
    public static void main(String[] args) {
    SimpleTableDemo frame = new SimpleTableDemo();
    frame.pack();
    frame.setVisible(true);

    Dimension d = table.getSize();
    scrollpane.getViewport().setViewPosition( new Point( 0,
              (int)d.getHeight() ) );This sets it to the end of the table, you might need to edit it to do as you require.
    Mike

  • How to user Error Trigger for mapping - trying to catch row-based errors

    Hello everyone,
    Has anyone managed to use the error trigger for a mapping?
    I created a row based map with the right parameters (i set the error trigger procedure which I already created in the database).
    For this map after run i have 5 warnings which appear in the interface but the error trigger procedure is not executed.
    I set the max errors to 3 so after run the map should end with errors instead of warnings.
    Still not executing the error trigger procedure.
    What am i doing wrong?
    Please help as i really need a way to "catch" row based errors - having multiple target tables sucks.
    Thank you,
    Irina
    Edited by: Irina on Jul 30, 2009 1:32 PM
    Edited by: Irina on Jul 30, 2009 3:38 PM

    It seems nobody knows what I'm talking about - no documentation on it either ... not even in the user guide ... not even on google ... well, just saying what it is doesn't count :D

  • How to select more than one row in a JTable swing adf adf?

    how to select more than one row in a JTable swing adf adf?

    // Allow selection to span one contiguous set of rows, visible columns, or block of cells
    table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    // Allow multiple selections of rows, visible columns, or cell blocks
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

Maybe you are looking for

  • Acrobat XI on MacBook Pro Retina down severely on scrolling PDFs

    Hi all. I've seen lots of threads around the net about slow scrolling on macbook and acrobat pro but having tried a few things I am compelled to ask myself for some help. I have a Retina MacBook Pro 15" from Late 2012 and fully updated Mountain Lion

  • Can i get a refund on a movie i accidentally purchased online

    can i get a refund on a movie i accidentally purchased online

  • Error in Interface Mapping

    Interface Mapping javax.xml.transform.TransformerException: com.sap.engine.lib.xml.parser.ParserException: XML Declaration not allowed here.(:main:, row:1, col:7) at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:251) at com.s

  • Poriblems with Server Side Include

    I amtrying to convert to Spry Menus using SSI. into a template.  been beating my head against the wall on what can go in and what can't in an include fil but that turns out not be my big problem when in using Dredamweaver CS5   and  do a server side

  • Bug in auto-increment for MSSQL

    I am using kodo 3.1.0 and have a scenario where I am persisting a new object that uses an auto-increment PK and the database has an on-insert trigger that inserts a log into an audit table. At the database level, what is happing is: 1) kodo calls "in