JTable tooltips repaint

I have extended JTable for some spreadsheet-like functionality. There is a problem with some columns after a tooltip pops up, the repaint color is wrong.
Rows have varying color dependent on content, and the tooltip repaint color is that of another row. But, this only occurs in specific columns.
I do not believe it is due to the renderer/editor components themselves. I replaced the renderers and editors in the problem columns with simple JPanels, but the problem is still seen.
Any thoughts?

Custom code isn't working. Hmm, I wonder where the
problem would be...my first suspicion is the custom code
If you need further help then you need to create a
"Short, Self Contained, Compilable and Executable,
Example Program (SSCCE)",
see http://homepage1.nifty.com/algafield/sscce.html,
that demonstrates the incorrect behaviour, because I
can't guess exactly what you are doing based on the
information provided.I am happy to provide specifics if you think that there might be a problem in a specific area.
Don't forget to use the "Code Formatting
Tags",
see
http://forum.java.sun.com/help.jspa?sec=formatting,
so the posted code retains its original formatting.This is not a homework assignment. It is rather large with many dependencies on a proprietary baseline. To make it self-contained (or small) would be more trouble than it is worth.
I am hoping for tips like, "have you checked the ..." or "try to override the ..." or "there is a known bug with ...". The Dukes will go to the tip that leads me to a fix, no debugging necessary.

