JTable Double-Object in the clipboard

Hello together,
this is my first posting here.
I've a JTable with Double-Objects. The Double-Objects in the JTable Cells are shown in the
Format *1.000,99*. I used a Renderer to Format the Value in the Cells.
If I use the STRG+C to Copy the Table Cells to Clipboard, the Values lose the format and the above Value is shown as follows:
*1000.99* in the Clipboard.
How can i tell Java that it use the rendered Format *1.000,99*
Greetings
Charly

In My TableModel the Value is in Double-Type. How can i manipulate the String Representation. Here is the The Model-Class
public class JDBCTableModel extends AbstractTableModel {
     Object[][] contents;
     String[] columnNames;
     Class[] columnClasses;
     String sql;
     Boolean[] editierbareSpalten;
     public JDBCTableModel(){
          super();
          contents = new Object[0][0];
     // AbstractTableModel methods
     public int getRowCount() {
          return contents.length;
     public int getColumnCount() {
          if (contents.length == 0)
               return 0;
          else
               return contents[0].length;
     public Object getValueAt(int row, int column) {
          return contents[row][column];
     public void setValueAt(Object o,int row, int column) {
          contents[row][column]=o;
     // overrides methods for which AbstractTableModel
     // has trivial implementations
     public Class getColumnClass(int col) {
          return columnClasses[col];
     public String getColumnName(int col) {
          return columnNames[col];
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
     try{
          return this.editierbareSpalten[col];
     }catch(Exception e){
          return false;
     public void setContent(Object[][] contents,String[] columnNames,Class[] columnClasses){
          setColumnClasses(columnClasses);
          setColumnNames(columnNames);
          setContent(contents);
          editierbareSpalten=new Boolean[columnNames.length];
          this.fireTableStructureChanged();
     public void setColumnClasses(Class[] columnClasses){
          this.columnClasses=columnClasses;
     public void setColumnNames(String[] columnNames){
          this.columnNames=columnNames;
     public void setContent(Object[][] contents){
          this.contents=contents;
}

Similar Messages

  • Selecting objects on the clipboard

    Hi,
    I have a program that draws circles on a JPanel.
    Now I'm trying to cut/ copy/paste these objects.
    I know I first need to select and object (a circle in my case)
    That is, get the system clipboard and then select an area/object
    My question is, how do I select an object?
    I have a popup menu that comes up on right clicking the mouse
    so I want the object that contains the current mouse coordinates
    to be selected.
    I'm out of ideas how to do this.
    Thanks in advance,
    Gk

    I also read somewhere that only text can be selected or put into the clipboart.
    Is tthat true?
    How then do we add objects to the clipboard?
    Thanks again,
    Gk

  • I can not create a Double object

    I cannot create Double objects. The following program should be straight-forward enough. Right?
    ++class TextfilerFloat++
    ++{++
    ++     public static void main (String[] args)++
    ++     {++
    ++          Double d = 332.2;++
    ++          System.out.println (d);++
    ++     }++
    ++}++
    Compiling it returns the following message:
    ++incompatible types++
    ++found : double++
    ++required: Double++
    ++          Double d = 332.2;++
    ++          ^++
    ++1 error++
    ++Tool completed with exit code 1++
    The same program but with the object Integer instead of Double works (for 332, not 332.2). The problem is not if I use "," och ".", I checked.
    Two questions:
    Because I have this problem, what other problems can i expect?
    What can I do to fix this problem (I have reinstalled Java once and it didn�t help)?

    I don�t use Java 1.4.2 and I never had it installed on my computer. I have Java SE 6.     
    I interpreted your advice (I am an beginner, and if I didn�t understand your advice thats probably the reason) by trying to do it this way:
    double           d = 112.2;
    Double          dd = d;It didn�t work.
    And, I�m sure, I just tried, the program works fine if I use Integer instead of Double.
    By the way, I get the program to work on other computers. And my Java teacher, who is very skilled, don�t know what the problem is.
    What else might I do to fix the problem?
    Edited by: oxygenisgoodforyou on Dec 15, 2007 4:13 AM

  • 30EA1 /2.*: Double-clicking objects in the navigator tree

    Hi,
    There is an inconsistency in double-clicking objects in the navigator tree:
    When Preferences - Database - ObjectViewer - Open Objects on Single Click is checked, double-clicking e.g. a table in the navigator will still open it the same way as single-clicking it.
    However, when Preferences - Database - ObjectViewer - Open Objects on Single Click is not checked, double-clicking the table in the navigator will open it, and expand the columns. The latter is quite irritating, especially on large tables.
    Can this be bugged, so double-clicking the table in the navigator will just open it?
    Thanks,
    K.

    The node is expanded on double click irrespective of what the preferenceIs this a typo or does it really expand always for you? For me it only expands with "single click objects" disabled.
    windows explorer also does the sameYes, and I'd even say that's the desired behaviour, especially since it's the only action taken.
    Common sense and standards are against taking 2 different actions at the same time. One should override the other.
    Ideally, double click with "single click objects" disabled would just open the object, and double click with "single click objects" enabled could expand the node as in the Windows Explorer (but doesn't have to).
    So that's almost completely the other way around as we get it now.
    Thanks,
    K.

  • How do I embed a pdf document into an existing pdf so that the user double clicks on the pdf object within the pdf and it opens? i've looked everywhere on various forums and tried attachments - but still not working. Thanks

    I've tried various methods but to no avail. I have a pdf document and within the pdf I'd like to embed a couple pdf documents so that all the user has to do is double click on the pdf object inside the pdf and it opens in a new window. I've tried using attachments to do it and linking it...but to no avail. Anyone know how to do? I'm using Acrobat Pro Version 11. Thanks

    The "embed" feature common to MS Office applications is not applicable to PDF (for the why and wherefore of PDF get comfortable and read the ISO Standard for PDF - ISO 32000-1:2008).
    You can insert other PDF files' pages into any given PDF.
    You can attach files of supported formats to a PDF (of course a PDF is supported).
    You cannot "embed". So, nothing is broken.
    Be well...

  • Can JButtons within applets copy to the clipboard?

    camickr wrote in another thread:
    As always I would like to see the Applet used that caused the problem. We should not have to create our own applet to test this. As we all know from the original problem you may be missing/adding code. And this posting is way off topic so any new SSCCE along with a new question should be posted in a new posting. If I understand the problem is that Ctrl+C works on a text area, but it doesn't work for a JButton that tries to copy text from the same text area?Not quite. Ctrl+C works within a JTable, copying selected row(s) to the clipboard. The problem is getting a JButton to copy arbitrary text to the clipboard, having nothing to do with a JTable.
    Well post the simple 20 line applet that demonstates this.Sorry, it's more than 20 lines. I included three approaches, Jeanette's, Walter's, and mine.
    * Created on 06.12.2010
    * Jeanette, Walter, and Rich
    import java.awt.EventQueue;
    import java.awt.datatransfer.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.Toolkit;
    import javax.swing.*;
    public class ThreeCopyButtons  extends JApplet  implements ClipboardOwner
        final JLabel first  = new JLabel("Larry");
        final JLabel second = new JLabel("Moe");
        final JLabel third  = new JLabel("Curly");
        static ThreeCopyButtons cb3;
        public JPanel getContent() {
            JButton kleo = new JButton("Kleo");
         cb3 = this;
            TransferHandler handler = new TransferHandler() {
                 * @inherited <p>
                @Override
                protected Transferable createTransferable(JComponent c) {
                    return new StringSelection(cb3.toString());
                 * @inherited <p>
                @Override
                public int getSourceActions(JComponent c) {
                    return COPY;
            kleo.setTransferHandler(handler);
            kleo.setAction(TransferHandler.getCopyAction());
            kleo.setText("Kleo");  // gets overridden by "copy"
         AppletCopyButton walt = new AppletCopyButton("Walt", toString());
         JButton rich = new JButton("Rich");
         rich.addActionListener( new ActionListener() {
             public void actionPerformed(ActionEvent e) {
              StringSelection ss = new StringSelection(cb3.toString());
              Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
              cb.setContents(ss, cb3);
            JComponent buttons = new JPanel();
            buttons.add(kleo);
            buttons.add(walt);
            buttons.add(rich);
            JPanel labels = new JPanel();
            labels.add(first);
            labels.add(second);
            labels.add(third);
            JPanel box = new JPanel();
            box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
         box.add(buttons);
         box.add(labels);
            return box;
        public String toString() {
         String s = first.getText() + "\t" +
                 second.getText() + "\t" +
                 third.getText();
         return(s);
        // Empty method needed for implementation of the ClipboardOwner interface.
        public void lostOwnership( Clipboard aClipboard, Transferable aContents) {
          //do nothing
        // method expected by applets
        public void init()
        { // the static block above should have already executed
         try {
             javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
              public void run() {
                  JPanel frame = getContent();
                  setContentPane(frame);
         } catch (Exception e) {
             System.err.println("makeContent() failed to complete: " + e);
             e.printStackTrace();
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.add(new ThreeCopyButtons().getContent());
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
    // Walter Laan
    class AppletCopyButton extends JButton {
        public AppletCopyButton(String label, String text) {
            super(label);
         final String clip = text;
            setTransferHandler(new TransferHandler() {
                // @Override
                protected Transferable createTransferable(JComponent c) {
                    return new StringSelection(clip);
                // @Override
                public int getSourceActions(JComponent c) {
                    return COPY;
            addActionListener(new ActionListener() {
                // @Override
                public void actionPerformed(ActionEvent e) {
                    Action copy = TransferHandler.getCopyAction();
                    copy.actionPerformed(new ActionEvent(AppletCopyButton.this,
                            ActionEvent.ACTION_PERFORMED, "copy"));
    }Here is a manifest file I call "3cbManifest.txt".
    Main-Class: ThreeCopyButtonsMake sure you preserve the trailing carriage return.
    ]javac ThreeCopyButtons.java
    ]jar cvfm ThreeCopyButtons.jar 3cbManifest.txt *.class
    ]java -jar ThreeCopyButtons.jar
    (The latter command simply tests, but it is running as program, not applet.)
    And here is a short HTML file to run it as an applet. I call it "3cb.html".
    <html>
    <head><title>TestApplet</title></head>
    <body>
    <applet code="ThreeCopyButtons.class"
            archive="ThreeCopyButtons.jar"
            width="450" height="300">
    Your browser is completely ignoring the <i>applet</i> tag!
    </applet>
    </body>
    </html>The three buttons match our three approaches:
    * Kleo -- Jeanette's approach
    * Walt -- Walt's approach
    * Rich -- my approach
    All three methods work fine as a program, whether running directly as classes or from the .jar. None however work as an applet, from the HTML page.
    To test either as applet or program:
    1) open a text editor
    2) type something short
    3) Ctrl+C copy what you typed
    4) click the Kleo button
    5) in editor, click <enter> and Ctrl+V to paste
    6) observe whether you see the text from step 3 or "Larry Moe Curly", with <tabs> between words.
    7) repeat steps 3-6 for the Walt and Rich buttons
    If you can figure out how to get the applet to bypass its security wall, great. We've found a bug in Java's applet security. If not, I am resigned to having the button in my actual app copy info to the table instead of to the clipboard.

    RichF wrote:
    You are right, but aw gee whiz. Have you ever written something that you think is pretty neat, then have to throw it away? hahahahahaha ... sure, happens nearly every day :-)
    My class QEPanel, which handles each row of the statistics, is like that.yeah, have seen it: pretty nasty mixing of view and data <g>
    Hmm, I wouldn't actually have to throw most of it away. :) correct ...
    The JLabel <b>label</b>s would become the table column labels, and the other JLabels would become integers specifying column. except that I don't completely understand what you are after here (ehem: get your vocabulary right, sir) a clean separation would map the data-part of a QEPanel into a QEBean, with properties title (was: label), percentRed ... etc. Something like:
    public class QEBean extends AbstractBean {
        private float sumRed, sumGrn, sumBlu;
        private float minDist = 9999999;
        private float maxDist = 0;
        private double sumDist;
        private int count;
        private int entries;
        private CountPerEntries countPerEntries;
        private String title;
        public QEBean(String title) {
            this.title = title;
        public void reset() {
            // do reset
            firePropertyChange(null, null, null);
        public void updateData(Color quantized, Color actual) {
            // do update internals
            firePropertyChange(null, null, null);
    //------------ getters...
        public String getTitle() {
            return title;
        public float getPercentRed() {
            if (count == 0)
                return 0f;
            return sumRed / count;
        // more getters
    }Then implement a specialized TableModel which knows about QEBean
    public class QEBeanTableModel extends AbstractTableModel {
        List<QEBean> errors = new ArrayList<QEBean>();
        private PropertyChangeListener errorChangeListener;
        @Override
        public int getColumnCount() {
            return 7;
        @Override
        public int getRowCount() {
            return errors.size();
        @Override
        public Class<?> getColumnClass(int columnIndex) {
            switch (columnIndex) {
                   // implement as appropriate
            return Object.class;
        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            QEBean error = errors.get(rowIndex);
            switch (columnIndex) {
            case 0:
                return error.getTitle();
            case 1:
                return error.getPercentRed();
              // more as appropriate
            return null;
        public void addError(QEBean error) {
            int oldSize = getRowCount();
            error.addPropertyChangeListener(getPropertyChangeListener());
            errors.add(error);
            fireTableRowsInserted(oldSize, oldSize);
        public QEBean getError(int row) {
            return errors.get(row);
        private PropertyChangeListener getPropertyChangeListener() {
            if (errorChangeListener == null) {
                errorChangeListener = new PropertyChangeListener() {
                    @Override
                    public void propertyChange(PropertyChangeEvent evt) {
                        int row = errors.indexOf(evt.getSource());
                        fireTableRowsUpdated(row, row);
            return errorChangeListener;
        public void resetAll() {
            for (QEBean error : errors) {
                error.reset();
    }Then use the model in HelpBox:
    // init model and keep in field
         qErrors = new QEBeanTableModel();
         qErrors.addError(new QEBean("Hex QE"));
         qErrors.addError(new QEBean("Name QE"));
         qErrors.addError(new QEBean("Mismatch QE"));
         qErrors.addError(new QEBean("SearchAccuracy"));
            // can't resist - JXTable would make customization so much easier :-)
         // JXTable errorTable = new JXTable(qErrors);
         JTable errorTable = new JTable(qErrors);
         errorTable.setBackground(Color.BLACK);
         errorTable.setSelectionBackground(Color.BLACK);
         errorTable.setForeground(Color.WHITE);
         errorTable.setSelectionForeground(Color.WHITE);
         errorTable.setGridColor(Color.BLACK);
            // install renderers which produce an output similar to the labels
           panel.add(errorTable)
    // in the update methods - update the QEBeans stored in the model
        public void updateQE(int which, String q, String a)
         Color     quantized = Color.black;
         Color     actual = Color.black;
         int     rgb[] = { 0, 0, 0 };
         NTC.getRGB(q, rgb);
         quantized = new Color(rgb[0], rgb[1], rgb[2]);
         NTC.getRGB(a, rgb);
         actual = new Color(rgb[0], rgb[1], rgb[2]);
         qErrors.getError(which -1).updateData(quantized, actual);
    // similar in reset, updateEntriesThat's all and will give you an output very similar to the rows of individual labels, only more symetric.
    The toString() method would go away because row toString() is already built into JTable.ehhh? No, not that I know of :-) The default renderer uses the toString of the cell value, the row is not involved.
    >
    Then you can implement the button's action to copy that error table's content to the clipboard. Better usability ensured, IMO.I'll just throw away the darn button. The colorTable doesn't have one, so why should the statisticsTable? sure, that's an option - the visual setup outlined above is for hiding the table-nature, if you want it expose, just do - no problem.
    Cheers
    Jeanette

  • Shading part of a JTable Cell dependent upon the value of the cell

    Hi
    Was hoping some one woudl be able to provide some help with this. I'm trying to create a renderer that will "shade" part of a JTable cell's background depending upon the value in the cell as a percentage (E.g. if the cell contains 0.25 then a quarter of the cell background will be shaded)
    What I've got so far is a renderer which will draw a rectangle whose width is the relevant percentage of the cell's width. (i.e. the width of the column) based on something similar I found in the forum but the part I'm struggling with is getting it to draw this rectangle in any cell other than the first cell. I've tried using .getCellRect(...) to get the x and y position of the cell to draw the rectangle but I still can't make it work.
    The code for my renderer as it stands is:
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import javax.swing.JLabel;
    import javax.swing.JTable;
    import javax.swing.table.TableCellRenderer;
    public class PercentageRepresentationRenderer extends JLabel implements TableCellRenderer{
         double percentageValue;
         double rectWidth;
         double rectHeight;
         JTable table;
         int row;
         int column;
         int x;
         int y;
         public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
              if (value instanceof Number)
                   this.table = table;
                   this.row = row;
                   this.column = column;
                   Number numValue = (Number)value;
                   percentageValue = numValue.doubleValue();
                   rectHeight = table.getRowHeight(row);
                   rectWidth = percentageValue * table.getColumnModel().getColumn(column).getWidth();
              return this;
         public void paintComponent(Graphics g) {
            x = table.getCellRect(row, column, false).x;
            y = table.getCellRect(row, column, false).y;
              setOpaque(false);
            Graphics2D g2d = (Graphics2D)g;
            g2d.fillRect(x,y, new Double(rectWidth).intValue(), new Double(rectHeight).intValue());
            super.paintComponent(g);
    }and the following code produces a runnable example:
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableModel;
    public class PercentageTestTable extends JFrame {
         public PercentageTestTable()
              Object[] columnNames = new Object[]{"A","B"};
              Object[][] tableData = new Object[][]{{0.25,0.5},{0.75,1.0}};
              DefaultTableModel testModel = new DefaultTableModel(tableData,columnNames);
              JTable test = new JTable(testModel);
              test.setDefaultRenderer(Object.class, new PercentageRepresentationRenderer());
              JScrollPane scroll = new JScrollPane();
              scroll.getViewport().add(test);
              add(scroll);
         public static void main(String[] args)
              PercentageTestTable testTable = new PercentageTestTable();
              testTable.pack();
              testTable.setVisible(true);
              testTable.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }If anyone could help or point me in the right direction, I'd appreciate it.
    Ruanae

    This is an example I published some while ago -
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Fred120 extends JPanel
        static final Object[][] tableData =
            {1, new Double(10.0)},
            {2, new Double(20.0)},
            {3, new Double(50.0)},
            {4, new Double(10.0)},
            {5, new Double(95.0)},
            {6, new Double(60.0)},
        static final Object[] headers =
            "One",
            "Two",
        public Fred120() throws Exception
            super(new BorderLayout());
            final DefaultTableModel model = new DefaultTableModel(tableData, headers);
            final JTable table = new JTable(model);
            table.getColumnModel().getColumn(1).setCellRenderer( new LocalCellRenderer(120.0));
            add(table);
            add(table.getTableHeader(), BorderLayout.NORTH);
        public class LocalCellRenderer extends DefaultTableCellRenderer
            private double v = 0.0;
            private double maxV;
            private final JPanel renderer = new JPanel(new GridLayout(1,0))
                public void paintComponent(Graphics g)
                    super.paintComponent(g);
                    g.setColor(Color.CYAN);
                    int w = (int)(getWidth() * v / maxV + 0.5);
                    int h = getHeight();
                    g.fillRect(0, 0, w, h);
                    g.drawRect(0, 0, w, h);
            private LocalCellRenderer(double maxV)
                this.maxV = maxV;
                renderer.add(this);
                renderer.setOpaque(true);
                renderer.setBackground(Color.YELLOW);
                renderer.setBorder(null);
                setOpaque(false);
                setHorizontalAlignment(JLabel.CENTER);
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
                final JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
                if (value instanceof Double)
                    v = ((Double)value).doubleValue();
                return renderer;
        public static void main(String[] args) throws Exception
            final JFrame frame = new JFrame("Fred120");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(new Fred120());
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    }

  • More DataFlavors copied to the clipboard/used in D&D in one step

    Hallo,
    For my GUI app. I would like to enable different types of information to copied to the clipboard.
    e.g. object type 1 - Document ID ( actual row's document ID from JTable ) - to copy document type
    object type 2 - string representation ( columns texts from JTable ) - to copy to excel
    I would like to keep them general, with different possible combinations
    among them ( up to 10 different object types ), according to some specs.
    Has anybody idea, if it is possible ? ( prefarably with 1.4 D&D interface ).
    Data are packed in createTransferable() call, but it allows just 1 format (?) ...
    Maybe I can use some 'envelope' format holding all possible information,
    but that idea doesn't looks nice for me :(
    Thanks for any hint.
    Tibor

    Hi !
    Thanks for your help. For drag & drop it's fine. System will ask for 'best' format as I expect.
    How is it with clipboard ? I had idea to copy table columns as a "text" flavor
    ( for paste into excel ) and user created flavor "id" with documentId inside.
    On paste I would take 'what's better' ( e.g. as a document reference better would be better my "id" flavor,
    because that information doesn't need to be in table cells inside ).
    Maybe I will have to use 'own' clipboard for these reasons.
    Tibor

  • DefaultListModel  & JTable; how to sync the items in the DefaultListModel

    I have a jtable with items in it
    example
    name date age
    Peter 01-jan-43 62
    Ron 03-nov-73 32
    when double clicking the name( eg peter), a new window pops up contains all relevent info of the user.
    I added a sorter and when sorting the table it comes in the correct-wanted order, however, when double clicking the item - the wrong window pops up.
    I take it the DefaultListModel is not synchronized with the tables elements.
    Q: how to correct the DefaultListModel once the table has been sorted so it will be in sync with the jtable.
    thanks
    peter

    thank you camicker for replying.
    I have been trying for the past 4 hours to dig in the code (as well as google) to find where to implement a sync with the DefaultListModel. Nothing.
    any input?
    package com.shared.model;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.*;
    public class TableSorter extends AbstractTableModel
        protected TableModel tableModel;
        public static final int DESCENDING = -1;
        public static final int NOT_SORTED = 0;
        public static final int ASCENDING = 1;
        private static Directive EMPTY_DIRECTIVE = new Directive(-1, NOT_SORTED);
        public static final Comparator COMPARABLE_COMAPRATOR = new Comparator()
            public int compare(Object o1, Object o2)
                return ((Comparable) o1).compareTo(o2);
        public static final Comparator LEXICAL_COMPARATOR = new Comparator()
            public int compare(Object o1, Object o2)
                return o1.toString().compareTo(o2.toString());
        private Row[] viewToModel;
        private int[] modelToView;
        private JTableHeader tableHeader;
        private MouseListener mouseListener;
        private TableModelListener tableModelListener;
        private Map columnComparators = new HashMap();
        private List sortingColumns = new ArrayList();
        public TableSorter()
            this.mouseListener = new MouseHandler();
            this.tableModelListener = new TableModelHandler();
        public TableSorter(TableModel tableModel)
            this();
            setTableModel(tableModel);
        public TableSorter(TableModel tableModel, JTableHeader tableHeader)
            this();
            setTableHeader(tableHeader);
            setTableModel(tableModel);
        private void clearSortingState()
            viewToModel = null;
            modelToView = null;
        public TableModel getTableModel()
            return tableModel;
        public void setTableModel(TableModel tableModel)
            if (this.tableModel != null)
                this.tableModel.removeTableModelListener(tableModelListener);
            this.tableModel = tableModel;
            if (this.tableModel != null)
                this.tableModel.addTableModelListener(tableModelListener);
            clearSortingState();
            fireTableStructureChanged();
        public JTableHeader getTableHeader()
            return tableHeader;
        public void setTableHeader(JTableHeader tableHeader)
            if (this.tableHeader != null)
                this.tableHeader.removeMouseListener(mouseListener);
                TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
                if (defaultRenderer instanceof SortableHeaderRenderer)
                    this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
            this.tableHeader = tableHeader;
            if (this.tableHeader != null)
                this.tableHeader.addMouseListener(mouseListener);
                this.tableHeader.setDefaultRenderer
                        new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer())
        public boolean isSorting()
            return sortingColumns.size() != 0;
        private Directive getDirective(int column)
            for (int i = 0; i < sortingColumns.size(); i++)
                Directive directive = (Directive)sortingColumns.get(i);
                if (directive.column == column)
                    return directive;
            return EMPTY_DIRECTIVE;
        public int getSortingStatus(int column)
            return getDirective(column).direction;
        private void sortingStatusChanged()
            clearSortingState();
            fireTableDataChanged();
            if (tableHeader != null)
                tableHeader.repaint();
        public void setSortingStatus(int column, int status)
            Directive directive = getDirective(column);
            if (directive != EMPTY_DIRECTIVE)
                sortingColumns.remove(directive);
            if (status != NOT_SORTED)
                sortingColumns.add(new Directive(column, status));
            sortingStatusChanged();
        protected Icon getHeaderRendererIcon(int column, int size)
            Directive directive = getDirective(column);
            if (directive == EMPTY_DIRECTIVE)
                return null;
            return new Arrow(directive.direction == DESCENDING, size, sortingColumns.indexOf(directive));
        private void cancelSorting()
            sortingColumns.clear();
            sortingStatusChanged();
        public void setColumnComparator(Class type, Comparator comparator)
            if (comparator == null)
                columnComparators.remove(type);
            else
                columnComparators.put(type, comparator);
        protected Comparator getComparator(int column)
            Class columnType = tableModel.getColumnClass(column);
            Comparator comparator = (Comparator) columnComparators.get(columnType);
            if (comparator != null)
                return comparator;
            if (Comparable.class.isAssignableFrom(columnType))
                return COMPARABLE_COMAPRATOR;
            return LEXICAL_COMPARATOR;
        private Row[] getViewToModel()
            if (viewToModel == null)
                int tableModelRowCount = tableModel.getRowCount();
                viewToModel = new Row[tableModelRowCount];
                for (int row = 0; row < tableModelRowCount; row++)
                    viewToModel[row] = new Row(row);
                if (isSorting())
                    Arrays.sort(viewToModel);
            return viewToModel;
        public int modelIndex(int viewIndex)
            return getViewToModel()[viewIndex].modelIndex;
        private int[] getModelToView()
            if (modelToView == null)
                int n = getViewToModel().length;
                modelToView = new int[n];
                for (int i = 0; i < n; i++)
                    modelToView[modelIndex(i)] = i;
            return modelToView;
        // TableModel interface methods
        public int getRowCount()
            return (tableModel == null) ? 0 : tableModel.getRowCount();
        public int getColumnCount()
            return (tableModel == null) ? 0 : tableModel.getColumnCount();
        public String getColumnName(int column)
            return tableModel.getColumnName(column);
        public Class getColumnClass(int column)
            return tableModel.getColumnClass(column);
        public boolean isCellEditable(int row, int column)
            return tableModel.isCellEditable(modelIndex(row), column);
        public Object getValueAt(int row, int column)
            return tableModel.getValueAt(modelIndex(row), column);
        public void setValueAt(Object aValue, int row, int column)
            tableModel.setValueAt(aValue, modelIndex(row), column);
        // Helper classes
        private class Row implements Comparable
            private int modelIndex;
            public Row(int index)
                this.modelIndex = index;
            public int compareTo(Object o)
                int row1 = modelIndex;
                int row2 = ((Row) o).modelIndex;
                for (Iterator it = sortingColumns.iterator(); it.hasNext();)
                    Directive directive = (Directive) it.next();
                    int column = directive.column;
                    Object o1 = tableModel.getValueAt(row1, column);
                    Object o2 = tableModel.getValueAt(row2, column);
                    int comparison = 0;
                    // Define null less than everything, except null.
                    if (o1 == null && o2 == null)
                        comparison = 0;
                    } else if (o1 == null)
                        comparison = -1;
                    } else if (o2 == null)
                        comparison = 1;
                    } else {
                        comparison = getComparator(column).compare(o1, o2);
                    if (comparison != 0)
                        return directive.direction == DESCENDING ? -comparison : comparison;
                return 0;
        private class TableModelHandler implements TableModelListener
            public void tableChanged(TableModelEvent e)
                // If we're not sorting by anything, just pass the event along.            
                if (!isSorting())
                    clearSortingState();
                    fireTableChanged(e);
                    return;
                // If the table structure has changed, cancel the sorting; the            
                // sorting columns may have been either moved or deleted from            
                // the model.
                if (e.getFirstRow() == TableModelEvent.HEADER_ROW)
                    cancelSorting();
                    fireTableChanged(e);
                    return;
                // We can map a cell event through to the view without widening            
                // when the following conditions apply:
                // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
                // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
                // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
                // d) a reverse lookup will not trigger a sort (modelToView != null)
                // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
                // The last check, for (modelToView != null) is to see if modelToView
                // is already allocated. If we don't do this check; sorting can become
                // a performance bottleneck for applications where cells 
                // change rapidly in different parts of the table. If cells
                // change alternately in the sorting column and then outside of            
                // it this class can end up re-sorting on alternate cell updates -
                // which can be a performance problem for large tables. The last
                // clause avoids this problem.
                int column = e.getColumn();
                if (e.getFirstRow() == e.getLastRow()
                        && column != TableModelEvent.ALL_COLUMNS
                        && getSortingStatus(column) == NOT_SORTED
                        && modelToView != null)
                    int viewIndex = getModelToView()[e.getFirstRow()];
                    fireTableChanged(new TableModelEvent(TableSorter.this,
                                                         viewIndex, viewIndex,
                                                         column, e.getType()));
                    return;
                // Something has happened to the data that may have invalidated the row order.
                clearSortingState();
                fireTableDataChanged();
                return;
        private class MouseHandler extends MouseAdapter
            public void mouseClicked(MouseEvent e)
                JTableHeader h = (JTableHeader) e.getSource();
                TableColumnModel columnModel = h.getColumnModel();
                int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                int column = columnModel.getColumn(viewColumn).getModelIndex();
                if (column != -1)
                    int status = getSortingStatus(column);
                    if (!e.isControlDown())
                        cancelSorting();
                    // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
                    // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
                    status = status + (e.isShiftDown() ? -1 : 1);
                    status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
                    setSortingStatus(column, status);
        private static class Arrow implements Icon
            private boolean descending;
            private int size;
            private int priority;
            public Arrow(boolean descending, int size, int priority)
                this.descending = descending;
                this.size = size;
                this.priority = priority;
            public void paintIcon(Component c, Graphics g, int x, int y)
                Color color = c == null ? Color.GRAY : c.getBackground();            
                // In a compound sort, make each succesive triangle 20%
                // smaller than the previous one.
                int dx = (int)(size/2*Math.pow(0.8, priority));
                int dy = descending ? dx : -dx;
                // Align icon (roughly) with font baseline.
                y = y + 5*size/6 + (descending ? -dy : 0);
                int shift = descending ? 1 : -1;
                g.translate(x, y);
                // Right diagonal.
                g.setColor(color.darker());
                g.drawLine(dx / 2, dy, 0, 0);
                g.drawLine(dx / 2, dy + shift, 0, shift);
                // Left diagonal.
                g.setColor(color.brighter());
                g.drawLine(dx / 2, dy, dx, 0);
                g.drawLine(dx / 2, dy + shift, dx, shift);
                // Horizontal line.
                if (descending) {
                    g.setColor(color.darker().darker());
                } else {
                    g.setColor(color.brighter().brighter());
                g.drawLine(dx, 0, 0, 0);
                g.setColor(color);
                g.translate(-x, -y);
            public int getIconWidth()
                return size;
            public int getIconHeight()
                return size;
        private class SortableHeaderRenderer implements TableCellRenderer
            private TableCellRenderer tableCellRenderer;
            public SortableHeaderRenderer(TableCellRenderer tableCellRenderer)
                this.tableCellRenderer = tableCellRenderer;
            public Component getTableCellRendererComponent(JTable table,
                                                           Object value,
                                                           boolean isSelected,
                                                           boolean hasFocus,
                                                           int row,
                                                           int column)
                Component c = tableCellRenderer.getTableCellRendererComponent(table,
                        value, isSelected, hasFocus, row, column);
                if (c instanceof JLabel) {
                    JLabel l = (JLabel) c;
                    l.setHorizontalTextPosition(JLabel.LEFT);
                    int modelColumn = table.convertColumnIndexToModel(column);
                    l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
                return c;
        private static class Directive
            private int column;
            private int direction;
            public Directive(int column, int direction)
                this.column = column;
                this.direction = direction;
    }

  • JTable: double clicking triggers some action

    Hi there,
    A double click on a row of a JTable makes usually the underlying cell editable. This is the default behaviour of a JTable.
    In my application, the JTable only shows data, without giving users editing rights. Beside that, I'd like that a double click on a row, triggers other actions, like for example copying the selected row to the clipboard or sending it per mail....
    How do I have to configure the JTable for these purposes? Do I have to override the default ListSelectionListener? Did anybody make experiences with that?
    Thanks for your help,
    Best regards,
    edar

    like for example copying the selected row to the clipboardCtrl-C is the default KeyStroke combination for this.
    Beside that, I'd like that a double click on a row, triggers other actions...Then you need to add a MouseListener to the table. Then use:
    rowAtPoint(...);
    columnAtPoint(...);to determine which cell was clicked

  • Pls Help :JTable Double Value Editing Problem

    hi friends
    as i am new to swings and Jtable pls help me if u can.
    in the code copied below when i start putting value into the Double column of JTable
    a ( .0 ) is appended at the end which is undesirable it should be like that only when the value is
    something like 22.99 and also i want to limit the double value's fractional part to be limited to 2 digits only.
    if this can be done in my Table model itself so that it will work everywhere i use this model
    Pls tell me what exactly do i need, a custom Cell Editor or Cell Renderer. and whether can i do it in the
    Table Model Defination class or whether i can only do it on the Jtable only.
    guys its so confusing.pls help
    if anyone can send a sample code for achieving this it would be of great help
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.text.*;
    public class TableProcessing extends JFrame implements TableModelListener
        JTable table;
        public TableProcessing()
            String[] columnNames = {"Item", "Quantity", "Price", "Cost"};
            Object[][] data =
                {"Bread", new Integer(1), new Double(1.11), new Double(1.11)},
                {"Milk", new Integer(1), new Double(2.22), new Double(2.22)},
                {"Tea", new Integer(1), new Double(3.33), new Double(3.33)},
                {"Cofee", new Integer(1), new Double(4.44), new Double(4.44)}
            DefaultTableModel model = new DefaultTableModel(data, columnNames);
            model.addTableModelListener( this );
            table = new JTable( model )
                //  Returning the Class of each column will allow different
                //  renderers to be used based on Class
                public Class getColumnClass(int column)
                    return getValueAt(0, column).getClass();
                //  The Cost is not editable
                public boolean isCellEditable(int row, int column)
                    if (column == 3)
                        return false;
                    else
                        return true;
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            JScrollPane scrollPane = new JScrollPane( table );
            getContentPane().add( scrollPane );
         *  The cost is recalculated whenever the quantity or price is changed
        public void tableChanged(TableModelEvent e)
            if (e.getType() == TableModelEvent.UPDATE)
                int row = e.getFirstRow();
                int column = e.getColumn();
                if (column == 1 || column == 2)
                    int    quantity = ((Integer)table.getValueAt(row, 1)).intValue();
                    double price = ((Double)table.getValueAt(row, 2)).doubleValue();
                    Double value = new Double(quantity * price);
                    table.setValueAt(value, row, 3);
        public static void main(String[] args)
            TableProcessing frame = new TableProcessing();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
    }thank in advance
    jags

    No.
    But further to this try:
    public class MyCustomRenderer  extends javax.swing.table.DefaultTableCellRenderer
              private java.text.DecimalFormat FORMAT_DOUBLE;
              public MyCustomRenderer()
                      FORMAT_DOUBLE = new java.text.DecimalFormat("#, ##0.00");
              public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                        //NB! you could also set foreground/background here to indicate positive/negative values...
                        if(value.getClass().equals(Double.class))//is this a double?
                                double d = ((Double)value).doubleValue();
                                d = (Double.isNaN(d)||Double.isInfinity(d))?0:d;
                                this.setText(FORMAT_DOUBLE.format(d));
                        else//not a double so let's toString() it...
                               this.setText(""+value);
    }then, using code pasted above, specify a new instance of this class as the default renderer in your
    table.....
    :)

  • JTable - Can I change the color of the text on a row by row basis?

    Hi All,
    I'm redoing a bit of old uni coursework (to model a stockmarket, stock ticker server & stock ticker application) to brush up my Java skills (esp Swing and Event Handling) and am programming the UI by hand using Swing (its the only way to learn something....(I've certianly nailed Layout Management!!))
    In the stocktickerserver GUI I'm using a JTable to display the details about stocks.
    The user can select a stock and view the details of the stock in another frame. In one panel in the JFrame I've got a JTable listing the history items for the stock (Price, Change, Date).
    Is it possible to color the rows of the JTable according to the value of the change column (or at least the value I insert there)?
    e.g
    if (change > 0){
    Blue;
    else{
    if (change < 0){
    Red;
    else{
    Green;
    I'm completly ignorant on how to achieve this (or even if its possible at all) so all your ideas welcome.
    Any help much appreciated
    Pete
    P.S.
    The Stock History is a class that I store in a [private] Vector in the Stock Class.
    For the selected Stock I loop through this vector getting the items (using various accessor methods)
    I extract the values from the return StockHistory object and build a DefaultTableModel from these
    Then I call JTable.setModel(theModel) to build the table

    implement TableCellRenderer and change foreground of the Renderer in the method getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) . Install this renderer to your table.

  • DEtailed scheduling planning board - scalling of objects in the charts

    Hi,
    I am wandering if there is a possibility of changing the scale in the graphical planning board in APO PPDS, eg. in the resource chart. in the way that I could change the scale just for a certain period of time or one object.
    for example:
    the planning period choosen is 10.09.14 to 01.10.14., scale unit is hour, but the duration of some orders or operations is less than a minute. Woud it be possible to somehow change the scale just for 1 day or 1 hour within the shown period? zooming in does not help as then I cannot see the other lines that I need to look at when scheduling that specific order or operation.
    thank's for any helpful hint!
    br,
    Wojtek

    Hi Mike,
    thank you for responding to my query.
    I know the functionality with the right-click. this unfortunately does not help as the whole time frame is stretched-out => they cannot seen some objects, while the planners would like to strech-out only part of the shown period.
    I also checked the possibility of changing the scale down to seconds cause some operations have a duration of less than a minute (timescale editor = double left-click on the scale). But the production is still unhappy. They have seen in some software such a possibility and wish the same in the graphical planning board. they want to see just part of the time frame in another scale so that the objects outside the scale remain in the same time unit but the objects within the considered time frame would be displayed in another time unit.
    In the resource chart if you right-click an operation you can select the option shrink/stretch operation => I am not sure if there is sth wrong with my connection but most of the time when I click this option nothing happens. Just a couple of times while clicking on the same operation I manged to get a pop up "change operation duration" where you can define in % the new duration. but have to choose a new duration between "min and max duration" that are in this pop up zero => so I cannot change anything and have no clue where this zeros for min and max come from and in the end if that might solve my problem.
    br,
    Wojtek

  • UCCX copy data in the enterprise data window right to the clipboard

    Hello I need help please! how to write a macro to copy data in the enterprise data window right to the clipboard? I should be able to take the data right from enterprise data and copy it to the clipboard so the agent can paste it into any application they want.  The macro step wants an application first - how do I get around this?
    Thanks.Hello I need help please! how to write a macro to copy data in the enterprise data window right to the clipboard? I should be able to take the data right from enterprise data and copy it to the clipboard so the agent can paste it into any application they want.  The macro step wants an application first - how do I get around this?
    Thanks.

    Do you have more than one enterprise fields showing your CAD layout?
    Do you wish to copy all of the them or just one of them?
    Do you wish to copy the name as well as the value?
    At any rate, a macro is not needed to copy the enterprise data.  You simply double click it and press CTRL+C.
    See this video here, which shows me doing just that:
    http://www.youtube.com/watch?v=88E-z0ShlFE&list=UUkB02mmFBBZqVBWY5XHAsoA&index=12&feature=plcp
    A macro might just complicate the matter, and force the Agent into a single option.  But let's get your answers to the above first, before we make any final decisions on the matter.
    Anthony Holloway
    Please use the star ratings to help drive great content to the top of searches.

  • Writing Image in the clipboard to Oracle DB

    Hi,
    I want to write the image in the clipboard to the Blob am using JDeveloper. Can any1 help me please I am stuck on conversion and writing to Blob.
    Very Urgent Please!!!!!!!
    Comments: Applet is used to diplay an image present in the clipboard, convert this image into bytes write it to a blob and transfer the blob into Oracle DB
    package mypackage1;
    import java.applet.Applet;
    import javax.swing.JLabel;
    import oracle.jdeveloper.layout.XYLayout;
    import oracle.jdeveloper.layout.XYConstraints;
    import java.awt.datatransfer.*;
    import java.awt.image.*;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.event.*;
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import oracle.jdeveloper.layout.OverlayLayout2;
    import java.awt.Button;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.sql.Blob;
    import java.sql.Statement;
    import java.awt.Toolkit;
    import java.awt.event.*; //Clipboard
    import java.awt.datatransfer.*; //Clipboard
    import java.awt.Image;// .image.*; //Clipboard
    import java.sql.*;
    import java.sql.*;
    import java.net.*;
    import java.lang.*;
    import java.awt.TextField;
    import java.awt.Font;
    import oracle.sql.BLOB;
    public class ClipboardImage extends Applet
    Button displayButton = new Button();
    Button exitButton = new Button();
    JLabel photoLabel = new JLabel();
    Panel panel1 = new Panel();
    XYLayout xYLayout2 = new XYLayout();
    XYLayout xYLayout1 = new XYLayout();
    Button submitButton = new Button();
    Connection connection = null;
    static Image photo;
    public byte[] data;
    public Blob bl;
    TextField Message = new TextField();
    public ClipboardImage()
    public void init()
    try
    jbInit();
    catch(Exception e)
    e.printStackTrace();
    public static void main(String[] args)
    ClipboardImage applet = new ClipboardImage();
    Frame frame = new Frame();
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    frame.add(applet, BorderLayout.CENTER);
    frame.setTitle("Applet Frame");
    applet.init();
    applet.start();
    frame.setSize(300, 300);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    frame.setLocation((d.width - frameSize.width) / 2, (d.height -
    frameSize.height) / 2);
    frame.setVisible(true);
    private void jbInit() throws Exception
    this.setLayout(xYLayout2);
    this.setBackground(new Color(136, 212, 122));
    displayButton.setLabel("Display");
    displayButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    scanButton_actionPerformed(e);
    exitButton.setLabel("Exit");
    exitButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    exitButton_actionPerformed(e);
    photoLabel.setText("Photo");
    panel1.setLayout(xYLayout1);
    panel1.setBackground(new Color(255, 249, 240));
    xYLayout2.setWidth(288);
    xYLayout2.setHeight(300);
    submitButton.setLabel("Submit");
    submitButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    submitButton_actionPerformed(e);
    Message.setFont(new Font("Abadi MT Condensed", 0, 9));
    panel1.add(photoLabel, new XYConstraints(0, 0, 115, 155));
    this.add(Message, new XYConstraints(20, 275, 250, 15));
    this.add(submitButton, new XYConstraints(105, 220, 80, 30));
    this.add(panel1, new XYConstraints(90, 25, 115, 155));
    this.add(exitButton, new XYConstraints(195, 220, 85, 30));
    this.add(displayButton, new XYConstraints(10, 220, 85, 30));
    void exitButton_actionPerformed(ActionEvent e)
    System.exit(0);
    If an image is on the system clipboard, this method returns it
    otherwise it returns null
    public static Image getClipboard()
    Transferable t =
    Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    try
    if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor))
    Image text = (Image)t.getTransferData(DataFlavor.imageFlavor);
    photo = text;
    return text;
    catch (UnsupportedFlavorException e)
    catch (IOException e)
    return null;
    Display an image in the system's clipboard
    void scanButton_actionPerformed(ActionEvent e)
    Image img = this.getClipboard();
    photo = img;
    photoLabel.setIcon(new ImageIcon(photo));
    // Gives out int array
    public int[] fetchPixels(Image image, int width, int height)
    int pixMap[] = new int[width*height];
    PixelGrabber pg = new PixelGrabber(image, 0,0,width,height, pixMap,
    0, width);
    try
    pg.grabPixels();
    catch (InterruptedException e)
    return null;
    if((pg.status() & ImageObserver.ABORT)!=0)
    return null;
    return pixMap;
    // Here int array given by Pixel Grabber function is converted into
    byte array
    public byte[] extractData(int[] pixmap, int numbands) {
    byte data[] = new byte[pixmap.length*numbands];
    for(int i=0;i<pixmap.length;i++){
    int pixel = pixmap;
    byte a = (byte)((pixel >> 24) & 0xff);
    byte r = (byte)((pixel >> 16) & 0xff);
    byte g = (byte)((pixel >> 8) & 0xff);
    byte b = (byte)((pixel ) & 0xff);
    if(numbands == 4){
    data[i*numbands+0] = r;
    data[i*numbands+1] = g;
    data[i*numbands+2]= b;
    data[i*numbands+3] = a;
    } else {
    data[i*numbands+0] = r;
    data[i*numbands+1] = g;
    data[i*numbands+2]= b;
    return data;
    public void processData() {
    Image awtImage = getClipboard();
    int imageWidth = awtImage.getWidth(this);
    int imageHeight = awtImage.getHeight(this);
    int[] pix = fetchPixels(awtImage, imageWidth, imageHeight);
    data = extractData(pix, 4);
    photo = awtImage;
    System.out.println(" Height = " + imageHeight + " Width = " +
    imageWidth + " Pixel = " + pix + " Byte = " + data);
    void submitButton_actionPerformed(ActionEvent e)
    processData();
    try {
    System.out.println("Executing code");
    // Load the JDBC driver
    String driverName = "oracle.jdbc.driver.OracleDriver";
    Class.forName(driverName);
    // Create a connection to the database
    String serverName = "10.20.90.101";
    String portNumber = "1521";
    String sid = "iasdb";
    String url = "jdbc:oracle:thin:@" + serverName + ":" +
    portNumber + ":" + sid;
    String username = "birmingham";
    String password = "in";
    connection = DriverManager.getConnection(url, username,
    password);
    PreparedStatement ast = connection.prepareStatement("INSERT
    INTO PASSPORT (PASSID, PHOTO) VALUES (1992, EMPTY_BLOB())");
    ast.executeUpdate();
    PreparedStatement pst = connection.prepareStatement("UPDATE
    PASSPORT SET PHOTO = ? WHERE PASSID = 1992");
    //pst.setObject(1, (Object)photo);
    //Writing bytes to blob bl
    bl.setBytes(0, data);
    //Setting the blob to transfer to the blob column in oracle
    db
    pst.setBlob(1, bl);
    pst.executeUpdate(); if(pst.EXECUTE_FAILED == 1)
    Message.setText("Sql failed!");
    }else{
    Message.setText("Sql success!");
    System.out.println ("Connected\n");
    } catch (ClassNotFoundException ea) {
    // Could not find the database driver
    } catch (SQLException ea) {
    System.out.println(ea.toString());

    Look at the ArrayListTransferHandler class in the following Drag List Demo example: http://www.java2s.com/Code/Java/Swing-JFC/DragListDemo.htm

Maybe you are looking for

  • How do I connect my Mac book pro to Apple TV wireless

    I am not sure how to connect my Mac book pro to the tv with Apple TV wirelessly

  • Default viewer for Reader 9

    Some of our users have Acrobat 5.0 and Reader 9.0 installed on their machines. Internet explorer (multiple versions) always try to open pdf links in in Acrobat 5.0, but we want them to open in Reader as default. I have searched and searched for optio

  • InfoPath deployment in SharePoint 2013

    Hi, I am new to INFOPATH development We are trying to deploy code based infopath 2013 thourgh central admin. It is getting deployed perfectly, but its getting deployed to 14 Hive folder. How can we deploy it to 15 Hive folder structure ? I have tried

  • Original iPad WiFi works, but no WiFi icon

    I know this started after I upgraded to 4.3, but I can't say whether it started immediately after installing 4.3. My original 16GB WiFi only iPad has always been a champ when it comes to connecting to and staying connected to WiFi. Lately, I've notic

  • Undo Management

    Hello guys, I have a problem with Undo Tablespace in Oracle 9i. There's a OLPT system, Oracle 9i DBServer on Linux. The problem is that Undo datafile has grown very much, reaching about 4 GB. I restarted the my DB, but UndoTablespace continue with 99