Canvas - Graphic object properties

The problem is as following:
I’ve got a form where objects are situated on two tab pages. A number of text_items are placed on rectangle graphic objects. My goal is to control visibility of those objects depending on certain conditions:
With text items correctly works:
QUANTITY_ID ITEM;
QUANTITY_ID := find_item('PRODUCT.QUANTITY');
set_item_property (QUANTITY_ID, visible, property_false);
With graphics object I’m facing the problem with reaching the item:
G_QUANTITY_ID ITEM;
G_QUANTITY_ID := find_item('?????????????.G_QUANTITY');
Placement of the object:
Forms -> Canvases -> Tab Pages -> [Product] -> Graphics -> [G_QUANTITY]
Where:
[Product] – Name of the tab page
[G_QUANTITY] – Rectangle graphic object
I’ll appreciate any kind of help. Thanks in advance.

Hello,
There is no available built-in concerning the graphic objects displayed on the canvas. All you can do use another stacked canvas to show/hide the graphic objects located on it.
Francois

Similar Messages

  • Read graphic Object properties 'scaling'

    Hi all,
    I am trying to read 'scaling' graphic Object properties values using in below code.  In case graphic having 60% that time also I am getting only 100%. So can I get some help? Thank you very much.
    function CheckScaing(doc)
       graphicObj = doc.FirstGraphicInDoc;
    while(graphicObj.ObjectValid())
            graphicObj = graphicObj.NextGraphicInDoc;
                  if(graphicObj.type == Constants.FO_Inset)
                      name = graphicObj.InsetFile;
                      var insetDpis=graphicObj.InsetDpi
                      alert(insetDpis)

    Hello,
    There is no available built-in concerning the graphic objects displayed on the canvas. All you can do use another stacked canvas to show/hide the graphic objects located on it.
    Francois

  • GUI graphical objects properties

    I want to develop a GUI for an RF switching network where the user see a diagram of the actual network. I did something similar before but I was using a pdf of an autocad drawing of the network where I placed custom controls to represent the switches (see the attached front panel picture). By clicking on the switch it was changing position. Note that the switching network to be developped is a lot more bigger that the one showed. The GUI will be a top level diagram and by clicking on some section the detail of these sections will open and that's where the user will set the switches
    Now I would like the created path to change color to better see it. Is there a graphical application I could use where the line objects have properties that can be changed in LabVIEW? Or is there a way to do it in LabVIEW?
    Thanks for your suggestions.
    Ben
    Attachments:
    Switching Network.PNG ‏298 KB

    Have you reviewed the examples we have linked into the Picture Control thread located in the Breakpoint?
    THe center portion of the GUI shown in these two images was rendered using a Picture.
    and the same with 6 cells used and gas routed thru some cells.
    and for my model railroad I developed this interface so I can see which blocks are allocated to which cab control.
    Just trying to help,
    (another) Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to change font/ font color etc in a graphic object using JCombobox?

    Hello
    My program im writing recently is a small tiny application which can change fonts, font sizes, font colors and background color of the graphics object containing some strings. Im planning to use Jcomboboxes for all those 4 ideas in implementing those functions. Somehow it doesnt work! Any help would be grateful.
    So currently what ive done so far is that: Im using two classes to implement the whole program. One class is the main class which contains the GUI with its components (Jcomboboxes etc..) and the other class is a class extending JPanel which does all the drawing. Therefore it contains a graphics object in that class which draws the string. However what i want it to do is using jcombobox which should contain alit of all fonts available/ font sizes/ colors etc. When i scroll through the lists and click the one item i want - the graphics object properties (font sizes/ color etc) should change as a result.
    What ive gt so far is implemented the jcomboboxes in place. Problem is i cant get the font to change once selecting an item form it.
    Another problem is that to set the color of font - i need to use it with a graphics object in the paintcomponent method. In this case i dnt want to create several diff paint.. method with different property settings (font/ size/ color)
    Below is my code; perhaps you'll understand more looking at code.
    public class main...
    Color[] Colors = {Color.BLUE, Color.RED, Color.GREEN};
            ColorList = new JComboBox(Colors);
    ColorList.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ev) {
                     JComboBox cb = (JComboBox)ev.getSource();
                    Color colorType = (Color)cb.getSelectedItem();
                    drawingBoard.setBackground(colorType);
              });;1) providing the GUI is correctly implemented with components
    2) Combobox stores the colors in an array
    3) ActionListener should do following job: (but cant get it right - that is where my problem is)
    - once selected the item (color/ font size etc... as i would have similar methods for each) i want, it should pass the item into the drawingboard class (JPanel) and then this class should do the job.
    public class DrawingBoard extends JPanel {
           private String message;
           public DrawingBoard() {
                  setBackground(Color.white);
                  Font font = new Font("Serif", Font.PLAIN, fontSize);
                  setFont(font);
                  message = "";
           public void setMessage(String m) {
                message = m;
                repaint();
           public void paintComponent(Graphics g) {
                  super.paintComponent(g);
                  //setBackground(Color.RED);
                  Graphics2D g2 = (Graphics2D) g;
                  g2.setRenderingHint             
                  g2.drawString(message, 50, 50);
           public void settingFont(String font) {
                //not sure how to implement this?                          //Jcombobox should pass an item to this
                                   //it should match against all known fonts in system then set that font to the graphics
          private void settingFontSize(Graphics g, int f) {
                         //same probelm with above..              
          public void setBackgroundColor(Color c) {
               setBackground(c);
               repaint(); // still not sure if this done corretly.
          public void setFontColor(Color c) {
                    //not sure how to do this part aswell.
                   //i know a method " g.setColor(c)" exist but i need to use a graphics object - and to do that i need to pass it in (then it will cause some confusion in the main class (previous code)
           My problems have been highlighted in the comments of code above.
    Any help will be much appreciated thanks!!!

    It is the completely correct code
    I hope that's what you need
    Just put DrawingBoard into JFrame and run
    Good luck!
    public class DrawingBoard extends JPanel implements ActionListener{
         private String message = "message";
         private Font font = new Font("Serif", Font.PLAIN, 10);
         private Color color = Color.RED;
         private Color bg = Color.WHITE;
         private int size = 10;
         public DrawingBoard(){
              JComboBox cbFont = new JComboBox(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
              cbFont.setActionCommand("font");
              JComboBox cbSize = new JComboBox(new Integer[]{new Integer(14), new Integer(13)});
              cbSize.setActionCommand("size");
              JComboBox cbColor = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbColor.setActionCommand("color");
              JComboBox cbBG = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbBG.setActionCommand("bg");
              add(cbFont);
              cbFont.addActionListener(this);
              add(cbSize);
              cbSize.addActionListener(this);
              add(cbColor);
              cbColor.addActionListener(this);
              add(cbBG);
              cbBG.addActionListener(this);
         public void setMessage(String m){
              message = m;
              repaint();
         protected void paintComponent(Graphics g){
              super.paintComponent(g);
              Graphics2D g2 = (Graphics2D)g;
              g2.setColor(bg);//set background color
              g2.fillRect(0,0, getWidth(), getHeight());          
              g2.setColor(color);//set text color
              FontRenderContext frc = g2.getFontRenderContext();
              TextLayout tl = new TextLayout(message,font,frc);//set font and message
              AffineTransform at = new AffineTransform();
              at.setToTranslation(getWidth()/2-tl.getBounds().getWidth()/2,
                        getWidth()/2 + tl.getBounds().getHeight()/2);//set text at center of panel
              g2.fill(tl.getOutline(at));
         public void actionPerformed(ActionEvent e){
              JComboBox cb = (JComboBox)e.getSource();
              if (e.getActionCommand().equals("font")){
                   font = new Font(cb.getSelectedItem().toString(), Font.PLAIN, size);
              }else if (e.getActionCommand().equals("size")){
                   size = ((Integer)cb.getSelectedItem()).intValue();
              }else if (e.getActionCommand().equals("color")){
                   color = (Color)cb.getSelectedItem();
              }else if (e.getActionCommand().equals("bg")){
                   bg = (Color)cb.getSelectedItem();
              repaint();
    }

  • FrameMaker 10 - Finding all graphics in a book with a Object Properties Scaling equal to 0%?

    Is there a way in FrameMaker 10 in the book to quickly find all imported graphics (.bmp, .cgm, .jpg, & .wmf) that are out-of-aspect ratio or where the Object Properties Scaling equals 0%?
    I import a lot of graphic (around a 100 or so) in FrameMaker 10 and I would like to be reassured that all imported graphic have the correct aspect ratio, and find any that are wrong quickly.
    I would like to be able to do this search in the Book format rather than each section.
    Is there a way to do this?
    Thanks!

    Denis, this would require scripting. ExtendScript would likely be the first choice and would be perfect for the job. Given that you want to operate on the whole book at once, the script would be a little bit longer, so you might not get someone to post it here for free. I would consider it because it would be a nice addition to the samples on my website, but I can't do it right this minute. If no one offers for free, hit me up in a day or two and I might be able to accommodate  you.
    One question though... are you really looking to verify the aspect ratio? This could be a considerably more complicated task. FrameMaker doesn't save the original ratio, so you would need to reimport the graphic into some other scratchpad area, calculate the aspect ratio, then compare it to the place of reference. I'm not sure that I could go that far.
    Alex, I think you may have misunderstood the question. Also, it's not even clear if these are structured files, and if so, if there is a structured application to save as XML.
    Russ

  • On import, graphics resized after displaying object properties

    Hello, my XML files contain many links to EPS files, such as:
    <image href="mygraphic.eps" align="right" id="0B">
    After importing the XML files, the graphics are sized correctly. They're exactly the size of the imported-by-reference graphic.
    Some of the graphics resize if I display the object properties or simply save the file. For example, an EPS will resize itself 20%.
    In one file that contains two images, only one might resize itself.
    My read/write rules have no rules to resize a graphic on import.
    What could I be missing?

    Thanks for the suggestion, I'll give it a try. But I'm not sure I can even read any temperatures from this old gpu. I ran sensors-detect and it found none.
    Also, if it was a heat issue, why does it go away as soon as I restart the X server? Surely it would still be overheating. Maybe it's time to take this thing apart again and clean it out.
    Last edited by xamindar (2015-01-17 16:29:38)

  • In Object Properties dialog box, modify "tab path"...

    For FrameMaker versions up to and including 8 (and I suspect 9).
    Select a graphic, then click in sequence
    ESC g o to open the
    Object Properties dialog box. By default the dialog box opens with the insertion point in the
    Width text entry area.
    Now press TAB four times: The insertion point moves sequentially to the
    Height,
    Top,
    Left, and then
    Color text entry areas.
    I wish the last movement, to the
    Color text entry area, was replaced with movement to the
    Percent text entry area. This would enable me to use the keyboard to efficiently configure the size, position, and scaling of a graphic.
    As it is, I virtually never need to select the graphic's
    Color text entry area and the movement of the insertion point to that essentially useless tool drives me crazy: It makes me TAB all the way 'round the dialog box or grab the pointing device to get it to the
    Percent text entry area...
    Cheers,
    Riley

    Odd... What does your properties dialog look like? Can you post a screenshot of the dialog box? Also, what version of LabVIEW are you running?
    Message Edited by smercurio_fc on 06-03-2008 04:56 PM

  • Can't edit object properties (Acrobat X, Acrobat 8.x)

    I'm trying to tag a PDF for accessibility. I would like to be able to tag the images in the document as 'background'.
    Unfortunately, I'm not able to edit any of the object properties for images.
    Here's what I do:
    Expose the Content tools.
    Click Edit Object.
    Click to select an image.
    Right-click and select Properties.
    At this point, a multi-tab dialog pops up, in which all fields are disabled.
    I thought to work around the problem by going back to Acrobat 8.x, but I'm seeing the same behavior there.
    What step am I missing, here?

    These are the steps I've been told to use to edit the tags on an image:
    Open the Content section in Tools.
    Click 'Edit Object'.
    Click image to select it.
    Right-click image and select 'Properties'.
    Change to Tags tab.
    Set tag to 'Artifact.'
    These steps are impossible to complete, because all fields in the Properties (a.k.a. "TouchUp properties" [sic]) dialog are disabled.
    If in fact this has "nothing to do with tagging an image", then I shouldn't even be able to access the dialog, much less be able to access it and discover that all settings it exposes are disabled.
    In fact, every means that I've found so far that gives me access to the "TouchUp proerties" dialog for an image or a path, gives it to me with all fields except color disabled. (Please note: this is not just paths, it's also images. Even if it were just paths, that would be a serious problem, since any brochure or magazine layout is liable to contain a huge number of paths that need to be tagged as background images.)
    The ONLY ways so far that I've found that it's possible to edit the tags on an image are:
    Use 'Find...' as described above to bring the image/path/etc. into the reading order, and then use the TouchUp Reading Order dialog or right-click in the Reading Order pane to set it as background. This is inexact and time-consuming, especially for things like graphic-intensive brochures or magazine layouts.
    Use a marquee-selection in the TouchUp Reading Order tool to select objects and set them as background. This is inadequate because in many of the cases that I deal with, you'll still be left with a lot of objects you can't select in this manner. (Try using this method to select an image that has the same vertical or horizontal dimension as the page it resides on, for example.)
    If you are aware of another way, I wisth you'd tell me what it is.
    It sounds to me like you're thinking I'm using the Select Object tool. I'm not. It's pretty obvious that's not going to work, because it doesn't even afford access to the "TouchUp properties" dialog.

  • Drawing a Graphics object on a Graphics object

    Is there anyway to draw a Graphics object on another Graphics object? I'm trying to show 2 screens, side by side, on a Canvas and I'm trying to cheat a little :-P Basically, I want to take half of one screen and half of another and put them on top of each other to form one screen.
    OR is there a way to turn a Graphics object into an Image object?

    I'm not sure if this is what you're after, but you can
    - create an offscreen image using "createImage(int width, int height)" method of a Component , then
    - obtain the graphics context of the offscreen image using "getGraphics()",
    - you can then draw onto the offscreen image using the graphics context.
    hope that helps. =)

  • Saving Graphics Object

    Is it possible to transfer a Graphics Object to another Canvas so that I can use the painted graphics there?
    I have a canvas, where some texts and boxes are painted. Now I want to start another Canvas, where the user can move a Pointer in the Graphic of the other Canvas.
    So I thought I hand over the Graphics-Object to my new Canvas and overwrite my actual Graphics-Object. Now I want to paint a crosspointer and move it on the screen.
    I hope anyone has understood this stupid question.
    Great_T

    You have to use "manual" double buffering:
    private Image image = Image.creaneImage(this.getWeight(), this.getHeight());
    private Graphics graphics = image.getGraphics();
    Paint to graphics.
    public void paint(Graphics g) {
    g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
    Then pass your image in the new Canvas and continue to paint to it's
    Graphics object
    I hope this is helpful.

  • Draw to an image using graphics object

    ive been trying to this. create a starfield 800px wide and twice the height of the screen 2x600. this image would be scrolling down the screen giving the appearance of moving through space. what i did was create an image the called "starField", and created a graphics object "starFieldObj" to draw dots (stars) to this image.
    is this the correct way to do this? my program seems to work differently depending on where i call "generateStarField()" which draws to "starFieldObj"
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class Alpha1 extends Canvas implements Runnable, MouseMotionListener, MouseListener, KeyListener {
         private Image buffer; //bufer image
         private Graphics gfx;
         private Graphics starFieldObj;
         private Image playerShip;
         private int frames = 60; //frames per second
         private MediaTracker mediaTracker; //tracks loaded images
         private boolean ready; //ready to  start animation
         private int [] keys = new int[256];
         private int playerShipX = 100;
         private int playerShipY = 100;
         private static Random random = new Random();
         private Image starField;
         private int starFieldSpeed = 5;
         private int starFieldX = 0;
         private int starFieldY = -600;
         public static void main(String[] args)
              Alpha1 t = new Alpha1();
              Frame f = new Frame("blah");
              f.setSize(800, 600);
              f.add(t, BorderLayout.CENTER);
              f.show();
              t.start();
              t.requestFocus();
              f.addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent e){
                        System.exit(0);}});
         public Alpha1()
              addKeyListener(this);
              addMouseListener(this);
              ready = false;
              mediaTracker = new MediaTracker(this);
              playerShip = getToolkit().getImage("testship1.png");
              //starField = getToolkit().getImage("testbg.png");
              //mediaTracker.addImage(playerShip, 0);
              mediaTracker.addImage(starField, 0);
              try {
                   mediaTracker.waitForID(0);
              catch (InterruptedException e) {
                   e.printStackTrace();
         public void start()
              buffer = createImage(getSize().width,getSize().height);
              //starField = createImage(getSize().width,getSize().height * 2);
              gfx = buffer.getGraphics();
              //starFieldObj = starField.getGraphics();
              generateStarfield();
              ready = true;
              new Thread(this).start();
         public void mouseDragged(MouseEvent e)     {}
         public void mouseMoved(MouseEvent e)     
              playerShipX = e.getX();
              playerShipY = e.getY();
         public void mouseReleased(MouseEvent e)     {}
         public void mousePressed(MouseEvent e)     {}
         public void mouseExited(MouseEvent e)     {}
         public void mouseEntered(MouseEvent e)  {}
         public void mouseClicked(MouseEvent e)     {}
         public void keyTyped(KeyEvent keyevent)     {}
         public void keyPressed(KeyEvent keyevent)
              keys[keyevent.getKeyCode()] = 1;
              System.out.println(keyevent.getKeyCode());
         public void keyReleased(KeyEvent keyevent)     
              keys[keyevent.getKeyCode()] = 0;
         public void run()
              while (true)
                   if (isVisible())
                        repaint();
                        updatePositions();
                   }//end if
                   try 
                   { Thread.sleep(1000/frames); }
                   catch (InterruptedException e)
                   { e.printStackTrace(); }
              }//end while
         public void paint(Graphics g) {     /*empty etc*/ }
         public void updatePositions()
              if (keys[38] == 1 & keys[40] == 0) //IF UP IS PRESSED
              { playerShipY -= 3; }
              if (keys[40] == 1 & keys[38] == 0) //IF DOWN IS PRESSED
              { playerShipY += 6; }
              if (keys[37] == 1 & keys[39] == 0) //IF LEFT IS PRESSED
              { playerShipX -= 5; }
              if (keys[39] == 1 & keys[37] == 0) //IF RIGHT IS PRESSED
              { playerShipX += 5; }
              //starFieldY = starFieldY + starFieldSpeed;
              //if (starFieldY == 0)
              //     starFieldY = -600;
              //     System.out.println("dadssa");
         public int getRandom(int from, int to)
              if (from > to)
                   int randTemp;
                   randTemp = from;
                   from = to;
                   to = randTemp;
              return random.nextInt(to-from+1)+from;
         public void generateStarfield()
              starFieldObj.setColor(Color.black);
              starFieldObj.fillRect (0, 0, 800, 600 * 2);
              for (int td=0; td < 900 ; td++) //draw 900x2 dots on 800x1200 image
                        starFieldObj.fillRect (getRandom(1,800), getRandom(1,600), 1, 1);
                        starFieldObj.fillRect (getRandom(1,800) + 800, getRandom(1,600) + 800, 1, 1);
         public void update(Graphics g)
              if (ready)
                   gfx.setColor(Color.black);
                   gfx.fillRect (0, 0, this.getSize().width, this.getSize().height);
                   //gfx.drawImage(starField,starFieldX,starFieldY,null);
                   gfx.drawImage(playerShip,playerShipX,playerShipY,null);
                   //gfx.drawString(Integer.toString(showFps),5,5);
                   g.drawImage(buffer,0,0,null);
    }

    updated code, i cant get starField to be 1200px in height
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class Alpha1 extends Canvas implements Runnable, MouseMotionListener, MouseListener, KeyListener {
         private Image buffer; //bufer image
         private Graphics gfx;
         private Graphics starFieldObj;
         private Image playerShip;
         private int frames = 60; //frames per second
         private MediaTracker mediaTracker; //tracks loaded images
         private boolean ready; //ready to  start animation
         private int [] keys = new int[256];
         private int playerShipX = 100;
         private int playerShipY = 100;
         private static Random random = new Random();
         private Image starField;
         private int starFieldSpeed = 5;
         private int starFieldX = 0;
         private int starFieldY = -600;
         public static void main(String[] args)
              Alpha1 t = new Alpha1();
              Frame f = new Frame("blah");
              f.setSize(800, 600);
              f.add(t, BorderLayout.CENTER);
              f.show();
              t.start();
              t.requestFocus();
              f.addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent e){
                        System.exit(0);}});
         public Alpha1()
              addKeyListener(this);
              addMouseListener(this);
              ready = false;
              mediaTracker = new MediaTracker(this);
              playerShip = getToolkit().getImage("testship1.png");
              //starField = getToolkit().getImage("testbg.png");
              //mediaTracker.addImage(playerShip, 0);
              mediaTracker.addImage(starField, 0);
              try {
                   mediaTracker.waitForID(0);
              catch (InterruptedException e) {
                   e.printStackTrace();
         public void start()
              buffer = createImage(getSize().width,getSize().height);
              starField = createImage(getSize().width,1200);
              gfx = buffer.getGraphics();
              starFieldObj = starField.getGraphics();
              ready = true;
              new Thread(this).start();
         public void mouseDragged(MouseEvent e)     {}
         public void mouseMoved(MouseEvent e)     
              playerShipX = e.getX();
              playerShipY = e.getY();
         public void mouseReleased(MouseEvent e)     {}
         public void mousePressed(MouseEvent e)     {}
         public void mouseExited(MouseEvent e)     {}
         public void mouseEntered(MouseEvent e)  {}
         public void mouseClicked(MouseEvent e)     {}
         public void keyTyped(KeyEvent keyevent)     {}
         public void keyPressed(KeyEvent keyevent)
              keys[keyevent.getKeyCode()] = 1;
              System.out.println(keyevent.getKeyCode());
         public void keyReleased(KeyEvent keyevent)     
              keys[keyevent.getKeyCode()] = 0;
         public void run()
              generateStarfield();
              while (true)
                   if (isVisible())
                        repaint();
                        updatePositions();
                   }//end if
                   try 
                   { Thread.sleep(1000/frames); }
                   catch (InterruptedException e)
                   { e.printStackTrace(); }
              }//end while
         public void paint(Graphics g) {     /*empty etc*/ }
         public void updatePositions()
              if (keys[38] == 1 & keys[40] == 0) //IF UP IS PRESSED
              { playerShipY -= 3; }
              if (keys[40] == 1 & keys[38] == 0) //IF DOWN IS PRESSED
              { playerShipY += 6; }
              if (keys[37] == 1 & keys[39] == 0) //IF LEFT IS PRESSED
              { playerShipX -= 5; }
              if (keys[39] == 1 & keys[37] == 0) //IF RIGHT IS PRESSED
              { playerShipX += 5; }
              starFieldY = starFieldY + starFieldSpeed;
              if (starFieldY == 0)
                   starFieldY = -600;
                   System.out.println("dadssa");
         public int getRandom(int from, int to)
              if (from > to)
                   int randTemp;
                   randTemp = from;
                   from = to;
                   to = randTemp;
              return random.nextInt(to-from+1)+from;
         public void generateStarfield()
              starFieldObj.setColor(Color.black);
              starFieldObj.fillRect (0, 0, 800, 1200);
              for (int td=0; td < 900 ; td++) //draw 900x2 dots on 800x1200 image
                        starFieldObj.setColor(Color.white);
                        starFieldObj.fillRect (getRandom(1,800), getRandom(1,600), 1, 1);
                        starFieldObj.fillRect (getRandom(1,800) + 800, getRandom(1,600) + 800, 1, 1);
         public void update(Graphics g)
              if (ready)
                   gfx.setColor(Color.black);
                   //gfx.fillRect (0, 0, this.getSize().width, this.getSize().height);
                   gfx.drawImage(starField,starFieldX,starFieldY,null);
                   gfx.drawImage(playerShip,playerShipX,playerShipY,null);
                   //gfx.drawString(Integer.toString(showFps),5,5);
                   g.drawImage(buffer,0,0,null);
    }

  • Extend Graphics OBJECT

    Hi!
    I need to add functionality to existing Graphics objects, like in:
    interface ABC {
      public void drawString(String,int,int);
      public void m();
    class ABCGr extends Graphics implements ABC {
      public void m() {}
    class Sth extends JPanel {
      public void doSth(ABC d) {}
      public void paintComponent(Graphics g) {
        ABC d = (ABCGr)g;
        doSth(d);
    }(This does not run, of course.)
    The crucial point here is that doSth() is also called with something else than an extended Graphics object (i.e. another ABC).
    Is the only way to achieve this to write a wrapper that contains a reference to the Graphics object and wraps all Graphics methods explicitely? This would be a bit clumsy!
    Any hint to a more elegant (and probably better performing) way would be greatly appreciated!
    Best regards,

    As much as I hate to say it, you really can't extend the graphics object.
    Here's why, basically the graphics object is supposed to be an interface to a canvas so it sit right on top of the thing that you are drawing to, be that the screen, an image in memory or the printer. SO you really can't extend it. You'd have to extend every seperate instance.
    What it sounds like you want to do is provide a bunch of utility functions to the Graphics object. This is probably better done with a class of static functions like this.
    class GraphicsUtil {
    static void doGraphicsFun( Graphics g) {//do stuff
    }I know that it's not the most elegant solution, but the graphics class is an abstract class and you can't really add functionality like that. Think about extending an interface, if you extend an interface, you can't make all the classes that implemented the old interface implment your new functions.
    I wouldn't write a wrapper, this will only slow your code down, static functions are the way to go.

  • Changing Graphics object

    Hoa can I change the color properties of the graphics object of one component in another component?

    The short answer is you can't. Graphics objects are not part of the state of a
    component -- they are created when rendering needs to be done and
    are disposed afterwards. Also, the same graphics object is shared: the same
    graphics objects is adjusted and used to repaint a frame and all its components,
    for example.
    Components do have some "graphical" state, however, like their foreground
    and background color and font. What is your goal?

  • Transparent Graphics Object

    Alright, I have one graphics object that draws all of the main elements of the screen, and I have a buffered image that is modified through a second graphics object. I want to know how to make the background for the second object transparent, so that if I drew something onto it, then drew the buffered image into the main graphics object, I'd be able to see all the drawing done in the original graphics object behind the uncovered areas, sort of like an overlay. Code examples are highly appreciated. Thanks in advance for any replies.
    (PS: Right now when I draw the image, it covers up the entire screen with the color grey, making it impossible to see the objects behind it.)

    I wrote example for AWT because in SWING it can be done very easy. Run this code, it runs fine. Use only your image files.
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.image.BufferedImage;
    import java.awt.*;
    import java.awt.event.*;
    public class ImageTest extends Canvas implements WindowListener {
    public static void main(String[] args) {
    Frame frame = new Frame("Image testing");
    ImageTest instance = new ImageTest();
    frame.add(instance);
    frame.addWindowListener(instance);
    frame.pack();
    frame.setVisible(true);
    public Dimension getPreferredSize() {
    return new Dimension(256, 256);
    BufferedImage backgroundImage;
    BufferedImage alphaImage;
    void initImage() {
    Image img = getToolkit().createImage("D:\\temp\\JavaTests\\viewcode.jpg");
    Image bkImage = getToolkit().createImage("D:\\temp\\JavaTests\\SolarEclipse.jpg");
    MediaTracker Mt = new MediaTracker(this);
    Mt.addImage(img, 0);
    Mt.addImage(bkImage, 1);
    try{
    Mt.waitForAll();
    }catch(Exception e){};
    BufferedImage bi = new BufferedImage(img.getWidth(this), img.getHeight(this), BufferedImage.TYPE_4BYTE_ABGR);
    alphaImage = new BufferedImage(bkImage.getWidth(this), bkImage.getHeight(this), BufferedImage.TYPE_4BYTE_ABGR);
    Graphics gr = bi.getGraphics();
    gr.drawImage(img, 0, 0, this);
    backgroundImage = (BufferedImage)bi;
    gr = alphaImage.getGraphics();
    gr.drawImage(bkImage, 0, 0, bkImage.getWidth(this)/2, bkImage.getHeight(this)/2, bkImage.getWidth(this)/2, bkImage.getHeight(this)/2, bkImage.getWidth(this), bkImage.getHeight(this), this);
    Color bl = new Color(0, 0, 0);
    for (int x=0; x<bkImage.getWidth(this); x++)
    for (int y=0; y<alphaImage.getHeight(this); y++) {
    Color c = new Color(alphaImage.getRGB(x,y));
    int r = c.getRed();//x*4;
    int g = c.getGreen();//y*4;
    int b = c.getBlue();//255 - (x+y)*2;//Math.abs(y*8-255);
    // Make transparent colors, which look like black
    int a = (r == b && g == b && r < 100 && g < 100 && b < 100)?0:255;
    int vv = (a<<24) | (r<<16) | (g<<8) | b;
    alphaImage.setRGB(x, y, vv);
    public void paint(Graphics gfx) {
    if (backgroundImage == null)
    initImage();
    gfx.drawImage(backgroundImage, 0, 0, this);
    int i = 0;
    int delta = 100;
    gfx.drawImage(alphaImage, i, i, this);
    gfx.drawImage(alphaImage, i + delta, i + delta, this);
    gfx.drawImage(alphaImage, i + delta*2, i + delta*2, this);
    gfx.drawImage(alphaImage, i + delta*3, i + delta*3, this);
    gfx.drawImage(alphaImage, i + delta*4, i + delta*4, this);
    gfx.drawImage(alphaImage, i + delta*5, i + delta*5, this);
    void exitForm(java.awt.event.WindowEvent evt) {
    System.exit(0);
    public void windowActivated(java.awt.event.WindowEvent windowEvent) {
    public void windowClosed(java.awt.event.WindowEvent windowEvent) {
    public void windowClosing(java.awt.event.WindowEvent windowEvent) {
    System.exit(0);
    public void windowDeactivated(java.awt.event.WindowEvent windowEvent) {
    public void windowDeiconified(java.awt.event.WindowEvent windowEvent) {
    public void windowIconified(java.awt.event.WindowEvent windowEvent) {
    public void windowOpened(java.awt.event.WindowEvent windowEvent) {

  • Null Graphics objects

    Hello, I am attempting to write a java program that places a graph within a panel that the user can interact with. I have chosen Canvas() as the method to acieve this, but am running into problems with the instantiation of the graphics object- it keeps returning null, and I haven't the faitest idea why. Here is my code in question:
    Canvas canvas = new Canvas();
    Graphics g = canvas.getGraphics();
    'g' is null- when I try to call g.drawLine(), it gives me a nullPointerException. Any help or information about why this is occuring would be greatly appreciated.

    Well, I figured out that I needed to add the canvas to the contentPane before it had a Graphics object associated with it. But now, where the canvas is, there is a just a gray box. SetColor doesn't work, drawLine doesn't work, nothing. Here is the code:
    Canvas canvas = new Canvas();
    contentPane.add(canvas, BorderLayout.WEST);
    show();
    Graphics g = canvas.getGraphics();
    Color white = new Color (255,255,255);
    g.setColor(white);
    setSize(300,200);
    //Sets up the graph lines and tic marks
    int size = 100;
    g.drawLine(0, 0, size, 0);
    g.drawLine(0, 0, 0, size);
    //Horizontal tics
    g.drawLine((size/4), 0, (size/4), (size/10));
    g.drawLine((size/2), 0, (size/2), (size/10));
    g.drawLine(((3*size)/4), 0, ((3*size)/4), (size/10));
    g.drawLine(size, 0, size, (size/10));
    //Vertical tics
    g.drawLine(0, (size/4), (size/10), (size/4));
    g.drawLine(0, (size/2), (size/10), (size/2));
    g.drawLine(0, ((3*size)/4), (size/10), ((3*size)/4));
    g.drawLine(0, size, (size/10), size);
    show();
    As I said, it compiles and runs fine, but there are no lines set up. I even added a bunch of show() statements as a desperate effort to get something to show up. Can anyone help? Thanks
    I hate programming.

Maybe you are looking for

  • Activate Scenarios with Solution Builder CRM Best Practices V1.2007

    Hi, I finished all steps in Quickguide for CRM Best Practices V1.2007 until the end. All worked fine without any problem. Now I want to activate a scenario. 1. In the field Workbench I get a list of 15 Request/Task, I`m only able to select one. 2. In

  • Missing the iOS7 "Instant" Photo Filter in iOS 8! Alternatives?

    Hi, unfortunately Apple removed in iOS 8 the very loved "Instant" Photo Filter in the Apple Camera App. a) Does somebody know a way to get it back? HELLO APPLE CAN YOU PLEASE CHANGE THAT AGAIN!!?? b) I'm not sure, in the iOS 7 Days, a had a third Par

  • Scanner calibration for colour-managed workflow

    I would like to do a decent calibration of my Epson V750 Pro scanner to achieve a colour-managed workflow. I have the latest version X-Rite i1 Photo Pro 2 calibration kit, and although this enables me to calibrate my monitor and printer, it does not

  • Oracle Licensing for a server with Quad Core Processor

    I know Oracle Standard Edition ONE is only licensed to install on a server with a max of 2 processors. 1) Now when it comes to the type of processor does it matter what type of processors they are ? 2) Can we have 2 Quad Core Processors on the server

  • Problem while uploading the data in IBPI Transaction

    Hi All, Here i am processing the (data for IW22)session from sm35, here i am getting error Mallfunction End(Time). Anybody can help me in this. It is very urgent. Thanks & Regards, Venkat N