Similar Messages

  • JTable ToolTip in two lines

    Hello everybody,
    Please advise me how to make a JTable ToolTip to be displayed in two lines
    Thanks,
    Elena

    Use HTML tags to split tool tip text between two lines. For example:
    JTable table = new JTable();
    table.setToolTipText("<html>This table's tool tip text<br>is split between two lines</html>");

  • JTable in JPanel last Column resize clips JTable doesnt repaint JPanel

    I have a JTable in a JPanel, when I drag the last column of the JTableHeader (u can see the column resizing as the text of the Table HeaderColumn moves with the drag) the JTable is outside the JPanel. Only when u click on another component and then click back on the JTableHeader does it repaint.
    I have tried jPanel.revalidate(); in the mouseDragged event of MouseMotionListener on the JTableHeader and all manner or repaints and fireTableStructureChanged. But I dont understand the order of events.
    The last bug to fix!!!
    NB I dont want to use scrollpane as its not necessary and as many tables are synchronized with one table it makes repaints less smooth
    Thanks Paul

    Well, I didn't find an answer but I did find a solution.
    The JPanel is the problem. I use it to help with layout which is not obvious in this example.
    As you can see in the code the JTable is placed in a JScrollPane which is place in a JPanel which is placed in a JTabbedPane.
    If I use Box instead of JPanel the JTable in the JScrollPane in the Box in the TabbedPane in the JFrame resizes correclty.
    So although JPanel is resizable with setSize it does not get resized when it's JFrame gets resized.
    I would still like to know why?
    ////////KBS
    JTabbedPane myTP = new JTabbedPane();
    Box myOne = Box.createHorizontalBox();
    Box myTwo = Box.createHorizontalBox();
    myOne.add(pane);
    myTP.add("One", myOne);
    myTP.add("Two", myTwo);
    ////////KBS

  • JTable ToolTip with MouseCursor

    Hi,
    i use a JTable to display some data (strings). But some of the strings i want to display are to long for the fields in the JTable. So parts of my string arent displayed.
    When the user moves the mouse-cursor over the field i want do display the complete string in the field via ToolTip.
    My Problem is that i dont know the event and that i dont know how to find out on which field the mouse-cursor is.
    regards
    Toni

    http://javaalmanac.com/egs/javax.swing.table/Tips.html?l=rel

  • Problem faced with Jtable

    I have a row added to JTable.I am trying to edit column 2 in it.Now i keep my cursor in the same column which is being edited (i.e the focus remains in the column being edited) & click on Cancel Button
    By means of this button i clear the Jtable.i.e delete the row which is added to it.
    Now i add 1 more row to this Jtable.
    The same column of the newly added row displays the contents which had been edited previously.
    Eg : Row consists of 3 columns Col. 1 : Name
    Col 2 : Roll No
    Col 3 : Place .
    Assume that i add a row with name pradeep Roll No. 2 & Place - Mumbai.
    I edit col. 2 having roll no. 2 & make it 3.Keeping the focus here only i click on cancel.
    This row has been thus deleted.Now i add a new row..which has name : Manish Roll No : 5 & Place : Mumbai.But Column 2 shows 3 instead of 5.
    I have tried Jtable..repaint();
    jtable.updateUI();
    jtable.lostFocus();
    jtable.getCellEditor().stopCellEditing();
    however still this happens...is there any way to make jtable lose focus externally.....or any other way to handle this.

    It's the same what i have explained, though it's not real stuff..the idea is the same....yet i have clarified things below also...i have an textfield wherein i enter the main code.I click on enter & the details related to this code get added to the grid.Like in the example given be4...Let's assume i enter 1 i.e the code in the textfield & click on enter.The details related to 1 are Name : Pradeep Roll No. : 2 & Place : Mumbai.(Note that Name,Roll No & Place are column names)
    This gets added to the grid.Now i change the Roll No. which is currently 2 to 3.My focus is in this column.For some reason i don't need this record & click on cancel button.
    Now i enter 2 in the Textfield & click on enter. The details expected to be seen in the added row are Name : Manish , Roll No. 5 & Place Mumbai.But what is seen instead of this is Name : Manish , Roll No. 3 & Place : Mumbai.Also the focus is already in column 2.
    When we edit a column the code added changes the column data & then calls
    jTable.getCellEditor().cancelCellEditing().
    The code on clicking cancel calls
    jtable.repaint();
    jtable.updateUI()
    if (jtblBarCodeDetails.isEditing()) {
    jtblBarCodeDetails.getCellEditor().stopCellEditing();
    well.....that is it..

  • JTable and events

    Hi,
    I am fairly new to Swing. I don't understand the following behaviour of JTables. If I minimize the frame containing the JTable, and afterwards maximize it again, the getValuAt method is called again for all visible rows and columns, even if the table data did not change. The same happens whit a mousemove over the JTable, and if another screen is dragged over the screen and afterwards dragged away from the screen.
    It is possible this is normal, but it affects the performance of the application in a quite considerable way.
    Greetings,
    Marc

    StansislavL is right, when the JTable is repainted also the data needs to be repainted and therefor retrieved form the DataModel. The way to solve your performance issues is to read the data once into a Vector of beans and use this to retrieve the value's for your JTable, like:public Object getValueAt (int row, int col)
      SomeBean sb = (SomeBean) data.get(row) //data = Vector of beans
      switch (col)
        case 0: return sb.getID();
        case 1: return sb.getName();
      return null;
    }greetz,
    Stijn

  • CLICKABLE link on a tooltip - how to?

    Could you please help me/?
    here's a piece of a code:
    <b>String</b> tip =
    "<html><body><a href=\"www.sun.com\">www.sun.com</a></body></html>";
    someButton.setTooltipText(tip);When the cursor is over the button, the tooltip with "www.sun.com" link written on it appears. But when i try to click on the link, the tooltip disappeares.
    Is it possible to create the tooltip with click-able links??
    Thank you all.

    Something like this...
    package gui;
    public class AboutDialog extends JPopupMenu implements ActionListener, HyperlinkListener
      private JEditorPane copyright;
      private JToolTip toolTip;
      public AboutDialog()
        setLayout(new BorderLayout());
        setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
        setBackground(Color.WHITE);
        copyright = new JEditorPane("text/html",
                                    "<html>" +
                                    "<hr>" +
                                    "<span style='font-size: 10px;'>" +
                                    "Copyright � 2005 <a href='http://www.myweb.es'>My Company</a>" +
                                    "</span>" +
                                    "</html>");
        copyright.setEditable(false);
        copyright.addHyperlinkListener(this);
        toolTip = copyright.createToolTip();
        add(copyright, BorderLayout.SOUTH);
      // show the window
      public void actionPerformed(ActionEvent e)
        MainPanel panel = MainPanel.getMainPanel();
        Rectangle bounds = panel.getBounds();
        Dimension dimension = this.getPreferredSize();
        this.show(panel, (bounds.width - dimension.width)/2, (bounds.height - dimension.height)/2);
      public void hyperlinkUpdate(HyperlinkEvent e)
        HyperlinkEvent.EventType eType = e.getEventType();
        if (eType == HyperlinkEvent.EventType.ACTIVATED)
          Component component = MainPanel.getMainPanel();
          if (SwingUtilities.windowForComponent(component) instanceof JFrame)
            return; // an application
          while (component != null) // looking for an applet
            if (component instanceof Applet)
              Applet applet = (Applet)component;
              AppletContext context = applet.getAppletContext();
              if (context != null)
                context.showDocument(e.getURL());
              break;
            else
              component = component.getParent();
        else
          String link = eType == HyperlinkEvent.EventType.ENTERED ? e.getURL().toExternalForm() : null;
          copyright.setToolTipText(link);
          toolTip.repaint();
      // hint to set up Antialiasing for the compoonent.
      protected void paintComponent(Graphics g)
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        super.paintComponent(g);
    }Cheers,
    D.

  • Keep vertical scroll bar still y JScrollPane

    Hello all!
    I have got a JTable added into a JScrollPane, which scroll bars are always shown.
    I have to repaint the JTable each 3 seconds and I would like to keep the vertical scroll bar in its original position, for example if I am watching row 24 of the JTable when the JTable is repainted I would like the vertical scroll bar to be in the same position as it was before repainting because now the vertical scroll bar is repainted always at the top...
    With the horizontal bar it works, the bar does not move from its previous state when the JTable is repainted...
    Any idea of what is happening?
    Thanks in advance :)

    This would do for u! ... do it after you have updated the table with the new rows... if you are not using the default table model then you can still get the row count through your JTable object ...
    This part moves the scrollbar to the last row coz im doing "myDefaultTableModel.getRowCount()-1", you can keep the current row index in an instance level variable bjust before refreshing the table and use it in this.setRowSelectionInterval() method ...
    this.setRowSelectionInterval(myDefaultTableModel.getRowCount()-1, myDefaultTableModel.getRowCount()-1);
    this.setColumnSelectionInterval(1, 1); //didnt need any specific column coz I wanted the row basically..
    this.scrollRectToVisible(this.getCellRect(this.getSelectedRow(), 1, true));This basically selects the given row and then moved the scrollbar over to that point as well ...
    OR, here's another alternative!! you can also get the current scrollbar value similarly jsut before refreshing and pass that on to this method ...
    this.jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getValue());Hope it helps...
    Cheers!
    Asim

  • Drawing a rectanlge and moving it around

    Hi,
    I have a JTable in which I do drag and drop. To visually support this, I draw a marker in the JTable, when the cursor is over a valid drop position, to indicate where the object will be inserted. I do this by drawing a rectangle between two tables.
            Rectangle rect= tt1.getCellRect(row, col, true);
            Rectangle2D marker= new Rectangle2D.Double(rect.getX()-1, rect.getY(), 2, rect.getHeight());
            if (marker.equals(lastMarker)){
                return lastMarker;
            }else{
                //Line2D line= new Line2D.Double( rect.getX()-1, rect.getY()+rect.getHeight());
                tt1.repaint();
                Graphics2D g2= (Graphics2D) tt1.getGraphics();           
                g2.fill(marker);
                return marker;
            }(the lastMarker is used to avoid redrawing it, if would be on the same position.)
    Now my problem is the tt1.repaint(). (tt1 is the JTable)
    This repaint always deletes my rectangle. I think, this is because the actual redraw is done after the marker is drawn. Therefore the rectangle is shown for some milliseconds and then disappears. But how can I avoid this? Any ideas?

    Don't use getGraphics for this. Trying to draw from event code doesn't work because system
    repaint events work independently of your event code, ie, system repaints call the paint
    methods of the components in the component hierarchy which have no idea that you are
    drawing markers from event code. Override the paint method (which will draw on top of the
    component) in your JTable to draw your drop marker. This way it will always be called
    during both event-initiated and system repaints.

  • DefaultTableCellRenderer is not called after fireTableStructureChanged()

    I have a simple JTable application, the data model gets changed and fireTableStructureChanged() is called which repaints the table and I see the modifications.... However the DefaultTableCellRenderer is not called for each row in the modler. So, if I have any colors, or text size differences from the default, this all goes away as the renderer process is not called when the jtable is repainted. Is there anything Im missing? I have tried calling repaint and varous other "repaint" things on the table etc... Note initially when the JTable is displayed all works fine, the DefaultCellRenderer routine is called on each row.... Its only after fireTableStuctureChanged is called it doesn't happen... Thanks for your response.., Jay Schrock

    I had the same problem and the following solved it to some extent.
    Before creating the table I created a DefaultTableColumnModel and added TableColumns to it using
    the TableColumn(int index, int width, TableCellRenderer renderer, TableCellEditor editor) constructor.
    Then I created the JTable with the JTable(TableModel, TableColumnModel) constructor. This works fine and does not lose the renderer and editor when the model data is changed.
    Please let me know if you find anything wrong with the above way.

  • Problem while trying to control a JScrollpane

    Hi,
    I am working on a JTable inside a JScrollpanel... So there's a horizontal scrollbar at the bottom of the frame.
    My JTable displays a planning, and is loaded by database requests.
    My table is divided into "pages" which are a group of columns. When the JTable asks for a cell of a page (to display it), and that the page has not yet been loaded then, a request is automatically sent to the database.
    The correct behaviour should be :
    1. Add an empty page to the model and call tableChanged() to notify the JTable
    2. The JTable asks for a cell
    3. Send a request to the data base
    4. Fill in the page with the response
    5. Since that page is located on the left hand side, another empty page should also be added on the left (but should not be visible). Call tableChanged() to notify the JTable
    6. But since that page is also located on the right hand side, another empty page should also be added on the right (but should not be visible). Call tableChanged() to notify the JTable
    7. Then for example if the user goes to the left (with the scrollbar or with the keyboard arrows), it will make the left empty page visible. So a request is launched, response managed, and an empty page added to the left...and so on...
    My problem is that when I add a page to the left, the JScollbar position is automatically set (by Swing ?) to zero.
    So the left empty page becomes automatically visible, the request sent, and the new empty page added... scrollbar to zero automatically... and this goes on and on and there is no end!
    I haven't got the code (I'm not at my office)... but I've tried everything to block the JScrollbar....
    Can I add columns to my model (and to the JTable) without the automatic reset of the JScrollbar ???
    I would like the scrollbar to be resized systematically to reflect the new size of the table while the visible columns remain the same and at the same place on the screen.
    Thanks
    Arnaud

    Ok.... didn't work :-(
    One of the main problem is that the addColumn() methods only append a column to the end (the right) of the table... so they are half-useless (half because sometimes the user wants to go right)
    I didn't try anything with scrollRectToVisible(), because I don't want to search for the right rectangle to display...
    I really think that the whole conception of the table in Java is done for easily managing rows... but not columns... There are no methods to manage columns... and in the Javadoc, I see that the only methods wich manage columns always call tableChanged()
    But there's something interesting : the user of my planning can change the cell layout by changing what is displayed, and the number of information displayed. This automatically change the cells' sizes... The way I ask the JTable to repaint is a tableChaned() call (repaint() only repaints the cell without updating the size). And when I call tableChanged() in this situation, the JScrollBar is not affected !
    So I think the scrollbar is reset to 0 only when the number of columns is changed. I changed my code to artificially change the number of columns of the TableModel before calling the tableChaned().... didn't work :-(
    My code force the correct position of the scrollbar by calling setValues(), or setValue() and setMaximum(), everytime I need... The position should be correct !
    I think Swing uses a Thread to do paintings, and size computation.... and it's surely my problem : at the end of the fireTableChanged() the Table isn't in its final state.... so setting the scrollbar position at this point is useless...
    What do you think ?

  • Refresh GUI

    hi,
    i am quite new to java.I have a GUI.GUI shows the rows retrieved from database in jtable. i wanna refresh content of jtable every 5 seconds (or sometime ) continously. I constructed a method to retrieve the query results , locate them into jtable and repaint it. How can i invoke this method every 5 seconds (or sometime) periodically?
    thanx in advance
    hELin

    Look into threads.yes i have searched a little, i am confused.
    should the function be implementing runnable or should i use SwingUtilities.invokeLater() method?
    (since method accesses swing components)

  • MDI JTable Overlap Area Repaint Problem

    Hi all,
    I have a problem for my application in MDI mode.
    I open many windows (JInternalFrame contain JTable) under JDesktopPane. Some of the windows are overlapping and when they receive update in the table, it seems repaint all of the overlapping windows, not only itself. This make my application performance become poor, slow respond for drap & drop an existing window or open a new window.
    To prove this, i make a simple example for open many simple table and have a thread to update the table's value for every 200 mill second. After i open about 20 windows, the performance become poor again.
    If anyone face the same problem with me and any suggestions to solve the problem ?
    Please help !!!!!
    Following are my sources:
    public class TestMDI extends JFrame {
        private static final long serialVersionUID = 1L;
        private JPanel contentPanel;
        private JDesktopPane desktopPane;
        private JMenuBar menuBar;
        private List<TestPanel> allScreens = new ArrayList<TestPanel>();
        private List<JDialog> freeFloatDialogs = new ArrayList<JDialog>();
        private List<JInternalFrame> mdiInternalFrm = new ArrayList<JInternalFrame>();
        int x = 0;
        int y = 0;
        int index = 0;
        private static int MDI_MODE = 0;
        private static int FREE_FLOAT_MODE = 1;
        private int windowMode = MDI_MODE;
        public TestMDI() {
            init();
        public static void main(String[] args) {
            new TestMDI().show();
        public void init() {
            contentPanel = new JPanel();
            desktopPane = new JDesktopPane();
            desktopPane.setDragMode(JDesktopPane.LIVE_DRAG_MODE);
            desktopPane.setFocusTraversalKeysEnabled(false);
            desktopPane.setFocusTraversalPolicyProvider(false);
            desktopPane.setBorder(null);
            desktopPane.setIgnoreRepaint(true);
            desktopPane.setPreferredSize(new Dimension(1000, 800));
            this.setSize(new Dimension(1000, 800));
            menuBar = new JMenuBar();
            JMenu menu1 = new JMenu("Test");
            JMenuItem menuItem1 = new JMenuItem("Open Lable Screen");
            menuItem1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    for (int i = 1; i < 4; i++) {
                        final TestJLableScreen screen = new TestJLableScreen("Screen  " + (allScreens.size() + 1));
                        screen.startTime();
                        if (windowMode == MDI_MODE) {
                            JInternalFrame frame = createInternalFram(screen);
                            desktopPane.add(frame);
                            mdiInternalFrm.add(frame);
                            if (allScreens.size() * 60 + 100 < 1000) {
                                x = allScreens.size() * 60;
                                y = 60;
                            } else {
                                x = 60 * index;
                                y = 120;
                                index++;
                            frame.setLocation(x, y);
                            frame.setVisible(true);
                        } else {
                            JDialog dialog = createJDialog(screen);
                            freeFloatDialogs.add(dialog);
                            if (i * 60 + 100 < 1000) {
                                x = i * 60;
                                y = 60;
                            } else {
                                x = 60 * index;
                                y = 120;
                                index++;
                            dialog.setLocation(x, y);
                            dialog.setVisible(true);
                        allScreens.add(screen);
            JMenuItem menuItem2 = new JMenuItem("Open Table Screen");
            menuItem2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    for (int i = 1; i < 4; i++) {
                        TestTableScreen screen = new TestTableScreen("Screen  " + (allScreens.size() + 1));
                        screen.startTime();
                        if (windowMode == MDI_MODE) {
                            JInternalFrame frame = createInternalFram(screen);
                            desktopPane.add(frame);
                            mdiInternalFrm.add(frame);
                            if (allScreens.size() * 60 + 100 < 1000) {
                                x = allScreens.size() * 60;
                                y = 60;
                            } else {
                                x = 60 * index;
                                y = 120;
                                index++;
                            frame.setLocation(x, y);
                            frame.setVisible(true);
                        } else {
                            JDialog dialog = createJDialog(screen);
                            freeFloatDialogs.add(dialog);
                            if (i * 60 + 100 < 1000) {
                                x = i * 60;
                                y = 60;
                            } else {
                                x = 60 * index;
                                y = 120;
                                index++;
                            dialog.setLocation(x, y);
                            dialog.setVisible(true);
                        allScreens.add(screen);
            menu1.add(menuItem1);
            menu1.add(menuItem2);
            this.setJMenuBar(menuBar);
            this.getJMenuBar().add(menu1);
            this.getJMenuBar().add(createSwitchMenu());
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.add(desktopPane);
            desktopPane.setDesktopManager(null);
        public JInternalFrame createInternalFram(final TestPanel panel) {
            final CustomeInternalFrame internalFrame = new CustomeInternalFrame(panel.getTitle(), true, true, true, true) {
                public void doDefaultCloseAction() {
                    super.doDefaultCloseAction();
                    allScreens.remove(panel);
            internalFrame.setPanel(panel);
            // internalFrame.setOpaque(false);
            internalFrame.setSize(new Dimension(1010, 445));
            internalFrame.add(panel);
            internalFrame.setFocusTraversalKeysEnabled(false);
            internalFrame.setFocusTraversalPolicyProvider(false);
            desktopPane.getDesktopManager();
            // internalFrame.setFocusTraversalKeysEnabled(false);
            internalFrame.setIgnoreRepaint(true);
            return internalFrame;
        public JDialog createJDialog(final TestPanel panel) {
            JDialog dialog = new JDialog(this, panel.getTitle());
            dialog.setSize(new Dimension(1010, 445));
            dialog.add(panel);
            dialog.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    allScreens.remove(panel);
            return dialog;
        public JMenu createSwitchMenu() {
            JMenu menu = new JMenu("Test2");
            JMenuItem menuItem1 = new JMenuItem("Switch FreeFloat");
            menuItem1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    windowMode = FREE_FLOAT_MODE;
                    for (JInternalFrame frm : mdiInternalFrm) {
                        frm.setVisible(false);
                        frm.dispose();
                        frm = null;
                    mdiInternalFrm.clear();
                    remove(desktopPane);
                    desktopPane.removeAll();
    //                revalidate();
                    repaint();
                    add(contentPanel);
                    index = 0;
                    for (JDialog dialog : freeFloatDialogs) {
                        dialog.setVisible(false);
                        dialog.dispose();
                        dialog = null;
                    freeFloatDialogs.clear();
                    for (int i = 0; i < allScreens.size(); i++) {
                        JDialog dialog = createJDialog(allScreens.get(i));
                        freeFloatDialogs.add(dialog);
                        if (i * 60 + 100 < 1000) {
                            x = i * 60;
                            y = 60;
                        } else {
                            x = 60 * index;
                            y = 120;
                            index++;
                        dialog.setLocation(x, y);
                        dialog.setVisible(true);
            JMenuItem menuItem2 = new JMenuItem("Switch MDI");
            menuItem2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    windowMode = MDI_MODE;
                    remove(contentPanel);
                    add(desktopPane);
                    for (int i = 0; i < freeFloatDialogs.size(); i++) {
                        freeFloatDialogs.get(i).setVisible(false);
                        freeFloatDialogs.get(i).dispose();
                    freeFloatDialogs.clear();
    //                revalidate();
                    repaint();
                    for (JInternalFrame frm : mdiInternalFrm) {
                        frm.setVisible(false);
                        frm.dispose();
                        frm = null;
                    mdiInternalFrm.clear();
                    index = 0;
                    for (int i = 0; i < allScreens.size(); i++) {
                        JInternalFrame frame = createInternalFram(allScreens.get(i));
                        desktopPane.add(frame);
                        mdiInternalFrm.add(frame);
                        if (i * 60 + 100 < 1000) {
                            x = i * 60;
                            y = 60;
                        } else {
                            x = 60 * index;
                            y = 120;
                            index++;
                        frame.setLocation(x, y);
                        frame.setVisible(true);
            menu.add(menuItem1);
            menu.add(menuItem2);
            return menu;
    public class TestTableScreen extends TestPanel {
        private static final long serialVersionUID = 1L;
        JTable testTable = new JTable();
        MyTableModel tableModel1 = new MyTableModel(1);
        private boolean notRepaint = false;
        int start = 0;
        JScrollPane scrollPane = new JScrollPane();
        private Timer timmer = new Timer(200, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Random indexRandom = new Random();
                final int index = indexRandom.nextInt(50);
                Random valRandom = new Random();
                final int val = valRandom.nextInt(600);
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        notRepaint = false;
                        TestTableScreen.this.update(index + "|" + val);
        public TestTableScreen(String title) {
            this.title = title;
            init();
            tableModel1.setTabelName(title);
        public void startTime() {
            timmer.start();
        public String getTitle() {
            return title;
        public void update(String updateStr) {
            String[] val = updateStr.split("\\|");
            if (val.length == 2) {
                int index = Integer.valueOf(val[0]);
                List vals = tableModel1.getVector();
                if (vals.size() > index) {
                    vals.set(index, val[1]);
    //                 tableModel1.fireTableRowsUpdated(index, index);
                } else {
                    vals.add(val[1]);
    //                 tableModel1.fireTableRowsUpdated(vals.size() - 1, vals.size() - 1);
                tableModel1.fireTableDataChanged();
        public TableModel getTableModel() {
            return tableModel1;
        public void init() {
            testTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            testTable.setRowSelectionAllowed(true);
            this.testTable.setModel(tableModel1);
            int[] width = { 160, 80, 45, 98, 60, 88, 87, 88, 80, 70, 88, 80, 75, 87, 87, 41, 88, 82, 75, 68, 69 };
            TableColumnModel columnModel = testTable.getColumnModel();
            for (int i = 0; i < width.length; i++) {
                columnModel.getColumn(i).setPreferredWidth(width[i]);
            testTable.setRowHeight(20);
            tableModel1.fireTableDataChanged();
            this.setLayout(new BorderLayout());
            TableColumnModel columnMode2 = testTable.getColumnModel();
            int[] width2 = { 200 };
            for (int i = 0; i < width2.length; i++) {
                columnMode2.getColumn(i).setPreferredWidth(width2[i]);
            scrollPane.getViewport().add(testTable);
            scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            this.add(scrollPane, BorderLayout.CENTER);
        class MyTableModel extends DefaultTableModel {
            public List list = new ArrayList();
            String titles[] = new String[] { "袨怓1", "袨怓2", "袨怓3", "袨怓4", "袨怓5", "袨怓6", "袨怓7", "袨怓8", "袨怓9", "袨怓10", "袨怓11",
                    "袨怓12", "袨怓13", "袨怓14", "袨怓15", "袨怓16", "袨怓17", "袨怓18", "袨怓19", "袨怓20", "袨怓21" };
            String tabelName = "";
            int type_head = 0;
            int type_data = 1;
            int type = 1;
            public MyTableModel(int type) {
                super();
                this.type = type;
                for (int i = 0; i < 50; i++) {
                    list.add(i);
            public void setTabelName(String name) {
                this.tabelName = name;
            public int getRowCount() {
                if (list != null) {
                    return list.size();
                return 0;
            public List getVector() {
                return list;
            public int getColumnCount() {
                if (type == 0) {
                    return 1;
                } else {
                    return titles.length;
            public String getColumnName(int c) {
                if (type == 0) {
                    return "head";
                } else {
                    return titles[c];
            public boolean isCellEditable(int nRow, int nCol) {
                return false;
            public Object getValueAt(int r, int c) {
                if (list.size() == 0) {
                    return null;
                switch (c) {
                default:
                    if (type == 0) {
                        return r + " " + c + "  test ";
                    } else {
                        return list.get(r) + "   " + c;
        public boolean isNotRepaint() {
            return notRepaint;
        public void setNotRepaint(boolean notRepaint) {
            this.notRepaint = notRepaint;
    public class TestPanel extends JPanel {
        protected String title = "";
        protected boolean needRepaint = false;
        protected boolean isFirstOpen = true;
        public String getTitle() {
            return title;
        public void setNeedRepaint(boolean flag) {
            this.needRepaint = flag;
        public boolean isNeedRepaint() {
            return needRepaint;
        public boolean isFirstOpen() {
            return isFirstOpen;
        public void setFirstOpen(boolean isFirstOpen) {
            this.isFirstOpen = isFirstOpen;
    public class TestJLableScreen extends TestPanel {
        private static final long serialVersionUID = 1L;
        private JLabel[] allLables = new JLabel[20];
        private Timer timmer = new Timer(20, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Random indexRandom = new Random();
                final int index = indexRandom.nextInt(10);
                Random valRandom = new Random();
                final int val = valRandom.nextInt(600);
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        TestJLableScreen.this.setNeedRepaint(true);
                        TestJLableScreen.this.update(index + "|" + val);
        public TestJLableScreen(String title) {
            this.title = title;
            init();
        public void startTime() {
            timmer.start();
        public String getTitle() {
            return title;
        public void update(String updateStr) {
            String[] val = updateStr.split("\\|");
            if (val.length == 2) {
                int index = Integer.valueOf(val[0]);
                allLables[index * 2 + 1].setText(val[1]);
        public void init() {
            this.setLayout(new GridLayout(10, 2));
            boolean flag = true;
            for (int i = 0; i < allLables.length; i++) {
                allLables[i] = new JLabel() {
                    // public void setText(String text) {
                    // super.setText(text);
                    // // System.out.println("  setText " + getTitle() + "   ; " + this.getName());
                    public void paint(Graphics g) {
                        super.paint(g);
                        // System.out.println("  paint " + getTitle() + "   ; " + this.getName());
                    // public void repaint() {
                    // super.repaint();
                    // System.out.println("  repaint " + getTitle() + "   ; " + this.getName());
                allLables[i].setName("" + i);
                if (i % 2 == 0) {
                    allLables[i].setText("Name " + i + "  : ");
                } else {
                    allLables[i].setOpaque(true);
                    if (flag) {
                        allLables[i].setBackground(Color.YELLOW);
                        flag = false;
                    } else {
                        allLables[i].setBackground(Color.CYAN);
                        flag = true;
                    allLables[i].setText(i * 8 + "");
            for (int i = 0; i < allLables.length; i++) {
                this.add(allLables[i]);
    public class CustomeInternalFrame extends JInternalFrame {
        protected TestPanel panel;
        public CustomeInternalFrame() {
            this("", false, false, false, false);
        public CustomeInternalFrame(String title) {
            this(title, false, false, false, false);
        public CustomeInternalFrame(String title, boolean resizable) {
            this(title, resizable, false, false, false);
        public CustomeInternalFrame(String title, boolean resizable, boolean closable) {
            this(title, resizable, closable, false, false);
        public CustomeInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable) {
            this(title, resizable, closable, maximizable, false);
        public CustomeInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable,
                boolean iconifiable) {
            super(title, resizable, closable, maximizable, iconifiable);
        public TestPanel getPanel() {
            return panel;
        public void setPanel(TestPanel panel) {
            this.panel = panel;

    i had the same problem with buttons and it seemed that i overlayed my button with something else...
    so check that out first do you put something on that excact place???
    other problem i had was the VAJ one --> VisualAge for Java (terrible program)
    it does strange tricks even when you don't use the drawing tool...
    dunno 2 thoughts i had... check it out...
    SeJo

  • How to display cusomized custom tooltip(jwindow)  in jtable cell position

    Hi,
    i am trying to display custom tooltip for jtable cell. i created custom tooltip(jwindow) and on mouseover of jtable cell i am trying to display the custom tooltip.
    But it is not display the position of jtable cell. How to display the exact position of jtable cell
    please help me on this.

    Did you read the posting directly below yours which was also about a custom tool tip?
    JScrollableToolTip is buggy
    The code presented there shows the tool tip in the proper location.
    For more help create a [url http://sscce.org]SSCCE, that demonstrates the incorrect behaviour.
    Don't forget to read the "Welcome to the new home" posting at the start of the forum to learn how to use the "code tags" so posted code is formatted and readable.

  • Printing JTable after turning off double buffering causing repaint problems

    I've followed all the instructions to speed up a print job in java by turning off double buffering temporarily by using the following call before calling paint() on the component...
    RepaintManager.currentManager(printTable).setDoubleBufferingEnabled(false);
    ... and then turning it back on afterwards...
    RepaintManager.currentManager(printTable).setDoubleBufferingEnabled(true);
    but the problem is that if it is a long print job, then the rest of the application (including other JTables) isn't repainting properly at all. I have the printing going on in a separate thread since I don't think it's acceptable UI practices to force the user to wait until a print job finishes before they can proceed with using their application. I've tried controlling the double buffering at the JPanel level as well, but it always affects the entire application until the print spooling is complete.
    Does anyone have any suggestions to solve this annoying SWING printing problem?
    Thanks,
    - Tony

    When you post code, make sure and put it between code
    tags, so it looks good:
    public static void main(String[] args) {
    System.out.println("Doesn't this look great?");
        public int print(Graphics g, PageFormat pf, int pageIndex) {
            System.out.println( "Calling print(g,pf,pageIndex) method" );
            int response = NO_SUCH_PAGE;
            Graphics2D g2 = (Graphics2D) g;
    // for faster printing, turn off double buffering
            disableDoubleBuffering(componentToBePrinted);
            Dimension d = componentToBePrinted.getSize(); //get size of document
            double panelWidth = d.width; //width in pixels
            double panelHeight = d.height; //height in pixels
            double pageHeight = pf.getImageableHeight(); //height of printer page
            double pageWidth = pf.getImageableWidth(); //width of printer page
            double scale = pageWidth / panelWidth;
            int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight);
    // make sure not print empty pages
            if (pageIndex >= totalNumPages) {
                response = NO_SUCH_PAGE;
            } else {
    // shift Graphic to line up with beginning of print-imageable region
                g2.translate(pf.getImageableX(), pf.getImageableY());
    // shift Graphic to line up with beginning of next page to print
                g2.translate(0f, -pageIndex * pageHeight);
    // scale the page so the width fits...
                g2.scale(scale, scale);
                componentToBePrinted.paint(g2); //repaint the page for printing
                enableDoubleBuffering(componentToBePrinted);
                response = Printable.PAGE_EXISTS;
            return response;
        }

Maybe you are looking for

  • Hdmi to RCA adapter

    I'm using a new intel mac mini to replace a video player in our middle school production studio. the Mac mini is running Mac is Lion, and a software package called Playback Pro. the main monitor is using the mini display port, and I purchased an hdmi

  • Alternative for WBS BOM

    hello In standard BOM for PP in T-code eg cs01 I can write alternative. But if I want to create WBS BOM with T-code cs71 I can't see such field for alternative. I checked in help.sap.com that alternative for WBS BOM are not used. I don't know why but

  • Clustering, ServletContext

    Is there no way to insure that ServletContext is propagated across a cluster           in Weblogic 6.1 sp1 without using another product? I am trying to make a           cache of some data that will be available to all servlets in a cluster The      

  • Front Row not finding iTunes?

    I recently moved all my music to an external hard drive, and since then, I haven't been able to use Front Row. The application starts up perfectly, but when I go to find any music to play, it says there is no music to be found. The message that pops

  • Finder menus corrupted

    My finder window menus have been changed from copy and paste to codes like N151 N153, etc. I reinstalled the OS and it's still like that. Has anyone run into this problem? Any insight? Thanks...TJ