Help! coloring background one row for 3 seconds in JTable with SwingTimer

Hi, I am struggling with this for the past three days but cannot come up with a solution.
I have a JTable and when i insert a new Row, i want to give that row a backgroundcolor for 3 seconds/ or let it blink for 3 seconds and then let it return to its original background color. While the current row is yellow, i want to insert a new row which also would be yellow for 3 seconds. The previous row would return white earlier than the row after, because that row is inserted earlier.
the problem is, that when i add a new row while the current row is yellow, the new row has the timer of the previous row, which means that the last row inserted will stay yellow for a shirter time, which i do not want.
i want a 3 second bgcolor for everyrow inserted. how can i achieve this ?
My code:
startBlinking() is called when a new row is being added to the JTable
public void startBlinking() throws InterruptedException{
if (timer.isRunning()){
timer.setInitialDelay(2);
timer.start();
----------------------- in another class:
//attributes
Action updateCursorAction = getAction();
Timer timer = new Timer(3000, updateCursorAction);
public Action getAction(){
updateCursorAction = new AbstractAction() {
boolean shouldDraw = false;
public void actionPerformed(ActionEvent e) {
if (shouldDraw =! shouldDraw) {
blinkingYellow();
} else{
blinkingWhite();
timer.stop();
return updateCursorAction;
public void blinkingWhite(){
receiverdata_Table.setRowSelectionInterval(0, 0);
receiverdata_Table.setSelectionBackground(Color.white);
public void blinkingYellow(){
receiverdata_Table.setRowSelectionInterval(0, 0);
receiverdata_Table.setSelectionBackground(Color.YELLOW);
}

Cant resist to point out the ease of doing something like this in Swingx <g>
Basically, the way to go is
- install a Highlighter with the visual property/ies you want to use for the highlighting effect
- update its HighlightPredicate (aka: condition for applying the property) as appropriate
Below is a code snippet (as usual runnable as-is in the context of SwingX test support). The candy is, that the exact same highlighting code is re-usable in JXList, JXTree and (probably, should check) JXComboBox
Enjoy
Jeanette
* Created on 17.12.2010
package org.jdesktop.swingx.renderer;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.Timer;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.InteractiveTestCase;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.AbstractHighlighter;
import org.jdesktop.swingx.decorator.ColorHighlighter;
import org.jdesktop.swingx.decorator.ComponentAdapter;
import org.jdesktop.swingx.decorator.HighlightPredicate;
public class DynamicHighlighterExperiments extends InteractiveTestCase {
    public void interactiveHighlightOnInsert() {
        final JXTable table = new JXTable(10, 4);
        final ColorHighlighter hl = new ColorHighlighter(HighlightPredicate.NEVER,
                Color.YELLOW,  null);
        table.addHighlighter(hl);
        final List<Integer> recentRows = new ArrayList<Integer>();
        ActionListener l = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int insertedRow = table.getModel().getRowCount();
                recentRows.add(insertedRow);
                ((DefaultTableModel) table.getModel()).addRow(new Object[] {insertedRow});
                table.scrollRowToVisible(table.convertRowIndexToView(insertedRow));
                updateHighlighter(hl, recentRows, insertedRow);
        Timer insertTimer = new Timer(500, l);
        insertTimer.start();
        showWithScrollingInFrame(table, "highlight inserted rows");
    protected void updateHighlighter(final AbstractHighlighter hl,
            final List<Integer> recentRows, final Integer row) {
        hl.setHighlightPredicate(new RowHighlightPredicate(recentRows));
        ActionListener l = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                recentRows.remove(row);
                hl.setHighlightPredicate(new RowHighlightPredicate(recentRows));
                ((Timer) e.getSource()).stop();
        Timer removeTimer =  new Timer(1500, l);
        removeTimer.setRepeats(false);
        removeTimer.start();
    // PENDING JW: move into swingx zoo of predicates
    public static class RowHighlightPredicate implements HighlightPredicate {
        List<Integer> rows;
        public RowHighlightPredicate(Collection<Integer> row) {
           rows = new ArrayList<Integer>(row);
        @Override
        public boolean isHighlighted(Component renderer,
                ComponentAdapter adapter) {
            int modelRow = adapter.convertRowIndexToModel(adapter.row);
            return rows.contains(modelRow);
    public static void main(String[] args) {
        DynamicHighlighterExperiments test = new DynamicHighlighterExperiments();
        try {
            test.runInteractiveTests();
        } catch (Exception e) {
            e.printStackTrace();
}

Similar Messages

  • Display only one row for distinct columns and with multiple rows their valu

    Hi,
    I have a table having some similar rows for some columns and multiple different rows for some other columns
    i.e
    o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status
    9825000111 01-jan-06 'a' 980515464 01-feb-06 c
    9825000111 01-jan-06 'a' 991543154 02-feb-06 d
    9825000111 01-jan-06 'a' 154845545 10-mar-06 a
    What i want is to display only one row for above distinct row along with multiple non distinct colums
    ie
    o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status
    9825000111 01-jan-06 'a' 980515464 01-feb-06 c
    991543154 02-feb-06 d
    154845545 10-mar-06 a
    regards,
    Kumar

    Re: SQL Help

  • How can I have one row for each object?

    Post Author: farnaz
    CA Forum: WebIntelligence Reporting
    I have 3 objcts that one of them is ID and second one is internal code and the third one is quantity.There is more than one value for each ID (becouse of internal code).I want to create a report based on ID and quantity (not based on internal code).I make a break on ID but the result shows me more than one row for each ID.so how can i have just one row for each ID?
    another question:
    how can I post screen shot of the results to my messag in forum?

    Post Author: jsanzone
    CA Forum: WebIntelligence Reporting
    farnaz:
    Have you tried to omit "internal code" from your grid?  In normal circumstances, if you have "ID" and "Quantity" on the grid, then WebI will on its own summarize Quantity based on ID, however, this is provided that Quantity has been set up as a measure (or metric).  The quickest way to tell if Quantity is a metric or not is to observe the color of its icon when you look at it in the data panel.  If it is a purple (or sometimes appears as pink or fuscia) dot, then it's a measure, but if it is a blue box then it is a dimension.  If you need Quantity as a measure then this will have to be modified at the universe (make it look like "sum(Quantity)" in the select phase of the object, and insure the object is defined as a number....

  • I would like to change my back ground color in one frame for a logo that i am using I am able to change it on the canvas but not on the timeline?

    I would like to change my back ground color in one frame for a logo that i am using I am able to change it on the canvas but not on the timeline?

    Are you using FCPX? It doesn't have a canvas. Do you really mean one frame, like 1/30th of a second? Add a custom generator underneath the logo. Make it whatever color you want. Make it however short you want.

  • Multiple parameters one row for each record

    I have this query I want the user to be able to allow the user to enter multiple MATL_CODE_MOD as a parameters, the problem is that the GURMAIL table have multiple records one for each GURMAIL_MATL_CODE_MOD, so it will give me duplicates.. How I can code this, so I can allow the user to enter multiple MATL_CODE_MOD codes, and have only one row for each record...
    and GURMAIL_MATL_CODE_MOD in ('8IBC','8IBD')
    select
    spriden_id,        
    spbpers_name_suffix   name_suffix,
    spbpers_name_prefix   name_prefix,
    spriden_last_name     last_name,
    spriden_first_name    first_name,
    spriden_mi            mi,
    srbrecr_term_code,
    srbrecr_majr_code,
    srbrecr_program_1,
    saturn_midd.utlq.f_matl_code_type(srbrecr_pidm)
    FROM
    saturn.srbrecr,
    saturn.spriden,
    saturn.spbpers,
    SATURN.SPRADDR,
    general.gurmail
    WHERE
    spriden_pidm = srbrecr_pidm
    and gurmail_pidm = spriden_pidm
    AND spriden_pidm = spraddr_pidm 
    --and srbrecr_term_code = decode(p_term  ,'%',SRBRECR_TERM_CODE,p_term)
    and spbpers_pidm = spriden_pidm
    and spriden_change_ind is null
    --and gurmail_matl_code_mod
    and SRBRECR_PROGRAM_1 = 'CMQ'
    and GURMAIL_MATL_CODE_MOD in ('8IBC','8IBD')
    --AND SPRADDR_ATYP_CODE = 'CM'
    AND SPRADDR_STREET_LINE1 IS NOT NULL;

    Hi,
    SELECT DISTINCT ...will keep duplicate rows out of the result set.
    Depending on your data, another possibility might be to not join the table that contains GURMAIL_MATL_CODE_MOD. Do an EXISTS sub-query on that table instead.
    If you need more help, post some sample data from all the tables, and the results you want from that data.
    Simplify, if possible, You can probably post a problem with 2 or 3 tables, each with 2 or 3 columns, that will have the same answer.
    Edited by: Frank Kulash on Apr 22, 2009 2:28 PM

  • How to change the color background in Pages for iPad?

    how to change the color background in Pages for iPad?

    You can find many themes at https://github.com/hdoria/xcode-themes  There's a download zip button on the right side of the page.
    Unzip and and copy the .dvtcolortheme files into /Users/YourUsername/Library/Developer/XCode/UserData/FontAndColorThemes Create the directory if it doesn't exist.
    If you can't find the Library directory you can get to it by using Finder's "Go to Folder..." option under "Go" or press shift + cmd + G then type the path.

  • Get only one row for each kind of a column

    hi there!
    i have a little problem.
    I have a table with 10 columns. One of them has repeated values. My goal is to get all the rows with this column only one time for each values that it has.
    Ex:
    Col1 Col2 Col3
    A A A
    B B B
    C A C
    D C D
    Column 2 has repeated values. My goal is to get:
    A A A
    B B B
    D C D
    Only one time each value of column 2.
    Thanks guys! ;)

    SQL>  CREATE TABLE Tbl (col1 VARCHAR2(1),col2 VARCHAR2(1),col3 VARCHAR2(1));
    Table created.
    SQL> INSERT INTO Tbl VALUES ('A','A','A');
    1 row created.
    SQL>              INSERT INTO Tbl VALUES ('B','B','B');
    1 row created.
    SQL>              INSERT INTO Tbl VALUES ('C','A','C');
    1 row created.
    SQL>              INSERT INTO Tbl VALUES ('D','C','D');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> SELECT * FROM tbl t1
      2  WHERE
      3  rowid=(SELECT min(rowid)
      4         FROM tbl t2
      5         WHERE t1.col2=t2.col2);
    C C C
    A A A
    B B B
    D C D
    SQL> SELECT * FROM tbl t1
      2  WHERE
      3  rowid=(SELECT max(rowid)
      4         FROM tbl t2
      5         WHERE t1.col2=t2.col2);
    C C C
    B B B
    C A C
    D C DEdited by: Saubhik on Aug 3, 2010 1:31 AM

  • Displaying data in one row for  for 2 tables without relaiton

    I Have 2 tables without any relation and there is a common field and i want to display data like below
    table refdet
    1)
    refdt----------refbr----refamt----refcat
    10-aug-09---10-----34234-----101a
    10-aug-009--11----23245-----102a
    1-AUG-09----10----455.98----104A
    19-aug-09-12-----10000-------103B
    2) brdet
    trdt---------brn-----brtot-----------brcat
    11-aug09--10-----454000-------A
    09-aug-09-12-----550000-------B
    30-sep-09--10-----430000------A
    09-aug-09-11-----550000-------B
    i want to display data for each branch refdet.refbr = brdet.brn
    refdet
    Br10
    refdt----------refbr----refamt----refcat-----trdt---------brn-----brtot-----------brcat
    10-aug-09---10-----34234-----101a-------11-aug09--10-----454000-------A
    1-AUG-09----10----455.98----104A------30-sep-09--10-----430000------A
    Br 11
    10-aug-009--11----23245-----102a -------09-aug-09-11-----550000-------B
    Br12
    19-aug-09-12-----10000-------103B------09-aug-09----12-----550000-------B
    i tried the following query but its not working
    select distinct null as refdt,null as refbr,null as refamt,null as refcat,b.trdt,b.brn,b.brtot,b.brcat
    from brdet a,refdet b
    where a.refbr (+) = b.brn
    union all
    select distinct a.refdt,a.refbr,a.refamt,a.refcat,null as trdt,null as brn,null as brtot,null as brcat
    from brdet a,refdet b
    where a.refbr = b.brn (+)
    its not giving the records on each row for both side its creating separte rows for each records in both table.
    rgds
    jytohi
    -

    Hi jytohi,
    Please lean back for a moment and study your question. Ask yourself, is this a reasonable way to ask a question?
    Jopefully you'll reach the answer, "No it isn't, I need to.."
    1. Turn these
    1)
    refdt----------refbr----refamt----refcat
    2) brdet
    trdt---------brn-----brtot-----------brcatinto CREATE TABLE statements.
    2. Turn these
    10-aug-09---10-----34234-----101a
    10-aug-009--11----23245-----102a
    1-AUG-09----10----455.98----104A
    19-aug-09-12-----10000-------103B
    11-aug09--10-----454000-------A
    09-aug-09-12-----550000-------B
    30-sep-09--10-----430000------A
    09-aug-09-11-----550000-------Binto INSERT INTO statements
    3. Turn this
    refdet
    Br10
    refdt----------refbr----refamt----refcat-----trdt---------brn-----brtot-----------brcat
    10-aug-09---10-----34234-----101a-------11-aug09--10-----454000-------A
    1-AUG-09----10----455.98----104A------30-sep-09--10-----430000------A
    Br 11
    10-aug-009--11----23245-----102a -------09-aug-09-11-----550000-------B
    Br12
    19-aug-09-12-----10000-------103B------09-aug-09----12-----550000-------Binto properly formatted expected output, along with a reasonable explanation of why
    4. Turn this
    select distinct null as refdt,null as refbr,null as refamt,null as refcat,b.trdt,b.brn,b.brtot,b.brcat
    from brdet a,refdet b
    where a.refbr (+) = b.brn
    union all
    select distinct a.refdt,a.refbr,a.refamt,a.refcat,null as trdt,null as brn,null as brtot,null as brcat
    from brdet a,refdet b
    where a.refbr = b.brn (+)into a properly formatted query
    And last, put everything in into curly brackets {noformat}{noformat} to preserve formatting and blank space.
    Best regards
    Peter                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • One model for JTree and JTable

    Hi.
    Is it possible for a JTree and a JTable to share one model?
    Thank you

    Hope u r not using Comonent TreeTable
    If u have Tree & Table different components, just want to have a common model then u can try this,
    It is nothing but default implementation given in DefaultTableModel
    public class MyTreeTableModel extends DefaultTreeModel implements TableModel, Serializable {
    protected Vector dataVector;
    /** List of listeners */
    protected EventListenerList listenerList = new EventListenerList();
    /** The <code>Vector</code> of column identifiers. */
    protected Vector columnIdentifiers;
    public MyTreeTableModel(TreeNode root) {
    this(root, false);
    // constructor for TreeModel only
    public MyTreeTableModel(TreeNode root, boolean asksAllowsChildren) {
    super(root, asksAllowsChildren);
    // constructor for TableModel only
    public MyTreeTableModel() {
    this(0, 0);
    private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
    // constructor for TableModel only
    public MyTreeTableModel(int rowCount, int columnCount) {
    this(newVector(columnCount), rowCount);
    // constructor for TableModel only
    public MyTreeTableModel(Vector columnNames, int rowCount) {
    super(null);
    setDataVector(newVector(rowCount), columnNames);
    // constructor for TableModel only
    public MyTreeTableModel(Object[] columnNames, int rowCount) {
    this(convertToVector(columnNames), rowCount);
    // constructor for TableModel only
    public MyTreeTableModel(Vector data, Vector columnNames) {
    super(null);
    setDataVector(data, columnNames);
    // constructor for TableModel only
    public MyTreeTableModel(Object[][] data, Object[] columnNames) {
    super(null);
    setDataVector(data, columnNames);
    * Returns a default name for the column using spreadsheet conventions:
    * A, B, C, ... Z, AA, AB, etc. If <code>column</code> cannot be found,
    * returns an empty string.
    * @param column the column being queried
    * @return a string containing the default name of <code>column</code>
    private String getDefaultColumnName(int column) {
    String result = "";
    for (; column >= 0; column = column / 26 - 1) {
    result = (char)((char)(column%26)+'A') + result;
    return result;
    * Returns a column given its name.
    * Implementation is naive so this should be overridden if
    * this method is to be called often. This method is not
    * in the <code>TableModel</code> interface and is not used by the
    * <code>JTable</code>.
    * @param columnName string containing name of column to be located
    * @return the column with <code>columnName</code>, or -1 if not found
    public int findColumn(String columnName) {
    for (int i = 0; i < getColumnCount(); i++) {
    if (columnName.equals(getColumnName(i))) {
    return i;
    return -1;
    * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
    * @param columnIndex the column being queried
    * @return the Object.class
    public Class getColumnClass(int columnIndex) {
    return Object.class;
    // Managing Listeners
    * Adds a listener to the list that's notified each time a change
    * to the data model occurs.
    * @param     l          the TableModelListener
    public void addTableModelListener(TableModelListener l) {
    listenerList.add(TableModelListener.class, l);
    * Removes a listener from the list that's notified each time a
    * change to the data model occurs.
    * @param     l          the TableModelListener
    public void removeTableModelListener(TableModelListener l) {
    listenerList.remove(TableModelListener.class, l);
    * Returns an array of all the table model listeners
    * registered on this model.
    * @return all of this model's <code>TableModelListener</code>s
    * or an empty
    * array if no table model listeners are currently registered
    public TableModelListener[] getTableModelListeners() {
    return (TableModelListener[])listenerList.getListeners(
    TableModelListener.class);
    // Fire methods
    * Notifies all listeners that all cell values in the table's
    * rows may have changed. The number of rows may also have changed
    * and the <code>JTable</code> should redraw the
    * table from scratch. The structure of the table (as in the order of the
    * columns) is assumed to be the same.
    public void fireTableDataChanged() {
    fireTableChanged(new TableModelEvent(this));
    * Notifies all listeners that the table's structure has changed.
    * The number of columns in the table, and the names and types of
    * the new columns may be different from the previous state.
    * If the <code>JTable</code> receives this event and its
    * <code>autoCreateColumnsFromModel</code>
    * flag is set it discards any table columns that it had and reallocates
    * default columns in the order they appear in the model. This is the
    * same as calling <code>setModel(TableModel)</code> on the
    * <code>JTable</code>.
    public void fireTableStructureChanged() {
    fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW));
    * Notifies all listeners that rows in the range
    * <code>[firstRow, lastRow]</code>, inclusive, have been inserted.
    * @param firstRow the first row
    * @param lastRow the last row
    public void fireTableRowsInserted(int firstRow, int lastRow) {
    fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
    TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
    * Notifies all listeners that rows in the range
    * <code>[firstRow, lastRow]</code>, inclusive, have been updated.
    * @param firstRow the first row
    * @param lastRow the last row
    public void fireTableRowsUpdated(int firstRow, int lastRow) {
    fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
    TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE));
    * Notifies all listeners that rows in the range
    * <code>[firstRow, lastRow]</code>, inclusive, have been deleted.
    * @param firstRow the first row
    * @param lastRow the last row
    public void fireTableRowsDeleted(int firstRow, int lastRow) {
    fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
    TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
    * Notifies all listeners that the value of the cell at
    * <code>[row, column]</code> has been updated.
    * @param row row of cell which has been updated
    * @param column column of cell which has been updated
    public void fireTableCellUpdated(int row, int column) {
    fireTableChanged(new TableModelEvent(this, row, row, column));
    * Forwards the given notification event to all
    * <code>TableModelListeners</code> that registered
    * themselves as listeners for this table model.
    * @param e the event to be forwarded
    public void fireTableChanged(TableModelEvent e) {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
    if (listeners==TableModelListener.class) {
    ((TableModelListener)listeners[i+1]).tableChanged(e);
    * Returns an array of all the objects currently registered
    * as <code><em>Foo</em>Listener</code>s
    * upon this <code>AbstractTableModel</code>.
    * <code><em>Foo</em>Listener</code>s are registered using the
    * <code>add<em>Foo</em>Listener</code> method.
    * <p>
    * You can specify the <code>listenerType</code> argument
    * with a class literal,
    * such as
    * <code><em>Foo</em>Listener.class</code>.
    * For example, you can query a
    * model <code>m</code>
    * for its table model listeners with the following code:
    * <pre>TableModelListener[] tmls = (TableModelListener[])(m.getListeners(TableModelListener.class));</pre>
    * If no such listeners exist, this method returns an empty array.
    * @param listenerType the type of listeners requested; this parameter
    * should specify an interface that descends from
    * <code>java.util.EventListener</code>
    * @return an array of all objects registered as
    * <code><em>Foo</em>Listener</code>s on this component,
    * or an empty array if no such
    * listeners have been added
    * @exception ClassCastException if <code>listenerType</code>
    * doesn't specify a class or interface that implements
    * <code>java.util.EventListener</code>
    public EventListener[] getListeners(Class listenerType) {
    return listenerList.getListeners(listenerType);
    * Returns the <code>Vector</code> of <code>Vectors</code>
    * that contains the table's
    * data values. The vectors contained in the outer vector are
    * each a single row of values. In other words, to get to the cell
    * at row 1, column 5: <p>
    * <code>((Vector)getDataVector().elementAt(1)).elementAt(5);</code><p>
    * @return the vector of vectors containing the tables data values
    public Vector getDataVector() {
    return dataVector;
    private static Vector nonNullVector(Vector v) {
    return (v != null) ? v : new Vector();
    * Replaces the current <code>dataVector</code> instance variable
    * with the new Vector of rows, <code>dataVector</code>.
    * <code>columnIdentifiers</code> are the names of the new
    * columns. The first name in <code>columnIdentifiers</code> is
    * mapped to column 0 in <code>dataVector</code>. Each row in
    * <code>dataVector</code> is adjusted to match the number of
    * columns in <code>columnIdentifiers</code>
    * either by truncating the <code>Vector</code> if it is too long,
    * or adding <code>null</code> values if it is too short.
    * <p>Note that passing in a <code>null</code> value for
    * <code>dataVector</code> results in unspecified behavior,
    * an possibly an exception.
    * @param dataVector the new data vector
    * @param columnIdentifiers the names of the columns
    public void setDataVector(Vector dataVector, Vector columnIdentifiers) {
    this.dataVector = nonNullVector(dataVector);
    this.columnIdentifiers = nonNullVector(columnIdentifiers);
    justifyRows(0, getRowCount());
    fireTableStructureChanged();
    * Replaces the value in the <code>dataVector</code> instance
    * variable with the values in the array <code>dataVector</code>.
    * The first index in the <code>Object[][]</code>
    * array is the row index and the second is the column index.
    * <code>columnIdentifiers</code> are the names of the new columns.
    * @param dataVector          the new data vector
    * @param columnIdentifiers     the names of the columns
    public void setDataVector(Object[][] dataVector, Object[] columnIdentifiers) {
    setDataVector(convertToVector(dataVector), convertToVector(columnIdentifiers));
    * Equivalent to <code>fireTableChanged</code>.
    * @param event the change event
    public void newDataAvailable(TableModelEvent event) {
    fireTableChanged(event);
    // Manipulating rows
    private void justifyRows(int from, int to) {
    // Sometimes the MyTreeTableModel is subclassed
    // instead of the AbstractTableModel by mistake.
    // Set the number of rows for the case when getRowCount
    // is overridden.
    dataVector.setSize(getRowCount());
    for (int i = from; i < to; i++) {
    if (dataVector.elementAt(i) == null) {
    dataVector.setElementAt(new Vector(), i);
    ((Vector)dataVector.elementAt(i)).setSize(getColumnCount());
    * Ensures that the new rows have the correct number of columns.
    * This is accomplished by using the <code>setSize</code> method in
    * <code>Vector</code> which truncates vectors
    * which are too long, and appends <code>null</code>s if they
    * are too short.
    * This method also sends out a <code>tableChanged</code>
    * notification message to all the listeners.
    * @param e this <code>TableModelEvent</code> describes
    * where the rows were added.
    *                    If <code>null</code> it assumes
    * all the rows were newly added
    public void newRowsAdded(TableModelEvent e) {
    justifyRows(e.getFirstRow(), e.getLastRow() + 1);
    fireTableChanged(e);
    * Equivalent to <code>fireTableChanged</code>.
    * @param event the change event
    public void rowsRemoved(TableModelEvent event) {
    fireTableChanged(event);
    * Obsolete as of Java 2 platform v1.3. Please use <code>setRowCount</code> instead.
    * Sets the number of rows in the model. If the new size is greater
    * than the current size, new rows are added to the end of the model
    * If the new size is less than the current size, all
    * rows at index <code>rowCount</code> and greater are discarded. <p>
    * @param rowCount the new number of rows
    public void setNumRows(int rowCount) {
    int old = getRowCount();
    if (old == rowCount) {
    return;
    dataVector.setSize(rowCount);
    if (rowCount <= old) {
    fireTableRowsDeleted(rowCount, old-1);
    else {
    justifyRows(old, rowCount);
    fireTableRowsInserted(old, rowCount-1);
    * Sets the number of rows in the model. If the new size is greater
    * than the current size, new rows are added to the end of the model
    * If the new size is less than the current size, all
    * rows at index <code>rowCount</code> and greater are discarded. <p>
    public void setRowCount(int rowCount) {
    setNumRows(rowCount);
    * Adds a row to the end of the model. The new row will contain
    * <code>null</code> values unless <code>rowData</code> is specified.
    * Notification of the row being added will be generated.
    * @param rowData optional data of the row being added
    public void addRow(Vector rowData) {
    insertRow(getRowCount(), rowData);
    * Adds a row to the end of the model. The new row will contain
    * <code>null</code> values unless <code>rowData</code> is specified.
    * Notification of the row being added will be generated.
    * @param rowData optional data of the row being added
    public void addRow(Object[] rowData) {
    addRow(convertToVector(rowData));
    * Inserts a row at <code>row</code> in the model. The new row
    * will contain <code>null</code> values unless <code>rowData</code>
    * is specified. Notification of the row being added will be generated.
    * @param row the row index of the row to be inserted
    * @param rowData optional data of the row being added
    * @exception ArrayIndexOutOfBoundsException if the row was invalid
    public void insertRow(int row, Vector rowData) {
    dataVector.insertElementAt(rowData, row);
    justifyRows(row, row+1);
    fireTableRowsInserted(row, row);
    * Inserts a row at <code>row</code> in the model. The new row
    * will contain <code>null</code> values unless <code>rowData</code>
    * is specified. Notification of the row being added will be generated.
    * @param row the row index of the row to be inserted
    * @param rowData optional data of the row being added
    * @exception ArrayIndexOutOfBoundsException if the row was invalid
    public void insertRow(int row, Object[] rowData) {
    insertRow(row, convertToVector(rowData));
    private static int gcd(int i, int j) {
    return (j == 0) ? i : gcd(j, i%j);
    private static void rotate(Vector v, int a, int b, int shift) {
    int size = b - a;
    int r = size - shift;
    int g = gcd(size, r);
    for(int i = 0; i < g; i++) {
    int to = i;
    Object tmp = v.elementAt(a + to);
    for(int from = (to + r) % size; from != i; from = (to + r) % size) {
    v.setElementAt(v.elementAt(a + from), a + to);
    to = from;
    v.setElementAt(tmp, a + to);
    * Moves one or more rows from the inlcusive range <code>start</code> to
    * <code>end</code> to the <code>to</code> position in the model.
    * After the move, the row that was at index <code>start</code>
    * will be at index <code>to</code>.
    * This method will send a <code>tableChanged</code> notification
    * message to all the listeners. <p>
    * <pre>
    * Examples of moves:
    * <p>
    * 1. moveRow(1,3,5);
    * a|B|C|D|e|f|g|h|i|j|k - before
    * a|e|f|g|h|B|C|D|i|j|k - after
    * <p>
    * 2. moveRow(6,7,1);
    * a|b|c|d|e|f|G|H|i|j|k - before
    * a|G|H|b|c|d|e|f|i|j|k - after
    * <p>
    * </pre>
    * @param start the starting row index to be moved
    * @param end the ending row index to be moved
    * @param to the destination of the rows to be moved
    * @exception ArrayIndexOutOfBoundsException if any of the elements
    * would be moved out of the table's range
    public void moveRow(int start, int end, int to) {
    int shift = to - start;
    int first, last;
    if (shift < 0) {
    first = to;
    last = end;
    else {
    first = start;
    last = to + end - start;
    rotate(dataVector, first, last + 1, shift);
    fireTableRowsUpdated(first, last);
    * Removes the row at <code>row</code> from the model. Notification
    * of the row being removed will be sent to all the listeners.
    * @param row the row index of the row to be removed
    * @exception ArrayIndexOutOfBoundsException if the row was invalid
    public void removeRow(int row) {
    dataVector.removeElementAt(row);
    fireTableRowsDeleted(row, row);
    // Manipulating columns
    * Replaces the column identifiers in the model. If the number of
    * <code>newIdentifier</code>s is greater than the current number
    * of columns, new columns are added to the end of each row in the model.
    * If the number of <code>newIdentifier</code>s is less than the current
    * number of columns, all the extra columns at the end of a row are
    * discarded. <p>
    * @param newIdentifiers vector of column identifiers. If
    *                    <code>null</code>, set the model
    * to zero columns
    public void setColumnIdentifiers(Vector columnIdentifiers) {
    setDataVector(dataVector, columnIdentifiers);
    * Replaces the column identifiers in the model. If the number of
    * <code>newIdentifier</code>s is greater than the current number
    * of columns, new columns are added to the end of each row in the model.
    * If the number of <code>newIdentifier</code>s is less than the current
    * number of columns, all the extra columns at the end of a row are
    * discarded. <p>
    * @param newIdentifiers array of column identifiers.
    *                    If <code>null</code>, set
    * the model to zero columns
    public void setColumnIdentifiers(Object[] newIdentifiers) {
    setColumnIdentifiers(convertToVector(newIdentifiers));
    * Sets the number of columns in the model. If the new size is greater
    * than the current size, new columns are added to the end of the model
    * with <code>null</code> cell values.
    * If the new size is less than the current size, all columns at index
    * <code>columnCount</code> and greater are discarded.
    * @param columnCount the new number of columns in the model
    public void setColumnCount(int columnCount) {
    columnIdentifiers.setSize(columnCount);
    justifyRows(0, getRowCount());
    fireTableStructureChanged();
    * Adds a column to the model. The new column will have the
    * identifier <code>columnName</code>, which may be null. This method
    * will send a
    * <code>tableChanged</code> notification message to all the listeners.
    * This method is a cover for <code>addColumn(Object, Vector)</code> which
    * uses <code>null</code> as the data vector.
    * @param columnName the identifier of the column being added
    public void addColumn(Object columnName) {
    addColumn(columnName, (Vector)null);
    * Adds a column to the model. The new column will have the
    * identifier <code>columnName</code>, which may be null.
    * <code>columnData</code> is the
    * optional vector of data for the column. If it is <code>null</code>
    * the column is filled with <code>null</code> values. Otherwise,
    * the new data will be added to model starting with the first
    * element going to row 0, etc. This method will send a
    * <code>tableChanged</code> notification message to all the listeners.
    * @param columnName the identifier of the column being added
    * @param columnData optional data of the column being added
    public void addColumn(Object columnName, Vector columnData) {
    columnIdentifiers.addElement(columnName);
    if (columnData != null) {
    int columnSize = columnData.size();
    if (columnSize > getRowCount()) {
    dataVector.setSize(columnSize);
    justifyRows(0, getRowCount());
    int newColumn = getColumnCount() - 1;
    for(int i = 0; i < columnSize; i++) {
    Vector row = (Vector)dataVector.elementAt(i);
    row.setElementAt(columnData.elementAt(i), newColumn);
    else {
    justifyRows(0, getRowCount());
    fireTableStructureChanged();
    * Adds a column to the model. The new column will have the
    * identifier <code>columnName</code>. <code>columnData</code> is the
    * optional array of data for the column. If it is <code>null</code>
    * the column is filled with <code>null</code> values. Otherwise,
    * the new data will be added to model starting with the first
    * element going to row 0, etc. This method will send a
    * <code>tableChanged</code> notification message to all the listeners.
    public void addColumn(Object columnName, Object[] columnData) {
    addColumn(columnName, convertToVector(columnData));
    // Implementing the TableModel interface
    * Returns the number of rows in this data table.
    * @return the number of rows in the model
    public int getRowCount() {
    return dataVector.size();
    * Returns the number of columns in this data table.
    * @return the number of columns in the model
    public int getColumnCount() {
    return columnIdentifiers.size();
    * Returns the column name.
    * @return a name for this column using the string value of the
    * appropriate member in <code>columnIdentifiers</code>.
    * If <code>columnIdentifiers</code> does not have an entry
    * for this index, returns the default
    * name provided by the superclass
    public String getColumnName(int column) {
    Object id = null;
    // This test is to cover the case when
    // getColumnCount has been subclassed by mistake ...
    if (column < columnIdentifiers.size()) {
    id = columnIdentifiers.elementAt(column);
    return (id == null) ? getDefaultColumnName(column)
    : id.toString();
    * Returns true regardless of parameter values.
    * @param row the row whose value is to be queried
    * @param column the column whose value is to be queried
    * @return true
    public boolean isCellEditable(int row, int column) {
    return true;
    * Returns an attribute value for the cell at <code>row</code>
    * and <code>column</code>.
    * @param row the row whose value is to be queried
    * @param column the column whose value is to be queried
    * @return the value Object at the specified cell
    * @exception ArrayIndexOutOfBoundsException if an invalid row or
    * column was given
    public Object getValueAt(int row, int column) {
    Vector rowVector = (Vector)dataVector.elementAt(row);
    return rowVector.elementAt(column);
    * Sets the object value for the cell at <code>column</code> and
    * <code>row</code>. <code>aValue</code> is the new value. This method
    * will generate a <code>tableChanged</code> notification.
    * @param aValue the new value; this can be null
    * @param row the row whose value is to be changed
    * @param column the column whose value is to be changed
    * @exception ArrayIndexOutOfBoundsException if an invalid row or
    * column was given
    public void setValueAt(Object aValue, int row, int column) {
    Vector rowVector = (Vector)dataVector.elementAt(row);
    rowVector.setElementAt(aValue, column);
    fireTableCellUpdated(row, column);
    // Protected Methods
    * Returns a vector that contains the same objects as the array.
    * @param anArray the array to be converted
    * @return the new vector; if <code>anArray</code> is <code>null</code>,
    *                    returns <code>null</code>
    protected static Vector convertToVector(Object[] anArray) {
    if (anArray == null) {
    return null;
    Vector v = new Vector(anArray.length);
    for (int i=0; i < anArray.length; i++) {
    v.addElement(anArray[i]);
    return v;
    * Returns a vector of vectors that contains the same objects as the array.
    * @param anArray the double array to be converted
    * @return the new vector of vectors; if <code>anArray</code> is
    *                    <code>null</code>, returns <code>null</code>
    protected static Vector convertToVector(Object[][] anArray) {
    if (anArray == null) {
    return null;
    Vector v = new Vector(anArray.length);
    for (int i=0; i < anArray.length; i++) {
    v.addElement(convertToVector(anArray[i]));
    return v;

  • How do I install Front Row for my MacBook Air with Lion OS

    I need to know how to simply install Front Row onto my MacBook Air with Lion OX 10.7.4. Please help.

    Front Row is indeed "gone." There are alternatives, but first look at these links:
    How to Install Front Row on Mac OS X Lion 10.7
    Front Row Enabler for Lion - Mac-Hatter Consulting, LLC.
    Get Front Row for Mac OS X 10.7 Lion
    Plex - A Complete Media Solution

  • Can you use one PC for 2 different Ipods, with out erasing the others music from Itunes?

    Can you use one PC for different Ipod touch's , with out erasing the other persons Itunes music?

    Yes.  See:
    How to use multiple iPods, iPads, or iPhones with one computer

  • One row expected but not counted with resultSet.next()

    Hi all, I am using the following method to check an entry in my database. The problem is that the while(rs.next()) loop is not entered and therefore not counting the rows within the resultSet. This only occurs when one row is retrieved from the db. The query executed definitely works.
            private boolean enteredInDaily(String date, String chan)
              int rowCnt = 0;
              String query =  "SELECT id FROM daily WHERE " +
                   "name = '" + name+ "' AND " +
                   "start_date <= '" + date + "' AND " +
                   "finish_date >= '" + date + "'";          
              try {
                   Class.forName("org.gjt.mm.mysql.Driver");
                   Connection dbCon = DriverManager.getConnection("jdbc:mysql://localhost/dbname?user=&password=");
                   Statement stmt = dbCon.createStatement();
                   ResultSet rs = stmt.executeQuery(query);               
                   while(rs.next()) {
                                    //this loop not entered
                        System.out.println(rs.getInt("id"));
                        rowCnt++;
              catch(ClassNotFoundException ex) {
                                    System.out.println(ex); }
              catch(SQLException ex) {
                                    System.out.println(ex); }
              System.out.println("rowCnt = " + query);
              if (rowCnt == 0)
                   return false;
              else
                   return true;
         }Can anyone shed any light on this problem??? Thanks.

    How very silly of me!! I was connecting to the real database and not my test db. Sorry to waste a post.

  • Multiple values to display on one row for employee help.

    Hello all,
    I am trying to return multiple values for an EE on a single row.  Example:
    So I had it working and then I added another column and condition and it duplicated the EMPLOYID.  Here is my script:
    SELECT            a.EMPLOYID, rtrim(a.FRSTNAME) + ' ' + a.LASTNAME as 'EMPLOYEE NAME', a.INACTIVE, a.BRTHDATE, c.STATE, c.ZIPCODE,
                    a.Primary_Pay_Record, UPR40301.DSCRIPTN AS JOBTITLE, b.BENEFIT, d.DEDUCTON as Spouse, e.DEDUCTON as Child, f.deducton as Voluntary,
                    b.BENEFIT as [Dental Benefit],
    CASE
             WHEN b.BENEFIT like 'LI%' THEN 'LI%'
             WHEN d.DEDUCTON like 'LI%SPE' then 'LI%SPE'
             WHEN e.DEDUCTON like 'LI%CHE' then 'LI%CHE'
             when f.DEDUCTON like 'LI%' then 'LI%'       
             else ''
    end
    FROM            UPR00100 a left outer join
                    UPR00600 b ON a.EMPLOYID = b.EMPLOYID left outer JOIN
                    UPR40301 ON a.JOBTITLE = UPR40301.JOBTITLE left outer join
                    UPR00102 c on a.EMPLOYID = c.EMPLOYID  left outer join
                    UPR00500 d on a.EMPLOYID = d.EMPLOYID left outer join
                    UPR00500 e on a.EMPLOYID = e.EMPLOYID left outer join
                    UPR00500 f on a.EMPLOYID = f.EMPLOYID
    WHERE        ((b.INACTIVE = 0) AND (a.INACTIVE = 0) AND (c.STATE <> '')and (c.ZIPCODE <> '') and (b.BENEFIT LIKE 'LI%') and (d.DEDUCTON like 'LI%SPE')
                 and (e.DEDUCTON like 'LI%CHE') and (f.DEDUCTON like 'LI%'))
    Any help would be greatly appreciated.
    //Jeff

    Thank you Simon.  I finally got it to work.  Here is my final script:
    SELECT distinct        a.EMPLOYID, rtrim(a.FRSTNAME) + ' ' + a.LASTNAME as 'EMPLOYEE NAME', a.INACTIVE, a.BRTHDATE, c.STATE, c.ZIPCODE,
                    a.Primary_Pay_Record, UPR40301.DSCRIPTN AS JOBTITLE, b.BENEFIT, d.DEDUCTON as Spouse, e.DEDUCTON as Child, f.deducton as Voluntary,
                    b.BENEFIT as [Dental Benefit],
    CASE
             WHEN b.BENEFIT like 'LI%' THEN 'LI%'
             WHEN d.DEDUCTON like 'LI%SPE' then 'LI%SPE'
             WHEN e.DEDUCTON like 'LI%CHE' then 'LI%CHE'
             when (f.DEDUCTON like 'LI%' and f.DEDUCTON NOT LIKE '%SPE' AND F.DEDUCTON NOT LIKE '%CHE')then 'LI%'        
             else ''
    end
    FROM            UPR00100 a left outer join
                    UPR00600 b ON a.EMPLOYID = b.EMPLOYID left outer JOIN
                    UPR40301 ON a.JOBTITLE = UPR40301.JOBTITLE left outer join
                    UPR00102 c on a.EMPLOYID = c.EMPLOYID  left outer join
                    UPR00500 d on a.EMPLOYID = d.EMPLOYID left outer join
                    UPR00500 e on a.EMPLOYID = e.EMPLOYID left outer join
                    UPR00500 f on a.EMPLOYID = f.EMPLOYID
    WHERE        ((b.INACTIVE = 0) AND (a.INACTIVE = 0) AND (c.STATE <> '')and (c.ZIPCODE <> '') and (b.BENEFIT LIKE 'LI%') and (d.DEDUCTON like 'LI%SPE')
                 and (e.DEDUCTON like 'LI%CHE') and (f.DEDUCTON like 'LI%' ) and (f.DEDUCTON not like 'LI%CHE' and f.DEDUCTON not like 'LI%SPE'))
    ORDER BY 'EMPLOYEE NAME'
    Thanks again everyone!!!
    //Jeff

  • How can I color just one row in a table?

    Hello,
    I'm implementing cut/copy/paste and I want that when I perform cut the row color will be pale/ghost than the regular selectionRow background. And I want this pale color to stay for this row regardless if I select now other rows. I need it for JTable, JTree & JList. So my question is how can I color a row in those components (permanently - till I release it)
    Thanks
    Bnaya.

    Hi,
    for a JTable I would suggest the following:
    1.in the body of the class
    int ghostrow = -1;
    Color ghostColor = Color.lightGray; // for example2. overwrite the prepareRenderer-method this way
    public Component prepareRenderer(TableCellRenderer render,int row, int column) {
    Component c = super.prepareRenderer(renderer,row,column);
    if (row==ghostrow) c.setBackground(ghostColor);
    return c;
    }3. add a method in your JTable subclass for setting of the ghostrow like this, in order to force the JTable to update its display after setting ghostrow
    public void setGhostRow(int row) {
    TableModel tm = getModel();
    int currow = tm.getRowCount();
    int oldrow = ghostrow;
    ghostrow = -1;
    if (row<currow) ghostrow = row;
    // next 2 rows in normal mode displayed, because it will not print the greater than symbol correctif ((oldrow>-1) && (oldrow<currow)) tableChanged(new TableModelEvent(tm,oldrow));
    if ((ghostrow>-1) && (ghostrow<currow)) tableChanged(new TableModelEvent(tm,ghostrow));
    For the other classes, you want this effect to happen in, try to find a similar method, that is central and do it in a similar way there.
    greetings Marsian

  • One program for pc and mac with different imports

    I am trying to port my Java program from the PC to the MAC. I would like to have one program that works on both, the PC and the MAC. So I am using the
    if (System.getProperty("mrj.version") == null) //PC
    else //MAC
    condition to see if I am on the PC or MAC for making sure that the About menu is at the Help menu on top of the application window (PC) or at the Program menu on top of the screen (MAC) and the Control key (PC) or Command key (MAC) is used.
    However, the Mac also uses additional imports, such as
    import com.apple.laf.*;
    import com.apple.mrj.*;
    import com.apple.eawt.*;
    I cannot make an if statement before the imports. How can I make sure that the imports are only used on the MAC?
    Thanks for your time!

    >
    ..my program has a GUI...>Cool. OK - if you have not tried applications launched by JWS (Java Web Start) it is usually handy to get a feel for how they work for the end user. The biggest difference is between sandboxed applications, and ones that request extended permissions in the form of either j2ee-application-client-permissions or all-permissions. The first removes the warning banner from the bottom of windows, and adds a few other allowable actions, while the latter is, as it implies - all permissions.
    Examples of all-permissions/sandboxed can be seen in this [demo of the JNLP fileservice|http://pscode.org/jws/api.html#fs].
    >
    .. It is a computer graphics program, and it has a Tools palette where you can specify what and how you want to draw or select or move, and it has a Measurements palette, where you can use numbers for your drawing.>Does it offer to export the resulting graphics (e.g. save them to disk)? Does the program load graphic objects from disk? The reason I pointed to a demo of the differences between sand boxed and trusted apps., is because if the app. wants to 'access the local disks' it will either need to request all-permissions or as demonstrated in the example, use the [JNLP API|http://java.sun.com/javase/6/docs/jre/api/javaws/jnlp/index.html] (a group of classes only available to apps. launched by webstart) to do common things like access disks or printer, or take control of downloads...
    If you click the [Launch File Service (sandboxed) demo|http://pscode.org/jws/filetest-sandbox.jnlp] link, you can see what the experience would be like for the end user if the app. were converted to use the JNLP API for file I/O and was delivered entirely sandboxed.
    Of course, if your app. could work entirely sand boxed, like an applet - no code signing or extra permissions would be necessary, but that is uncommon for a desktop application.
    >
    So could you please give me some explanation or reference how to do launching it using webstart, and putting the mac specific resources into a resource section flagged for the Mac? >Launching an app. via webstart is not entirely 'simple', especially if you are new to it. OTOH it is well worth the effort - for the sake of the end user.
    The very basics of webstart is that you create a JNLP file to launch the app., I guess it is similar to the Mac .plist (or whatever they are) that you are discussing in another thread. Java JNLP files are a form of XML. Here is an example of what one might look like for an app. that provides different resources to different OS.
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0"
          codebase="http://ananya.com/lib"
          href="ananyacurves.jnlp">
      <information>
        <title>Ananya Curves</title>
        <vendor>Ananya Systems</vendor>
        <description>Ananya Curves - Computer Graphics</description>
        <offline-allowed/>
        <shortcut online="false">
          <desktop/>
          <menu submenu="AnanyaSystems"/>
        </shortcut>
      </information>
      <security>
           <all-permissions />
      </security>
        <resources>
          <j2se version="1.6+" />
          <jar href="AnanyaCurves.jar" main='true' />
        </resources>
        <!-- This is it! Supply the mac specific classes ONLY to Macintosh OS. -->
        <resources os='Mac'>
          <jar href="mac-specific.jar" />
        </resources>
      <application-desc />
    </jnlp>
    >
    ..Well, I am a complete beginner at this.>It can be a steep learning curve to first use JWS successfully, but it is well worth it.
    There is a good [overview of webstart|http://java.sun.com/developer/technicalArticles/Programming/jnlp/], but I also find it handy to keep the documentation on the [JNLP file syntax|http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html] nearby.
    Unfortunately many IDEs (and people) are not that competent at writing JNLP files, so I provide a JNLP XSD and [YAX-V|http://pscode.org/xml/xmltools.html#yaxv] to validate them.

Maybe you are looking for