TableBorder after overwrite paintComponent Method

Hello,
I created my own TableCellRenderer and overwrite the paintComponent() method to rotate the content in the header of my JTable.
Now the TableHeader has no borders anymore. I tried to set the border again, but nothing solved my problem. I tried it in all classes to set the border.
Anyone an idea how to get the borders back in the tableheader?
Here's the Code:
----------------------------- class RowHeaderTable -----------------------------
import java.awt.*;
import javax.swing.*;
public class RowHeaderTable extends JFrame {
     private static final long serialVersionUID = 1L;
     public RowHeaderTable() {
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          TableModel tm = new TableModel();
          // Create a column model for the main table. This model ignores the first
          // column added, and sets a minimum width of 150 pixels for all others.
          HeaderTableColumnModel colMod = new HeaderTableColumnModel();
          // Create a column model that will serve as our row header table. This
          // model picks a maximum width and only stores the first column.
          BodyTableColumnModel rowHeaderModel = new BodyTableColumnModel();
          JTable jt = new JTable(tm, colMod);
          Dimension d = jt.getTableHeader().getPreferredSize();
          d.height = 80;
          d.width = 1000;
          jt.getTableHeader().setPreferredSize(d);
          // Set up the header column and get it hooked up to everything
          JTable headerColumn = new JTable(tm, rowHeaderModel);
          jt.createDefaultColumnsFromModel();
          headerColumn.createDefaultColumnsFromModel();
          // Make sure that selections between the main table and the header stay
          // in sync (by sharing the same model)
          jt.setSelectionModel(headerColumn.getSelectionModel());
          // Make the header column look pretty
          //headerColumn.setBorder(BorderFactory.createEtchedBorder());
          headerColumn.setBackground(jt.getTableHeader().getBackground());
          headerColumn.setColumnSelectionAllowed(false);
          headerColumn.setCellSelectionEnabled(true);
          // Put it in a viewport that we can control a bit
          JViewport jv = new JViewport();
          jv.setView(headerColumn);
          jv.setPreferredSize(headerColumn.getMaximumSize());
          // With out shutting off autoResizeMode, our tables won't scroll
          // correctly (horizontally, anyway)
          jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
          // We have to manually attach the row headers, but after that, the scroll
          // pane keeps them in sync
          JScrollPane jsp = new JScrollPane(jt);
          jsp.setRowHeader(jv);
          jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader());
          getContentPane().add(jsp, BorderLayout.CENTER);
     public static void main(String args[]) {
          /*try {
               UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          } catch (ClassNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (InstantiationException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (IllegalAccessException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (UnsupportedLookAndFeelException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          RowHeaderTable rht = new RowHeaderTable();
          rht.setTitle("Fenstertitel");
          rht.setSize(500, 480);
          rht.setLocation((rht.getToolkit().getScreenSize().width/2)-(rht.getSize().width/2), (rht.getToolkit().getScreenSize().height/2)-(rht.getSize().height/2));
          rht.setVisible(true);
}----------------------------- class RotatedTableCellRenderer -----------------------------
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.TableCellRenderer;
public class RotatedTableCellRenderer extends JLabel implements TableCellRenderer {
     private static final long serialVersionUID = 1L;
     protected int m_degreesRotation = -90;
     public RotatedTableCellRenderer(int degrees) {
          m_degreesRotation = degrees;
     public Component getTableCellRendererComponent(JTable table, Object value,
               boolean isSelected, boolean hasFocus, int row, int column) {
          this.setToolTipText(value.toString());
          if(value.toString().length()>=15){
               this.setText(value.toString().substring(0, 12) + "...");
          else {
               this.setText(value.toString());
          this.setFont(new Font(this.getFont().getFamily(), Font.PLAIN, 12));
          return this;
     public void paintComponent(Graphics g) {
          Graphics2D g2 = (Graphics2D)g;
          g2.setClip(0,0,this.getWidth(),this.getHeight());
          g2.setColor(Color.BLACK);
          AffineTransform at = new AffineTransform();
          at.setToTranslation(this.getWidth(), this.getHeight());
          g2.transform(at);
          double radianAngle = ( ((double)m_degreesRotation) / ((double)180) ) * Math.PI;
          at.setToRotation(radianAngle);
          g2.transform(at);
          g2.drawString(this.getText(), 3.0f, -((this.getWidth()/2)-3));
          super.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
}----------------------------- class HeaderTableColumnModel -----------------------------
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;
public class HeaderTableColumnModel extends DefaultTableColumnModel {
     private static final long serialVersionUID = 1L;
     boolean first = true;
     public void addColumn(TableColumn tc) {
          // Drop the first column . . . that'll be the row header
          if (first) { first = false; return; }
          tc.setPreferredWidth(25);
          tc.setHeaderRenderer(new RotatedTableCellRenderer(-90));
          super.addColumn(tc);
}----------------------------- class BodyTableColumnModel -----------------------------
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;
public class BodyTableColumnModel extends DefaultTableColumnModel{
     private static final long serialVersionUID = 1L;
     boolean first = true;
     public void addColumn(TableColumn tc) {
          if (first) {
               tc.setMaxWidth(tc.getPreferredWidth());
               super.addColumn(tc);                         
               first = false;
}----------------------------- class TableModel -----------------------------
import javax.swing.table.AbstractTableModel;
public class TableModel extends AbstractTableModel{
     private static final long serialVersionUID = 1L;
     String data[] = {"", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t"};
     public String headers[] = {"Row #", "Hier steht der lange Text 1", "Hier steht der lange Text 2", "Hier steht der lange Text 3", "Hier steht der lange Text 4", "Hier steht der lange Text 5", "Hier steht der lange Text 6", "Hier steht der lange Text 7", "Hier steht der lange Text 8", "Hier steht der lange Text 9", "Hier steht der lange Text 10"
               , "Hier steht der lange Text 11", "Hier steht der lange Text 12", "Hier steht der lange Text 13", "Hier steht der lange Text 14", "Hier steht der lange Text 15", "Hier steht der lange Text 16", "Hier steht der lange Text 17", "Hier steht der lange Text 18", "Hier steht der lange Text 19", "Hier steht der lange Text 20"};
     public int getColumnCount() {
          return data.length;
     public int getRowCount() {
          return 1000;
     public String getColumnName(int col) {
          return headers[col];
     // Synthesize some entries using the data values & the row #
     public Object getValueAt(int row, int col) {
          return data[col] + row;
Message was edited by:
S.Beutel

Thanks for your reply camickr.
I've been looking into ways around the rendering issues of paintComponent and it is interesting to see some of the methods necessary to overcome this (e.g setOpaque, repaint etc).
One method I saw was putting the objects you want to draw into a data structure (i.e ArrayList) and then using this to draw multiple objects onto the screen. Thus overcomming the super.paintComponent issue of erasing previous drawings. Is this the "preferred" way or is there a more practical solution.
Chris.

Similar Messages

  • Problem after over riding paintComponent() method

    I am over riding the paintComponent() method for a button to show the text in 2 lines. But when I invoke setEnabled(false) on the button, the button is getting disabled but the text is not.
    Could any one please let me know how to do that.
    The code for the paintComponent() method is pasted for reference
    protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    int w = getWidth();
    int h = getHeight();
    FontMetrics fm = g.getFontMetrics();
    int textw1 = fm.stringWidth(text1);
    int textw2 = fm.stringWidth(text2);
    FontRenderContext context = g2.getFontRenderContext();
    LineMetrics lm = getFont().getLineMetrics(text1, context);
    int texth = (int)lm.getHeight();
    prefHeight = texth;
    int x1 = (w - textw1) / 2;
    int x2 = (w - textw2) / 2;
    int th = (texth * 2);
    int dh = ((h - th) / 2);
    int y1 = dh + texth - 3;
    int y2 = y1 + texth;
    // Draw texts
    g.setColor(getForeground());
    g.drawString(text1, x1, y1);
    g.drawString(text2, x2, y2);
    regards,
    shantanu

    Hi,
    Thanks for advices, I solved the problem...it was simplier than i thought. When the g.drawImage(.... is called ) i just added Thread.sleep( time ) after that line. This gives the sound therad time to play the sound without interrput and time to main thread to handle the image. All works now pretty much as i thought, except when JFrame is overlapped the image is not drawn again...this can be corrected ( maybe?)by adding windoslistener and implement the methods in that inteface and make some repainting in different situations. But cause you gave me the magic work Thread priority I hox! the problem, so here goes 10 duke dollars.

  • PaintComponent method problems...

    Hi, I am developing an game application ( just for fun ) and I have a huge problem with paintComponent method. I Have a class ImagePanel that extends JPanel class. The ImagePanel class overrides the paintComponent method and paintChildren method ( since i have added components inside the JPanel also these must be painted ). The ImagePanel is instantied in my main class IntroView which extends JFrame where it's added. Now when the IntroPanel is created i have noticed that the paintComponent and paintChildren method is called all over again . I Have a soundclip playing in background in it's own thread and this continously paintComponent method call causes the sound clip to break off in few seconds. I Have tried to use JLabel instead of JPanel, but then the image is not shown( alltougth the methods are called only once ). I Have also tried next code to get rid of continous paintComponent call
    ...from ImagePanel class
    ImagePanel extends JPanel.....
    public final void paintComponent( Graphics g )
    if( firstTime )
    super.paintComponent( g );
    g.drawImage( myImage, 0, 0, this );
    firstTime = false;
    public final void paintChildrens( Graphics g )
    if( paintChildren )
    super.paintChildren( g );
    add( startLabel );
    add( optionsLabel );
    paintChildren = false;
    public boolean isOpaque()
    return true;
    Now the paintComponent and paintChildren is called only once. There is still a "little problem" since the paintComponent doesen't paint the image, it paints only the background( I think g.drawImage(...) didint have time to paint the image? ). Also the labels added in paintChildren method are not shown. Sounds paly now just fine.This situation makes me grazy. Please consult me with this problem.....i can surely send also the whole source if needed. There is no effect if I change isOpaque to true or false.

    Hi,
    Thanks for advices, I solved the problem...it was simplier than i thought. When the g.drawImage(.... is called ) i just added Thread.sleep( time ) after that line. This gives the sound therad time to play the sound without interrput and time to main thread to handle the image. All works now pretty much as i thought, except when JFrame is overlapped the image is not drawn again...this can be corrected ( maybe?)by adding windoslistener and implement the methods in that inteface and make some repainting in different situations. But cause you gave me the magic work Thread priority I hox! the problem, so here goes 10 duke dollars.

  • PaintComponent method refuses to be invoked.

    Hello All!
    I have a problem with graphics representation by swing. Namely I have an application based on Jframe object. It includes three Jpanel components. I need to map information from Jtable as diagram in the plotPanel. That�s code fragment I try to use:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.JComponent.*;
    import java.lang.*;
    import java.io.*;
    * @author  Administrator
    public class ROC extends javax.swing.JFrame{
    public ROC() {
            initComponents();
    /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            menuPanel = new javax.swing.JPanel();
            openButton = new javax.swing.JButton();
            tablePanel = new javax.swing.JPanel();
            pointsTable = new javax.swing.JTable();
            generateButton = new javax.swing.JButton();
            plotPanel = new javax.swing.JPanel();
            plotPanel.add(new PlotArea(), java.awt.BorderLayout.CENTER);
    ������ //This is a piece of code to initialize other components
            plotPanel.setLayout(new java.awt.BorderLayout());
            plotPanel.setBackground(java.awt.Color.white);
            plotPanel.setPreferredSize(new java.awt.Dimension(600, 380));
            plotPanel.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);
            plotPanel.addContainerListener(new java.awt.event.ContainerAdapter() {
                public void componentAdded(java.awt.event.ContainerEvent evt) {
                    plotPanelComponentAdded(evt);
            getContentPane().add(plotPanel, java.awt.BorderLayout.CENTER);
            pack();
    ������  // Different functions (such as loading data from the file to JTable i.e.)
           public static void main(String args[]) {
            System.out.println("Application starts");
            new ROC().show();
        // Variables declaration - do not modify
        private javax.swing.JPanel menuPanel;
        private javax.swing.JButton openButton;
        private javax.swing.JPanel tablePanel;
        private javax.swing.JTable pointsTable;
        private javax.swing.JButton generateButton;
        private javax.swing.JPanel plotPanel;
        // End of variables declaration
    public class PlotArea extends javax.swing.JComponent{
        /** Creates new plotPanel */
        public PlotArea() {
            System.out.println("PlotArea has been created");
            setPreferredSize(new java.awt.Dimension(600, 380));
            setMinimumSize(new java.awt.Dimension(200, 100));
            super.setBorder(BorderFactory.createLineBorder(Color.red, 5));
            repaint();
        public void paintComponent(java.awt.Graphics g) {
            System.out.println("PaintComponent method has been invoked");
            Graphics2D g2d = (Graphics2D)g;
    ������ // this is the code to implement custom painting
    }The trouble is that PaintComponent method hasn�t been invoked. Help me please. What should I do to cause PaintComponent to be performed?

    You might want to ensure your "plotPanel" uses a BorderLayout if you're specifying a constraint:
    plotPanel = new javax.swing.JPanel(new BorderLayout());
    plotPanel.add(new PlotArea(), java.awt.BorderLayout.CENTER);You shouldn't need to call "repaint" in the constructor of PlotArea, either. I doubt it'll make any difference.
    Hope this helps.

  • How to get the previous state of my data after issuing coomit method

    How to get the previous state of some date after issuing commit method in entity bean (It should not use any offline storage )

    >
    Is there any way to get the state apart from using
    offline storage ?As I said the caller keeps a copy in memory.
    Naturally if it is no longer in memory then that is a problem.
    >
    and also what do you mean by auditlog?
    You keep track of every change to the database by keeping the old data. There are three ways:
    1. Each table has a version number/delete flag for each record. A record is never updated nor deleted. Instead a new record is created with a new version number and with the new data.
    2. Each table has a duplicate table which has all of the same columns. When the first table is modified the old data is moved to the duplicate table.
    3. A single table is used which has columns for 'table', 'field', 'data' and 'activity' (update, delete). When a change is made in any table then this table is updated. This is generally of limited useability due to the difficulty in recovering the data.
    All of the above can have a user id, timestamp, and/or additional information which is relevant to the data being changed.
    Note that ALL of this is persisted storage.
    I am not sure what this really has to do with "offline storage" unless you are using that term to refer to backed up data which is not readily available.

  • This paintComponent Method is Annoying - HELP

    ok, I think I touched upon this problem sometime earlier, however I face a larger problem which I've been trying to solve by a different and simpler means but I get nothin.
    I have a paintComponent method which DRAWS lines, strings and shapes that get PAINTED on to a JFrame all good and well.
    Now, because of the amount of lines, strings and shapes I have on this "paintComponent", I want to put it in a class of its own. and THEN call it from the class it was in.
    So I want to create a new class, just for the paintComponent.
    Now, I've tried Numerous ways of trying to call it from another class but it just comes up as a blank screen. Oh and no I am not calling it directly too.
    Does anyone know where I am going wrong?
    help would be very much appreciated.

    ok LETS do this.
    class beep
    I call the paintComponent here to paint my JFrame BUT HOW!
    class drawingBoard----------------------------------------------------
    // create a rectangle called 'therectangle';
    protected void paintComponent(Graphics g)
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.draw(therectangle)
    g2.drawString("", 100, 100)
    Edited by: Calibre2007 on Feb 20, 2008 4:11 PM
    Edited by: Calibre2007 on Feb 20, 2008 4:11 PM

  • Overriding paintcomponent method JButton

    Hi,
    I'm trying to make my own buttons (with a JPEG image as template and a string painted on this template, depending on which button it is) by overriding the paintComponent-method of the JButton class, but I still have a small problem. I want to add some mouse-events like rollover and click and the appropriate animation with it (when going over the button, the color of the button becomes lighter, when clicking, the button is painted 2 pixels to the left and to the bottom). But my problem is there is some delay on these actions, if you move the mousepointer fast enough, the pointer can already be on another button before the previous button is restored to its original state. And of course, this isn't what I want to see.
    I know you can use methods like setRollOverIcon(...), but if doing so, I think you need a lot of images ( for each different button at least 3) and I want to keep the number of images to a minimum.
    I searched the internet and these forums for a solution, but I didn't found any. I'm quite sure there is at least one good tutorial on this since I already tried to do this once, but I forgot how to do it, and I can't find the tutorial anymore.
    This is an example of the MyButton-class I already wrote, I hope it clarifies my problem:
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class MyButton extends JButton{
         BufferedImage button = null;
         int x, y;
         String text = "";
         MyButton(String t){
              super(t);
              text = t;
              setContentAreaFilled(false);
              setBorderPainted(false);
              setFocusPainted(false);
              addMouseListener(new MouseListener(){
                   public void mouseClicked(MouseEvent arg0) {
                        x += 2;
                        y += 2;
                   public void mouseEntered(MouseEvent arg0) {
                        //turn lighter
                   public void mouseExited(MouseEvent arg0) {
                        x -= 2;
                        y -= 2;
                   public void mousePressed(MouseEvent arg0) {}
                   public void mouseReleased(MouseEvent arg0) {}
         protected void paintComponent(Graphics g){
              Graphics2D g2d = (Graphics2D)g;
              try{
                   button = ImageIO.read(new File("Red_Button.jpg"));
              }catch(IOException ioe){}
              //Drawing JButton
              g2d.drawImage(button, null, x, y);
              g2d.drawString(text, x+5, y+5);     
    }Thanks in advance,
    Sam

    Okay, thanks, I replaced the image-read-in into the constructor of a JButton, and I think it goes a lot faster now (but that can be my imagination).
    I still use a mouseListener because I have no idea how to use the ButtonModelinterface. I searched to find a good tutorial, but I didn't really find one? Any recommendations (yes, I read the sun-tutorial, but did not find it really explanatory).
    Here's a complete SSCCE (although it isn't really necessary anymore since my main problem seams to be solved):
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class MyButton extends JButton{
         BufferedImage button = null;
         int x, y;
         String text = "";
         public MyButton(String t){
              super(t);
              text = t;
              try{
                   button = ImageIO.read(new File("Blue_Button.jpg"));
              }catch(IOException ioe){}
              setBorderPainted(false);
              addMouseListener(new MouseListener(){
                   public void mouseClicked(MouseEvent arg0) {}
                   public void mouseEntered(MouseEvent arg0) {
                        x += 2;
                        y += 2;
                   public void mouseExited(MouseEvent arg0) {
                        x -= 2;
                        y -= 2;
                   public void mousePressed(MouseEvent arg0) {}
                   public void mouseReleased(MouseEvent arg0) {}
         protected void paintComponent(Graphics g){
              Graphics2D g2d = (Graphics2D)g;
              g2d.drawImage(button, null, x, y);
              g2d.drawString(text, x+25, y+15);     
         public void fireGUI(){
              JFrame frame = new JFrame("ButtonModelTester");
              frame.setLayout(new GridLayout(2,1,10,10));
              frame.add(new MyButton("Test1"));
              frame.add(new MyButton("Test2"));
              frame.setSize(200,100);
              frame.setVisible(true);
         public static void main(String[] args){
              SwingUtilities.invokeLater(new Runnable(){
                   public void run(){
                        new MyButton(null).fireGUI();
    }Thanks,
    Sam
    PS: you mentioned my earlier posts? So they are still somewhere on this forum, because I couldn't find the anymore, they aren't in my watch list. I Checked this since I thought I asked something similar before...

  • PaintComponent Method

    Hello,
    can any one tell me when paintComponent(Graphics gc){} method will be called???
    it's needed that i have to extends JPanel.
    in my prog m extending theJApplet class.
    can paintComponent(Graphics gc){} will called if m extending the JApplet..
    plz tell me..
    waiting 4 yr reply.
    Regards,
    Shruti.

    Swing related questions should be posted in the Swing forum.
    You override paintComponent of JPanel and add the panel to your JApplet. The paintComponent() method will be called as required.

  • PaintComponent method seems not to be called - im stumped

    Please find two simple classes:
    When debugging why my background image wont display I have discovered that the paintComponent() method of my BackgroundJPanel class never gets invoked. Its part of the heirarchy so im not sure why.. You will notice a few system.out's the only thing my console shows is a "zooob!" comment..
    package xrpg.client;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import javax.swing.*;  
    import javax.swing.ImageIcon;
    import javax.swing.JLayeredPane;
    import java.awt.Frame;
    import java.awt.Color;
    import jka.swingx.*;
    public class XClient {
          * @param args
         public static void main(String[] args)
              XClient app = new XClient();
         public XClient()
              //set look and feel
              try { UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName()); }
              catch (Exception e) { }
              //     Create the top-level container
              JFrame frame = new JFrame("XClient");
              frame.setUndecorated(true);
              frame.setBackground(Color.black);  
              // create background panel and add it to frame
              BackgroundJPanel bPanel = new BackgroundJPanel("xrpg/client/content/xrpg00002.jpg");
              bPanel.setBackground(Color.white);  
              frame.getContentPane().add(bPanel, java.awt.BorderLayout.CENTER);
              //JButton button = new JButton("I'm a Swing button!");
              //bPanel.add(button);
              //button.setLocation(10,10);
              frame.addWindowListener(new WindowAdapter(){
               public void windowClosing(WindowEvent e)
                    System.exit(0);
          // show & size frame
              frame.pack();
          frame.setVisible(true);
          Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
              frame.setSize(dim);
    package jka.swingx;
    import javax.swing.*;
    import java.awt.*;
    public class BackgroundJPanel extends JPanel {
              private Image img ;
              private boolean draw = true;
              public BackgroundJPanel(String imageResource)
                   System.out.println( "zooob!" );
                   // load & validate image
                   ClassLoader cl = this.getClass().getClassLoader();
                   try { img = new ImageIcon(cl.getResource(imageResource)).getImage(); } catch(Exception e){}
                   if( img == null ) {
                        System.out.println( "Image is null" );
                        draw=false;
                   if( img.getHeight(this) <= 0 || img.getWidth( this ) <= 0 ) {
                        System.out.println( "Image width or height must be +ve" );
                        draw=false;
                   setLayout( new BorderLayout() ) ;
              public void drawBackground( Graphics g ) {
                   System.out.println( "zeeeb!" );
                   int w = getWidth() ;
                   int h = getHeight() ;
                   int iw = img.getWidth( this ) ;
                   int ih = img.getHeight( this ) ;
                   for( int i = 0 ; i < w ; i+=iw ) {
                        for( int j = 0 ; j < h ; j+= ih ) {
                             g.drawImage( img , i , j , this ) ;
              protected void paintComponent(Graphics g) {
                   System.out.println( "zeeeha!" );
                   super.paintComponent(g);
                   if (draw) drawBackground( g ) ;
    }

    why my "original post with two class" example is not calling the paintComponent() A couple of things have conspired to prevent the invocation of the paintComponent() method.
    The preferredSize of your panel is (0, 0). Therefore, the size of all the components added to the frame is (0, 0). when the frame is made visible. It also appears than when you reset the size of the frame there is no need to repaint the panel since its size is (0, 0);
    Simple solution is to change the order of your code to be:
    frame.setSize(dim);
    frame.setVisible(true);A couple of notes:
    a) to maximize the frame, rather than setting the size manually it is better to use:
    frame.setExtendedState (JFrame.MAXIMIZED_BOTH);
    b) instead of using a window listener to close the frame it is easier to use:
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  • Automatic popup for reason of rej after an async method

    Hello,
    How to get a reason of rejection popup after an asynchronous method?
    Currently I am using the standard singlerelease method of object type BUS2012 for the release of purchase order. Now once this order gets rejected the user wants an <b>automatic popup for entering the reason for rejection</b> and NOT as another workitem in his inbox for execution.
    Please let me know how can I provide this functionality in the current scenario. <b>Also since the Previous method(singlerelease) is asynchronous “Advance with Dialog” does not work.</b>
    Thanks and Regards,
    Anuj

    It does not work for asynchronous methods but works for synchronous methods. As per SAP the advance with immediate dialog should work for asynchronous methods as well.
    Below is an excerpt from SAP help.
    At runtime, after completion of a step, (= work item has status completed), the workflow system checks the following properties of the subsequent work item:
    •     Is it a dialog work item?
    •     Does the corresponding task refer to a synchronous method?
    •     Is the indicator Advance with dialog set?
    •     Is the actual agent also a recipient of this work item?
    •     Has the work item reached all of its requested starts?
    If the answer to all these questions is yes, the workflow system automatically starts execution of the work item.
    May be you should write a message to SAP. In the meanwhile you can create a synchronous method for the business object.
    -Kiran

  • Changing exception clause in method signature when overwriting a method

    Hi,
    I stumbled upon a situation by accident and am not really clear on the details surrounding it. A short description:
    Say there is some API with interfaces Foo and Bar as follows:
    public interface Foo {
       void test() throws Exception;
    public interface Bar extends Foo {
       void test();
    }Now, I find it strange that method test() for interface Bar does not need to define Exception in its throws clause. When I first started with Java I was using Java 1.4.2; I now use Java 1.6. I cannot remember ever reading about this before and I have been unable to find an explanation or tutorial on how (or why) this works.
    Consider a more practical example:
    Say there is an API that uses RMI and defines interfaces as follwows:
    public interface RemoteHelper extends Remote {
       public Object select(int uid) throws RemoteException;
    public interface LocalHelper extends RemoteHelper {
       public Object select(int uid);
    }As per the RMI spec every method defined in a Remote interface must define RemoteException in its throws clause. The LocalHelper cannot be exported remotely (this will fail at runtime due to select() in LocalHelper not having RemoteException in its clause if I remember correctly).
    However, an implementing class for LocalHelper could represent a wrapper class for RemoteHelper, like this:
    public class Helper implements LocalHelper {
       private final RemoteHelper helper;
       public Helper(RemoteHelper helper) {
          this.helper = helper;
       public Object select(int id) {
          try {
             return (this.helper.select(id));
          } catch(RemoteException e) {
             // invoke app failure mechanism
    }This can uncouple an app from RMI dependancy. In more practical words: consider a webapp that contains two Servlets: a "startup" servlet and an "invocation" servlet. The startup servlet does nothing (always returns Method Not Allowed, default behaviour of HttpServlet), except locate an RMI Registry upon startup and look up some object bound to it. It can then make this object accessible to other classes through whatever means (i.e. a singleton Engine class).
    The invocation servlet does nothing upon startup, but simply calls some method on the previously acquired remote object. However, the invocation servlet does not need to know that the object is remote. Therefore, if the startup servlet wraps the remote object in another object (using the idea described before) then the invocation servlet is effectively removed from the RMI dependancy. The wrapper class can invoke some sort of failure mechanism upon the singleton engine (i.e. removing the remote object from memory) and optionally throw some other (optionally checked) exception (i.e. IllegalStateException) to the invocation servlet.
    In this way, the invocation servlet is not bound to RMI, there can be a single point where RemoteExceptions are handled and an unchecked exception (i.e. IllegalStateException) can be handled by the Servlet API through an exception error page, displaying a "Service Unavailable" message.
    Sorry for all this extensive text; I just typed out some thoughts. In short, my question is how and why can the throws clause change when overwriting a method? It's nothing I need though, except for the clarity (e.g. is this a bad practice to do?) and was more of an observation than a question.
    PS: Unless I'm mistaken, this is basically called the "Adapter" or "Bridge" (not sure which one it is) pattern (or a close adaptation to it) right (where one class is written to provide access to another class where the method signature is different)?
    Thanks for reading,
    Yuthura

    Yuthura wrote:
    I know it may throw any checked exception, but I'm pretty certain that an interface that extends java.rmi.Remote must include at least java.rmi.RemoteException in its throws clause (unless the spec has changed in Java 1.5/1.6).No.
    A method can always throw fewer exceptions than the one it's overriding. RMI has nothing to do with it.
    See Deitel & Deilte Advanced Java 2 Platform How To Program, 1st Ed. (ISBN 0-13-089650-1), page 793 (sorry, I couldn't find the RMI spec quick enough). Quote: "Each method in a Remote interface must have a throws clause that indicates that the method can throw RemoteException".Which means that there's always a possibility of RemoteException being thrown. That's a different issue. It's not becusae the parent class can throw RE. Rather, it's because some step that will always be followed is declared to throw RE.
    I later also noticed I could not add other checked exceptions, which made sense indeed. Your explanation made perfect sense now that I heard (read) it. But just to humour my curousity, has this always been possible? Yes, Java has always worked that way.
    PS: The overwriting/-riding was a grammatical typo (English is not my native language), but I meant to say what you said.No problem. Minor detail. It's a common mistake, but I always try to encourage proper terminology.

  • HT201302 Even though there are over 200 photos on my ipad, after trying both methods of importing and connecting with a lead, a message appears saying that there are no photos on this device. Any ideas?

    Even though there are over 200 photos on my ipad, after trying both methods of importing and connecting with a lead, a message appears saying that there are no photos on this device. Any ideas?

    Did you connect your iPad to your computer then open the application on your computer that transfers photos from a camera? Your computer should recognize the iPad as a camera. All photos in the Camera Roll on the iPad should then be seen and you should be able to copy them to the computer using that application.
    Photos that were synced to your iPad by connecting to your syncing computer cannot be copied back this way as the master file for those photos are on the syncing computer.

  • Why does the parameter of the paintComponent method have....?

    Why does the parameter of the paintComponent method have type Graphics and not Graphics2D?

    masijade. wrote:
    Additionally, it is, however, normally, a Graphics2D object's reference value that is passed around....which means most painting code starts out by casting the Graphics object to Graphics2D. You know what they say: death, taxes, and cruft... :P

  • About paintComponent method

    Hello,
    I am using swing to develop an user interface for a medium-complex program. Here is the code in the paintComponent method:
    public void paintComponent (Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
            super.paintComponents(g2);
            if (frame.m == null)
                System.out.println("Es null main");
            else {
                System.out.println("No es null main");
               Vector clusters = frame.m.obtenerClusters();
                Iterator it = clusters.iterator();
                while (it.hasNext()) {
                    Cluster c = (Cluster)it.next();
                    Punto p = c.obtenerCoordinador();
                    Color color = c.obtenerColor();
                    Vector sen = c.obtenerSensores();
                    Iterator itS = sen.iterator();
                    while (itS.hasNext()) {
                       Sensor s = (Sensor)itS.next();
                       dibujarSensor(g2, s, color);
                    if (p != null) {
                        dibujarCoordinador(g2, p, color);
                        if (frame.isSelectedDibujarCirculo()) {
                            dibujarCirculoMinimo(g2, c.obtenerCoordinador(), c.obtenerRadio(), color);
                NodoSink s = frame.m.obtenerSink();
                if (s != null) {
                  dibujarSink(g2,s);
        }Every time that this method is called (by me using repaint() or by the virtual machine), the program needs to "walk" over the hole Vector structure and paint again and again the same things, which is very inefficient.
    There are some way to avoid it? I'm worry about it because the Vector structure is commonly very long.
    Thanks!

    Create a BufferedImage and do the custom painting on the BufferedImage.
    If your painting is relatively static then you could create an ImageIcon from the BufferedImage and add the icon to a label and add the label to the GUI. If you need to change the custom painting then you would need to recreate the icon and update the image.
    If you painting is relatively dynamic, then you just change the paintComponent() method to draw the buffered image.

  • Cancel WorkItem after execute a Method

    Hi all,
    Is there a way to cancel a workitem after executing a method?
    I put this method at the tab METHODS in the activity USER DECISION, but when the method is executed before the workitem, i need this closed.
    It´s because i am using a worklist at the PORTAL, and then what I need is to show the workitem at the UWL and then when the user click on the link to the WI, execute the METHOD (this method opens a webpage made with webdynpro).
    Best Regards,
    Ricardo

    I think you want to complete the workitem , once the workitem is executed from the UWL right?
    if this is the case as you said that you are using a Decision step which will open a webdynpro applicaiton once it is executed, then instead of using the methods tab, I suggest you to modify from the application side
    1. If the end user clicks on the Approve button or reject button UNder the actions of these button, call the standard SAP fm SAP_WAPI_DECISION_COMPLETE to which you have to pass the currently executed workitem ID and Decision for approve as 0001 and for reject 0002.
    this is more suitable and simple way of completing the worktem.

Maybe you are looking for

  • How do I get a line out signal from my macpro mid-2012

    I went to Preferences, Sound, Output. The only option is HEADPHONES. I want to send music from iTunes to a sound mixing board. I can use the headphone port, but the signal is weak and poor sound quality. I used to use  my iPod which works well becaus

  • Oracle Replication and SQL*Load direct Path

    We are setting up Oracle replication and have a few tables which are loaded using SQL*Loader Direct path. I have following questions: 1. Can MultiMaster replication replicate direct patch sqlloaded data. 2. If the answer to the above question is no,

  • Search query TREX

    Hi, I try to configure the KM iview search query to return only result by the name of documents(or part of name) and not as full text. For example, if i make a search on "TEST" i can see in the result page: - document.doc <i>(name of file)</i> this a

  • Advanced file browsing capabilities

    I would like the Finder to improve on the way it can use extended attributes... Currently, we can edit a property named "Spotlight Comments", which in reality is "com.apple.metadata:kMDItemFinderComment". In list mode we can make a column appear, wit

  • How can i tell what Service Pack I am on

    Post Author: Fran CA Forum: Upgrading and Licensing Hi there, I am running Crystal Reports XI and wanted to know how i can tell what Service Pack is installed - i looked under help but couldnt see anything obvious. Thanks Fran