Painting components to buffers

Hi,
My class, GamePanel, is extending JPanel and implementing Runnable, therefore all my painting is done in run(). I am using a buffer to draw images on, I would also like to draw Component�s on it as well. Here is the code I�m using to draw the Component�s:
From gameRender()
// Get all the components
Component[] comms=this.getComponents();
// Go round all
for (int i=0;i<comms.length;i++)
System.out.println("Swing component name: "+comms.getName());
     // Paint it on here
     comms[i].paint(g);
Where g is the BufferedImage.getGraphics().
Then in another method also call from run(), the buffer is drawn on it the panel.
From paintScreen()
// Get the graphics from the panel
Graphics g=super.getGraphics();
// If the graphic and the buffer are not null
if (g!=null&&buffer!=null)
     // Draw the buffer
g.drawImage(buffer,0,0,null);
// Sync the display
Toolkit.getDefaultToolkit().sync();
// Dispose of the graphics
g.dispose();However, no components are painted.
Is there any way this can be done?
Thanks
Luke

I�ve managed to do something that seems to work now:
protected void paintScreen()
     try
          // Get the graphics from the panel
          Graphics g=super.getGraphics();
          // If the graphic and the buffer are not null
          if (g!=null&&buffer!=null)
               // Draw the buffer
               //g.drawImage(buffer,0,0,null);
               paintComponent(g);
          // Sync the display
          Toolkit.getDefaultToolkit().sync();
          // Dispose of the graphics
          g.dispose();
     } catch (Exception ex) {}
protected void paintComponent(Graphics g)
     if (buffer!=null)
          // Get the buffer graphics
          Graphics bufG=buffer.getGraphics();
          // Paint the border to the buffer
          super.paintBorder(bufG);
          // Paint the children to the buffer
          super.paintChildren(bufG);
          // Draw the buffer
          g.drawImage(buffer,0,0,null);
}I should properly dispose of bufG in panitComponent(), and I�m not sure how proper it is as the tutorials did advise against invoking the paintBorder() and paintChildren().
The other thing I need to do I the class is tiling of the image, I thought I mencion that here instead of starting a new thread.
I have a class, Backdrop, that draws an image using a start Point object, each time a call to moveXxx() is made, the start point is translated, - or + depeding on the direction.
At the moment, the image is drawn onto the background colour, but I would like to tile that image over the screen to fill in the gaps, if you see what I mean.
One idea I did have is , each time draw() is called, to move the start point, in intervals of image width and height, until both the x and y or less then or equal to 0, this would put the image into the top left hand corner, perhaps further depending on where the point started out. Once the image is in the corner, some kind of loop can be used to draw it up and down the owner panel.
What do you think? I just came up with that while writing.

Similar Messages

  • Trying to do something very strange with layouts and painting components

    I'm trying to do something very strange with changing the layout of a container, then painting it to a bufferedImage and changing it back again so nothing has changed. However, I am unable to get the image i want of this container in a new layout. Consider it a preview function of the different layouts. Anyway. I've tried everything i know about swing and have come up empty. There is probably a better way to do what i am trying to do, i just don't know how.
    If someone could have a look perhaps and help me out i would be much appreciative.
    Here is a self contained small demo of my conundrum.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import javax.swing.BoxLayout;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.border.LineBorder;
    // what is should do is when you click on the button "click me" it should place a image on the panel of the buttons in a
    // horizontal fashion. Instead it shows the size that the image should be, but there is no image.
    public class ChangeLayoutAndPaint
         private static JPanel panel;
         private static JLabel label;
         public static void main(String[] args)
              // the panel spread out vertically
              panel = new JPanel();
              panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
              // the buttons in the panel
              JButton b1, b2, b3;
              panel.add(b1 = new JButton("One"));
              panel.add(b2 = new JButton("Two"));
              panel.add(b3 = new JButton("Three"));
              b1.setEnabled(false);
              b2.setEnabled(false);
              b3.setEnabled(false);
              // the label with a border around it to show size in a temp panel with flowlayout to not stuff around
              // with the actual size we want.
              JPanel thingy = new JPanel();
              label = new JLabel();
              label.setBorder(new LineBorder(Color.black));
              thingy.add(label);
              // the button to make things go
              JButton button = new JButton("click me");
              button.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e)
                        //change layout
                        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
                        panel.doLayout();
                        //get image
                        BufferedImage image = new BufferedImage(panel.getPreferredSize().width, panel.getPreferredSize().height, BufferedImage.TYPE_INT_ARGB);
                        Graphics2D g = image.createGraphics();
                        panel.paintComponents(g);
                        g.dispose();
                        //set icon of jlabel
                        label.setIcon(new ImageIcon(image));
                        //change back
                        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                        panel.doLayout();
              // the frame
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(400,200);
              frame.setLocation(100,100);
              frame.getContentPane().add(panel, BorderLayout.NORTH);
              frame.getContentPane().add(thingy, BorderLayout.CENTER);
              frame.getContentPane().add(button, BorderLayout.SOUTH);
              frame.setVisible(true);
    }

    Looks like you didn't read the API for Container#doLayout().
    Causes this container to lay out its components. Most programs should not call this method directly, but should invoke the validate method instead.
    There's also a concurrency issue here in that the panel's components may be painted to the image before revalidation completes. And your GUI, like any Swing GUI, should be constructed and shown on the EDT.
    Try this for size -- it could be better, but I've made the minimum possible changes in your code:import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import javax.swing.BoxLayout;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import javax.swing.border.LineBorder;
    public class ChangeLayoutAndPaint {
      private static JPanel panel;
      private static JLabel label;
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            // the panel spread out vertically
            panel = new JPanel();
            panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
            // the buttons in the panel
            JButton b1, b2, b3;
            panel.add(b1 = new JButton("One"));
            panel.add(b2 = new JButton("Two"));
            panel.add(b3 = new JButton("Three"));
            b1.setEnabled(false);
            b2.setEnabled(false);
            b3.setEnabled(false);
            // the label with a border around it to show size in a temp panel with flowlayout to not stuff around
            // with the actual size we want.
            JPanel thingy = new JPanel();
            label = new JLabel();
            // label.setBorder(new LineBorder(Color.black));
            thingy.add(label);
            // the button to make things go
            JButton button = new JButton("click me");
            button.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                //change layout
                panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
                //panel.doLayout();
                panel.revalidate();
                SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                    //get image
                    BufferedImage image = new BufferedImage(panel.getPreferredSize().width,
                        panel.getPreferredSize().height, BufferedImage.TYPE_INT_ARGB);
                    Graphics2D g = image.createGraphics();
                    panel.paintComponents(g);
                    g.dispose();
                    //set icon of jlabel
                    label.setIcon(new ImageIcon(image));
                    //change back
                    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                    //panel.doLayout();
                    panel.revalidate();
            // the frame
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(400, 200);
            frame.setLocation(100, 100);
            frame.getContentPane().add(panel, BorderLayout.NORTH);
            frame.getContentPane().add(thingy, BorderLayout.CENTER);
            frame.getContentPane().add(button, BorderLayout.SOUTH);
            frame.setVisible(true);
    }db
    edit I prefer this:import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    public class LayoutAndPaint {
      JPanel panel;
      JLabel label;
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            new LayoutAndPaint().makeUI();
      public void makeUI() {
        JButton one = new JButton("One");
        JButton two = new JButton("Two");
        JButton three = new JButton("Three");
        one.setEnabled(false);
        two.setEnabled(false);
        three.setEnabled(false);
        panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.add(one);
        panel.add(two);
        panel.add(three);
        label = new JLabel();
        JButton button = new JButton("Click");
        button.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            layoutAndPaint();
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 400);
        frame.add(panel, BorderLayout.NORTH);
        frame.add(label, BorderLayout.CENTER);
        frame.add(button, BorderLayout.SOUTH);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      private void layoutAndPaint() {
        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
        panel.revalidate();
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            BufferedImage image = new BufferedImage(panel.getPreferredSize().width,
                panel.getPreferredSize().height, BufferedImage.TYPE_INT_ARGB);
            Graphics g = image.createGraphics();
            panel.paintComponents(g);
            g.dispose();
            label.setIcon(new ImageIcon(image));
            panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
            panel.revalidate();
    }db
    Edited by: DarrylBurke

  • What's the chain of methods called for painting components?

    Hi, I'm trying to find out at what point components are painted within a container, as in what methods are being called for that component to be rendered to the graphics context.
    I've tried watching for calls going to paint, paintAll and paintComponents, but if a component has been added to a container it seems that even if I override all of those methods of the container the components that have been added still get displayed.
    So I suppose I have two questions:
    * - What is the chain of methods called when a container is told to paint/repaint itself?
    * - What are the purpose of paintAll & paintComponents, I can't find anything that actually uses these calls.
    Thanks in advance,
    L

    Well it seems that the paint method of the component is being called from sun.awt.RepaintArea.paint(...) which itself is being kicked off from handling an event that's been thrown.
    That's clearer now....but has anyone seen when paintAll, paintComponents or the printXXX counterparts have actually been called by a part Sun's code? I can see how they (Sun) would advocate a practice lke this, but it would seem kinda lame for them to suggest it and then for them not to use it themselves.....that's why I think there's probably something in the JRE that does call these methods at sometime....can anyone cast some light on this?

  • How to resize painted components

    Hi All,
    I am working on a simple project called "WhiteBoard" which is veryu similar to MS-Paint. Could anyone please tell me how to resize the components which I have drawn on the panel. Thanks in advance.
    Regards,
    Shankar.

    Cast the Graphics instance passed to the paintComponent() method of your board to a Graphics2D.
    Then use the scale(double sx, double sy) method of the Graphics2D instance to zoom
    your board in or out.
    IMPORTANT NOTE: If you use a mouse listener on the board, you'll have to convert the mouse
    coordinates according to the zoom factor.

  • Painting components on Canvas

    I'm making a game that doesn't rely on layouts, containers, etc. Just a Canvas and a paint( Graphics ) override where the game is drawn. In the menu system for my game, I need a combo box. I don't want to implement one as it'd be kinda difficult, scrollbars on popup windows, etc. So, I would like to use the Swing version, JComboBox. Any suggestions on how?
    I've tried
    g.translate( tx, ty );
    mCmbTime.paint( g );
    g.translate( -tx, -ty );where mCmbTime is a JComboBox of course. Well, this displays a grey box to the Canvas. At least the box is visible, but the actual component does not seem to be drawn. BTW, before I do this i do:
    setBounds( 0, 0, 75, 25 );
    setVisible( true );Welp, any help would be appreciated.
    Thanks

    You post no code so we can't guess what you doing
    wrong (at least I can't). Theres no trick involved.
    You would simply do:It's more of a theoretical question than a "my program doesn't work" question. So it's hard to narrow it down to a segment of code.
    JComboBox comboBox = new JComboBox(....);
    comboBox.setBounds(....);
    panel.add( comboBox );I don't want to add it, just use it.
    Of course you have to make sure you don't paint over
    top of it in your game.Exactly the question, how do I paint it on top and use it's features, drop down list, etc.
    I'm not sure why you need to put the combobox in the
    same container as the game. Why not just create aIt's in the menu system before the game actually starts. I want to use it in a custom form where I already have created my own lightweight radio buttons and checkboxes. I just don't want to have to create my own combo box, and I think the Swing version will look just fine.
    panel with a border layout. Add the the combobox to
    the North and add your game JPanel to the center.It's not a regular application. The point is I'm painting EVERYTHING! And now I just want to put a combo box in a particular place on a JPanel and have it work like normal. Is this possible? I would think so considering Swing is a lightweight gui set anyway and it works like this by design. I would like a response from someone that has done this before.
    Thanks for the reply.

  • Paint components on a graphics

    Hi,
    I have made the following:
    public class Pmsg extends Panel{
    public Pmsg()
    super();
    public paint(g)
    g.drawString("http://www.java.sun.com",10,50);
    g.drawLine(10,50,120,50);
    My problem is that I want to make the link http://www.java.sun.com clickable. I tried to paint a component (label) to my graphics but I failed.
    Does anyone know how to do this?
    Have a nice Day,
    Pieter Pareit

    Hi,
    Create a panel exclusively for the hyperlink and add it to your main panel. And write a mouselistener to trap the mouseClicked event and on that event call AppletContext's showDocument() method , passing the url and the target.
    JP

  • How to use paint method to draw in many componets.

    Hi!
    I have code like this:
    public class MainPanel extends JPanel{
       JPanel p1;
       JPanel p2;
       public MainPanel(){
           super(new BorderLayout());
           p1 = new JPanel();
           p2 = new JPanel();
           add(p1 , BorderLayout.Center);
           add(p2 , BorderLayout. West);
           setVisible(true);
    @Override
        protected void paintComponent(Graphics g) {
           g.setColor(Color.red);
           g.fillrect(10,10,10,10);
    }This code is onle an example. Supose, this code will paint black rectangle on "main panel" to which p1 and p2 are added. What should i do to be able to paint this rectangle on p1 or p2 without creating separate classes in which i will override paintComponents() method for p1 and p2. I would like to avoid creating separete classes for each panels. Is there any way to do that using one paint Components method. Thanks in advance for all respone.

    (where's Darryl when you need him?)Erm, Pete, since when did I become an expert lol?
    Lost my hard disk, its been hiccuping for a couple of weeks now. I'm running on an old 20 GB PATA with a 5GB c drive. No IDE, no offline Javadoc. I'll get a HDD in the morning, but I hope I can spin up the old disk at least once and recover the last week's "work" ... just fun stuff actually.
    Why does this code draw rectangles just for split second?repaint() (and consequently paint(), paintComponent() and other painting methods) may be called by the system any time it is detected that the component needs to be repainted. Since you do not have a override for paintComponent, it will perform its default painting and paint the entire component, wiping out your rectangle.
    For persistent drawing on a JPanel or JComponent I know only one way: override paintComponent. If you need to avoid this, you could go with morgalr's suggestion to use JLabel.
    For this you would draw the triangle/rectangle/whatever to a BufferedImage, then call label.setIcon with a new ImageIcon constructed from the BufferedImage.
    Also, avoid obtaining a Graphics reference via getGraphics. During the lifetime of a visible component, various different Graphics references may be passed into the paintComponent method, so the reference you obtain may not be current. getGraphics can also return null.
    luck, db

  • Paint component inside JPanel

    Hi guys,
    I will start with the original problem and get to the only option that seems possible before hardcoding everything.
    I need to draw something like a binary tree. Jtree doesn't fall into binary because it does not have the root in the center. <1;2;6;8;9>, where 6 is the root, and 1,2 are its left child's children and 8,9 are right child's children. Since I couldn't find any possible solution of customizing JTree to draw it in binary format, I am left with the following option that is a step towards hardcoding.
    Create a subclass of JPanel and paint inside it. The full hardcode method would be to draw everything right here, ie the lines and the boxes.
    But since I need to listen to box selections using mouse, I was hoping to draw the boxes using JPanel/JLabel and override their paint() method.
    So is there a way to paint components(JLabel/JPanel and lines) into a painted component (JPanel)? Note, the container JPanel is not using any layout. everything is being drawn using paint method.

    You are probably going to want to create smaller objects that handle their own painting. For example... Create an extension of JComponent that handles painting a single node. Then create the JPanel to add those to. You can even go as far as writing your own LayoutManager to handle laying the Components out in your binary layout. This is really the most effective way to do it, especially if you want to be able to detect clicks and what not. You can just add MouseListener's to the individual components than.
    Hope this helps,
    Josh Castagno
    http://www.jdc-software.com

  • Saving Bufferedİmage as Gif [64x64]

    Hi to all I am designing an symbol drawer application that draws engineering symbols where they are complex symbols so that the drawing screen of my application panel is large to paint detailed. Well when user draws on the screen after every mouse relase action happened, the drawing in the screen is painted to a buffered image.
    My question is. there are saave and load buttons. When user clicks the save button I want user to enter the file name and i want to save the big buffered image to a gif file where the size is 64 X 64 which should be fixed so that it will be used in another application.
    I know i should use a gif encoder but i dont know how.
    Any suggestions and solutions are highly appriciated.
    Thanx
    metan v

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class SaveComponent extends JPanel implements ActionListener
        BufferedImage image;
        public void actionPerformed(ActionEvent e)
            BufferedImage scaled = scaleImage();
            try
                // use your gif encoder here...
                ImageIO.write(scaled, "png", new File("saveComponent.png"));
            catch(IOException ioe)
                System.err.println("write error: " + ioe.getMessage());
        private BufferedImage scaleImage()
            int W = 64;
            int H = 64;
            BufferedImage bi = new BufferedImage(W, W, image.getType());
            Graphics2D g2 = bi.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            g2.setPaint(UIManager.getColor("Panel.background"));
                        //Color.pink);
            g2.fillRect(0, 0, W, H);
            double scale = getScale(W, H);
            double x = (W - scale*image.getWidth())/2;
            double y = (H - scale*image.getHeight())/2;
            AffineTransform at = AffineTransform.getTranslateInstance(x, y);
            at.scale(scale, scale);
            g2.drawImage(image, at, this);
            g2.dispose();
            return bi;
        private double getScale(int w, int h)
            double xScale = w/(double)image.getWidth();
            double yScale = h/(double)image.getHeight();
            double scale = Math.min(xScale, yScale);     // scale to fit
            //double scale = Math.max(xScale, yScale);   // scale to fill
            return scale;
        protected void paintComponent(Graphics g)
            if(image == null)
                initImage();
            g.drawImage(image, 0, 0, this);
        private void initImage()
            int w = getWidth();
            int h = getHeight();
            int rad = Math.min(w, h)/4;
            GraphicsConfiguration gc = getGraphicsConfiguration();
            image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
                                                                //OPAQUE);
            Graphics2D g2 = image.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setBackground(UIManager.getColor("Panel.background"));
            g2.clearRect(0, 0, w, h);
            g2.setPaint(Color.blue);
            g2.draw(new Rectangle2D.Double(w/16, h/16, w*7/8, h*7/8));
            g2.setPaint(Color.red);
            g2.fill(new Ellipse2D.Double(w/2-rad, h/2-rad, 2*rad, 2*rad));
            g2.setPaint(Color.green.darker());
            g2.draw(new Arc2D.Double(w/8, h/4, w*3/4, h/3, -57.0, 294.0, Arc2D.OPEN));
            g2.setPaint(Color.pink);
            g2.draw(new Line2D.Double(w/4, h*3/4, w*3/4, h*3/4));
            g2.dispose();
        public static void main(String[] args)
            SaveComponent test = new SaveComponent();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(test);
            f.getContentPane().add(test.getSouthPanel(), "South");
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
        private JPanel getSouthPanel()
            JButton save = new JButton("save");
            save.setActionCommand("save");
            save.addActionListener(this);
            JPanel panel = new JPanel();
            panel.add(save);
            return panel;
    }

  • Why are backgrounds to created images black?

    Dear all,
    In creating a bufferred image (or a volatile image - perhaps this problem exists with all image classes), the background is completely black. Only the painted components (typically small coloured rectangles) appear as they should do, colour wise. I am creating the graphics using a Graphics2D object in the standard way. However, a call to
    g2.setBackground(Color.white) etc still results in a background color black, as does
    g2.setColor(Color.white), before the call that adds the rectangles
    So I thought, I'd first draa one huge white rectangle using something like
    g2.setColor(new Color(255,255,255)), then
    g2.fill3DRect(0,0,600,900,false) // whatever
    and then draw over the rectangles that I need to add. However the resultant background colour is gray rather than white. Whats going on?
    Any suggestions?
    Cheers
    Ben

    Here's a demo of using setColor.Works for me.
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class ImageBackground {
        public static void main(String[] args) {
            final int W = 200, H = 100;
            BufferedImage bi = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = bi.createGraphics();
            g.setColor(Color.WHITE); //!
            g.fillRect(0,0,W,H);    //!
            g.setColor(Color.BLUE);
            g.setFont(new Font("Lucida Bright", Font.PLAIN, 16));
            g.drawString("Hello, World!", 10, 50);
            g.dispose();
            JLabel label = new JLabel(new ImageIcon(bi));
            final JFrame f = new JFrame("ImageBackground");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(label);
            f.pack();
            SwingUtilities.invokeLater(new Runnable(){
                public void run() {
                    f.setLocationRelativeTo(null);
                    f.setVisible(true);
    }

  • Project for school - I encountered some problems

    School gave me and my team a assignment to make a simulation of a floor-robot called Robbie. You can see Robbie as a plotter it is a round robot with a pen that it can turn on or off. The simulation should be of a remote control which gives commands to a class called Robbie.
    http://yvo.net/forum/Version16.zip
    is what our group made so far.
    Our problems are:
    -> When Robbie moves, he shocks, I think this has something to do with the paint routines of the underlying Frame. (Frame has a container called World which has a lightweight component called Robbie). We used double buffering, it does not flicker, it shocks.
    -> Collision Detection, how should we do Collision Detection between a Wall and a Robbie (Wall can be turned 360 degrees, not just horizontal or vertical). The Robbie to Robbie collision detection works, but could be optimized a lot I think.
    -> It is too slow, are their ways to speed up the calculations/smarter repaint? (General Optimization, on school it should run pretty smoothly on a 486).
    All the information is in the zip-file and all the source-codes. I use JDK1.4 to compile/run. I noticed that JDK1.3 results in bad repainting. It's a package, the MAIN class is hvu.robbie.gui.MainFrame
    All suggestions are welcome, thank you,
    Yvo van Beek
    [email protected]

    Hi,
    The thread in RobbieControl should have a sleep
    period, instead of having it in the RobbieMove method.
    Right now its just calling the robbie-methods all the
    time. Actually I dont like that thread at all, think u
    should have a thread closer to the paintcalling
    methods instead, maybe in robbieMove or just in
    Robbie.The problem is, forward should be able to be called manually, like forward(100). Then Robbie should just move the 100 steps, but not too quick (that's why we implemented the pause). We implemented the Thread into the Remote Control, so that the user can keep the button pressed and Robbie will keep on moving AND because the method forward has to return the real number of steps it made, in order to do that (with 2 robbies) is to move the robbie trough the process of calling the method forward, then keep him busy with the moving process and then return. We first tried one Thread for the Remote and another one for moving Robbie. But that became complicated because the first Thread had to wait() in forward and awaken the move Thread, and after moving set the move thread to wait() en notify() the remote control Thread. But you can't force a wait() and notify() so that gave problems.
    >
    U should probably look at ur doublebuffering. Instead
    of doublebuffer the whole 'world' just buffer the
    components in it. That way u will avoid that
    components isnt fully painted when they move. If doing
    that, components-double buffering, u need to repaint
    the area where the component have moved from. And u
    will need to override some update(Graphics g) methods,
    in World and in robbie. They should just call paint.
    Ive tried it and the rotating looks much better,
    though the movement needs some improvement. I think u
    maybe need to override setLocation...Could you maybe give me a bit of code or explain it?
    I do not understand the process of container => container => component painting... My emailadress is [email protected] (there you can send source of post it here)
    >
    I think the collision-detection should be called in
    World.moveObject.We will change that, thank you :)
    >
    Hope theese comment isnt to vague. I will try find
    some old code of mine, and compare it with urs.
    Stig.Thank you for your help,
    Yvo van Beek

  • I really needed this one implementation of tree table on mvc

    hi there i'm burning my as* reading some tutorials about tree table and all i found was a complex codes
    i just wanna know if you know some codes of a simple tree table where in the content of a tree or table was hardcoded and there are no thingy effects such as sortes. coz i really wanted to implement this on mvc since we are using STable here's the sample code:
    View:
    package treeTable;
    import java.awt.*;
    //import java.awt.event.MouseEvent;
    //import java.util.EventObject;
    import javax.swing.*;
    //import javax.swing.table.TableCellEditor;
    //import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumnModel;
    //import javax.swing.tree.DefaultTreeCellRenderer;
    //import javax.swing.tree.DefaultTreeSelectionModel;
    //import javax.swing.tree.TreeCellRenderer;
    //import javax.swing.tree.TreeModel;
    //import javax.swing.tree.TreePath;
    import javax.swing.border.*;
    //import javax.swing.event.ListSelectionEvent;
    //import javax.swing.event.ListSelectionListener;
    import com.jgoodies.forms.layout.CellConstraints;
    import com.jgoodies.forms.layout.FormLayout;
    //import com.borland.jbcl.layout.*;
    import org.scopemvc.core.Control;
    import org.scopemvc.core.Selector;
    import org.scopemvc.view.swing.*;
    * View for PosCCYFX
    * @author Raymond Isip
    public class HistoricTotalPositionByCurrencyFXView extends SPanel implements HistoricTotalPositionByCurrencyFXConstants {
    // Instance variables for the selectors used by the JBuilder designer
    Selector cashStructTBLSelector = CASH_STRUCT_TBL_SELECTOR;
    Selector selectedCashStructTBLSelector = SELECTED_CASH_STRUCT_TBL_SELECTOR;
    Selector optionsTBLSelector = OPTIONS_TBL_SELECTOR;
    Selector selectedOptionsTBLSelector = SELECTED_OPTIONS_TBL_SELECTOR;
    Selector fxcashStructuredFwdLBLSelector = FXCASH_STRUCTURED_FWD_LBL_SELECTOR;
    Selector cashLBLSelector = CASH_LBL_SELECTOR;
    Selector structFwdsLBLSelector = STRUCT_FWDS_LBL_SELECTOR;
    Selector optionsLBLSelector = OPTIONS_LBL_SELECTOR;
         FormLayout MainFormLayout = new FormLayout ("12,p,12,p,12", "11,p,11");
         FormLayout LeftFormLayout = new FormLayout ("280,250,87", "p,p");
         FormLayout LeftTableFormLayout = new FormLayout ("p", "p,p");
         FormLayout RightTableFormLayout = new FormLayout ("300", "p,p");
         FormLayout LeftSubFormLayout = new FormLayout ("100,50,100", "p");
         CellConstraints cc = new CellConstraints();
    Border cashStructTBLBorder;
    STable cashStructTBLTable = new STable();
    JScrollPane cashStructTBLScrollPane = new JScrollPane(cashStructTBLTable);
    Border optionsTBLBorder;
    STable optionsTBLTable = new STable();
    JScrollPane optionsTBLScrollPane = new JScrollPane(optionsTBLTable);
    JLabel fxcashStructuredFwdLBLLabel = new JLabel();
    SLabel fxcashStructuredFwdLBLSLabel = new SLabel();
    JLabel cashLBLLabel = new JLabel();
    SLabel cashLBLSLabel = new SLabel();
    JLabel structFwdsLBLLabel = new JLabel();
    SLabel structFwdsLBLSLabel = new SLabel();
    JLabel optionsLBLLabel = new JLabel();
    SLabel optionsLBLSLabel = new SLabel();
    * Constructor for the PosCCYFXView object
    public HistoricTotalPositionByCurrencyFXView() {
    jbInit();
    * The main program for the PosCCYFXView class
    * @param args The command line arguments
    public static void main(String[] args) {
              HistoricTotalPositionByCurrencyFXView view = new HistoricTotalPositionByCurrencyFXView();
    JFrame frame = new JFrame();
    frame.setSize(800, 600);
    frame.getContentPane().add(view);
    frame.setVisible(true);
    * Used by Scope to set the window frame title.
    * @return The title value
    public String getTitle() {
    return "PosCCYFX";
    * Used by Scope to end the application when the window is closed.
    * @return The closeControl value
    public Control getCloseControl() {
    return new Control(HistoricTotalPositionByCurrencyFXController.EXIT_CONTROL_ID);
    * Description of the Method
    * @return Description of the Return Value
    public boolean validateForm() {
    return true;
    private void jbInit() {
    this.setLayout(MainFormLayout);
         JPanel LeftPanel = new JPanel();
         JPanel LeftSubPanel = new JPanel();
         JPanel LeftTablePanel = new JPanel();
              JPanel RightTablePanel = new JPanel();
         LeftPanel.setLayout(LeftFormLayout);
              LeftSubPanel.setLayout(LeftSubFormLayout);
              LeftTablePanel.setLayout(LeftTableFormLayout);
              RightTablePanel.setLayout(RightTableFormLayout);
              JScrollPane LeftScrollPane = new JScrollPane(LeftTablePanel);
              //LeftScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              LeftScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
              JScrollPane RightScrollPane = new JScrollPane(RightTablePanel);
              RightScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              RightScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
              LeftScrollPane.setPreferredSize(new Dimension(620,330));
              RightScrollPane.setPreferredSize(new Dimension(300,330));
    cashStructTBLTable.setSelector(cashStructTBLSelector);
    cashStructTBLTable.setSelectionSelector(selectedCashStructTBLSelector);
    String[] columnSelects = {"col1", "col2", "col3", "col4", "col5","col6", "col7", "col8", "col9", "col10"};
    String[] columnNames = {"USD", "Date","Product Type", "Details", "Buy", "Sell", "Sub Total", "Buy", "Sell", "Total"};
    int colWidths[] = {100,70,70,40,50,50,60,50,50,60};
    cashStructTBLTable.setColumnSelectors(columnSelects);
    cashStructTBLTable.setColumnNames(columnNames);
    cashStructTBLTable.setPreferredScrollableViewportSize(new Dimension(600,273));
    TableColumnModel cashStructTBLModel = cashStructTBLTable.getColumnModel();
    for (int x=0; x<colWidths.length; x++) {
    int width = colWidths[x];
    cashStructTBLModel.getColumn(x).setPreferredWidth(width);}
              cashStructTBLTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    cashStructTBLScrollPane.setBorder(cashStructTBLBorder);
    cashStructTBLScrollPane.getViewport().add(cashStructTBLTable, null);
    optionsTBLTable.setSelector(optionsTBLSelector);
    optionsTBLTable.setSelectionSelector(selectedOptionsTBLSelector);
    String[] columnSelects1 = {"col1", "col2", "col3"};
    String[] columnNames1 = {"Buy", "Sell", "Total"};
    int colWidths1[] = {90,90,100};
    optionsTBLTable.setColumnSelectors(columnSelects1);
    optionsTBLTable.setColumnNames(columnNames1);
    optionsTBLTable.setPreferredScrollableViewportSize(new Dimension(300,290));
    TableColumnModel optionsTBLModel = optionsTBLTable.getColumnModel();
    for (int x1=0; x1<colWidths1.length; x1++) {
    int width1 = colWidths1[x1];
    optionsTBLModel.getColumn(x1).setPreferredWidth(width1); }
              optionsTBLTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    optionsTBLScrollPane.setBorder(optionsTBLBorder);
    optionsTBLScrollPane.getViewport().add(optionsTBLTable, null);
              optionsTBLTable.setEnabled(false);
    fxcashStructuredFwdLBLLabel.setText(" FX Cash & Structured Forwards");
              fxcashStructuredFwdLBLLabel.setBorder(BorderFactory.createRaisedBevelBorder());
              cashLBLLabel.setText(" Cash");
              cashLBLLabel.setBorder(BorderFactory.createRaisedBevelBorder());
              structFwdsLBLLabel.setText(" Structured FWDs");
              structFwdsLBLLabel.setBorder(BorderFactory.createRaisedBevelBorder());
              optionsLBLLabel.setText(" Options");
              optionsLBLLabel.setBorder(BorderFactory.createRaisedBevelBorder());
              /******************************Fillers*************************************/
    JLabel sample = new JLabel(" ");
              JLabel sample1 = new JLabel(" ");
              JLabel sample2 = new JLabel(" ");
              JLabel sample3 = new JLabel(" ");
              JLabel sample4 = new JLabel(" ");
              sample.setBorder(BorderFactory.createRaisedBevelBorder());
              sample1.setBorder(BorderFactory.createRaisedBevelBorder());
              sample2.setBorder(BorderFactory.createRaisedBevelBorder());
              sample3.setBorder(BorderFactory.createRaisedBevelBorder());
              sample4.setBorder(BorderFactory.createRaisedBevelBorder());
              LeftSubPanel.add(sample, cc.xy(2,1));
              LeftPanel.add(sample1, cc.xy(1,1));
              LeftPanel.add(sample2, cc.xy(3,1));
              LeftPanel.add(sample3, cc.xy(1,2));
              LeftPanel.add(sample4, cc.xy(3,2));
              LeftSubPanel.add(cashLBLLabel, cc.xy(1,1));
              LeftSubPanel.add(structFwdsLBLLabel, cc.xy(3,1));
              LeftPanel.add(fxcashStructuredFwdLBLLabel, cc.xy(2,1));
              LeftPanel.add(LeftSubPanel, cc.xy(2,2));
              LeftTablePanel.add(LeftPanel, cc.xy(1,1));
              LeftTablePanel.add(cashStructTBLScrollPane, cc.xy(1,2));
              RightTablePanel.add(optionsLBLLabel, cc.xy(1,1));
              RightTablePanel.add(optionsTBLScrollPane, cc.xy(1,2));
              this.add(LeftScrollPane, cc.xy(2,2));
              this.add(RightScrollPane, cc.xy(4,2));
    Model:
    package treeTable;
    import java.util.ArrayList;
    import java.util.List;
    import org.scopemvc.core.ModelChangeEvent;
    import org.scopemvc.core.Selector;
    import org.scopemvc.model.basic.*;
    import org.scopemvc.model.collection.ListModel;
    * Model for for PosCCYFX
    * @author Raymond Isip
    public class HistoricTotalPositionByCurrencyFXModel extends BasicModel implements HistoricTotalPositionByCurrencyFXConstants {
    private ListModel cashStructTBLList = new ListModel();
    private CashStructTBLItem selectedCashStructTBL = null;
    private ListModel optionsTBLList = new ListModel();
    private OptionsTBLItem selectedOptionsTBL = null;
    private String fxcashStructuredFwdLBL;
    private String cashLBL;
    private String structFwdsLBL;
    private String optionsLBL;
    * Constructor for the PosCCYFXModel object
    public HistoricTotalPositionByCurrencyFXModel() {
              Object[] data1= new Object[]{"100","100","200"};
              Object[] data2= new Object[]{"","29.Apr.2004","Forward","SGD","200","100","300","250","150","400"};
              for(int x = 0; x<=25;x++){
                   selectedOptionsTBL = new OptionsTBLItem(data1);
                   optionsTBLList.add(selectedOptionsTBL);
                   selectedCashStructTBL = new CashStructTBLItem(data2);
                   cashStructTBLList.add(selectedCashStructTBL);
    * Gets the cashStructTBL list
    * @return The cashStructTBL list
    public List getCashStructTBLList() {
    return cashStructTBLList;
    * Sets the cashStructTBL list
    * @param newCashStructTBLList The new cashStructTBL list
    public void setCashStructTBLList(List newCashStructTBLList) {
    cashStructTBLList.setList(newCashStructTBLList);
    this.fireModelChange(ModelChangeEvent.VALUE_CHANGED, CASH_STRUCT_TBL_SELECTOR);
    * Gets the selected cashStructTBL item
    * @return A cashStructTBL item
    public CashStructTBLItem getSelectedCashStructTBL() {
    return selectedCashStructTBL;
    * Sets the selected cashStructTBL item
    * @param newCashStructTBL The new cashStructTBL item
    public void setSelectedCashStructTBL(CashStructTBLItem newCashStructTBL) {
    selectedCashStructTBL = newCashStructTBL;
    this.fireModelChange(ModelChangeEvent.VALUE_CHANGED, SELECTED_CASH_STRUCT_TBL_SELECTOR) ;
    * Gets the optionsTBL list
    * @return The optionsTBL list
    public List getOptionsTBLList() {
    return optionsTBLList;
    * Sets the optionsTBL list
    * @param newOptionsTBLList The new optionsTBL list
    public void setOptionsTBLList(List newOptionsTBLList) {
    optionsTBLList.setList(newOptionsTBLList);
    this.fireModelChange(ModelChangeEvent.VALUE_CHANGED, OPTIONS_TBL_SELECTOR);
    * Gets the selected optionsTBL item
    * @return A optionsTBL item
    public OptionsTBLItem getSelectedOptionsTBL() {
    return selectedOptionsTBL;
    * Sets the selected optionsTBL item
    * @param newOptionsTBL The new optionsTBL item
    public void setSelectedOptionsTBL(OptionsTBLItem newOptionsTBL) {
    selectedOptionsTBL = newOptionsTBL;
    this.fireModelChange(ModelChangeEvent.VALUE_CHANGED, SELECTED_OPTIONS_TBL_SELECTOR) ;
    * Gets the fxcashStructuredFwdLBL attribute
    * @return The fxcashStructuredFwdLBL value
    public String getFxcashStructuredFwdLBL() {
    return fxcashStructuredFwdLBL;
    * Sets the fxcashStructuredFwdLBL attribute
    * @param newFxcashStructuredFwdLBL The new fxcashStructuredFwdLBL value
    public void setFxcashStructuredFwdLBL(String newFxcashStructuredFwdLBL) {
    fxcashStructuredFwdLBL = newFxcashStructuredFwdLBL;
    this.fireModelChange(ModelChangeEvent.VALUE_CHANGED, FXCASH_STRUCTURED_FWD_LBL_SELECTOR);
    * Gets the cashLBL attribute
    * @return The cashLBL value
    public String getCashLBL() {
    return cashLBL;
    * Sets the cashLBL attribute
    * @param newCashLBL The new cashLBL value
    public void setCashLBL(String newCashLBL) {
    cashLBL = newCashLBL;
    this.fireModelChange(ModelChangeEvent.VALUE_CHANGED, CASH_LBL_SELECTOR);
    * Gets the structFwdsLBL attribute
    * @return The structFwdsLBL value
    public String getStructFwdsLBL() {
    return structFwdsLBL;
    * Sets the structFwdsLBL attribute
    * @param newStructFwdsLBL The new structFwdsLBL value
    public void setStructFwdsLBL(String newStructFwdsLBL) {
    structFwdsLBL = newStructFwdsLBL;
    this.fireModelChange(ModelChangeEvent.VALUE_CHANGED, STRUCT_FWDS_LBL_SELECTOR);
    * Gets the optionsLBL attribute
    * @return The optionsLBL value
    public String getOptionsLBL() {
    return optionsLBL;
    * Sets the optionsLBL attribute
    * @param newOptionsLBL The new optionsLBL value
    public void setOptionsLBL(String newOptionsLBL) {
    optionsLBL = newOptionsLBL;
    this.fireModelChange(ModelChangeEvent.VALUE_CHANGED, OPTIONS_LBL_SELECTOR);
    Controller:
    package treeTable;
    import java.awt.Dimension;
    import org.scopemvc.controller.basic.BasicController;
    import org.scopemvc.core.Control;
    import org.scopemvc.core.ControlException;
    * Controller for PosCCYFX
    * @author Raymond Isip
    public class HistoricTotalPositionByCurrencyFXController extends BasicController implements HistoricTotalPositionByCurrencyFXConstants {
    * Constructor for the PosCCYFXController object
    public HistoricTotalPositionByCurrencyFXController() {
    setModel(new HistoricTotalPositionByCurrencyFXModel());
    setView(new HistoricTotalPositionByCurrencyFXView());
         public HistoricTotalPositionByCurrencyFXController(HistoricTotalPositionByCurrencyFXView view) {
              setModel(new HistoricTotalPositionByCurrencyFXModel());
              setView(view);
    * Call this after creating the Controller to make it perform
    * its initial action. Default impl opens the view in a new frame.
    public void startup() {
              HistoricTotalPositionByCurrencyFXView myView = (HistoricTotalPositionByCurrencyFXView) getView();
    // This is the code that centers the view
    myView.setViewBounds(myView.CENTRED);
    myView.setPreferredSize(new Dimension(1000, 600));
    showView(myView);
    * Can be called by a parent to shutdown and remove this from
    * the chain of responsibility. Default impl does this:
    * <ul>
    * <li>call shutdown() on every child controller</li>
    * <li>call hideView()</li>
    * <li>setParent(null)</li>
    * </ul>
    public void shutdown() {
    super.shutdown();
    * Handles all controls
    * @param inControl The control token invoking the presentation logic
    * @throws ControlException when an error occured while handling the control
    protected void doHandleControl(Control inControl) throws ControlException {
    try {
    if (inControl.matchesID(SAVE)) {
    inControl.markMatched();
    doSave();
    } else if (inControl.matchesID(RESET)) {
    inControl.markMatched();
    doReset();
    } else if (inControl.matchesID(GOT_OPTIONS_TBL)) {
    inControl.markMatched();
    doGotOptionsTbl();
    } catch (ControlException ce) {
    throw ce;
    } catch (RuntimeException re) {
    re.printStackTrace();
    throw re;     
    } finally {
    // do cleanup
    * Handles the SAVE control
    * @todo Implement doSave
    protected void doSave() throws ControlException {
    // to implement
    * Handles the RESET control
    * @todo Implement doReset
    protected void doReset() throws ControlException {
    // to implement
    * Handles the GOT_OPTIONS_TBL control
    * @todo Implement doGotOptionsTbl
    protected void doGotOptionsTbl() throws ControlException {
    // to implement
    Launcher:
    package treeTable;
    import org.scopemvc.util.ResourceLoader;
    import org.scopemvc.util.UIStrings;
    * Launcher for PosCCYFX
    * @author Raymond Isip
    public class HistoricTotalPositionByCurrencyFXLauncher {
    * Constructor for the PosCCYFXLauncher object
    public HistoricTotalPositionByCurrencyFXLauncher() {
    * Start the PosCCYFX application
    * @param args The command line arguments
    public static void main(String[] args) {
    // TODO: change 'resources' by the name of your properties file
    UIStrings.setPropertiesName("resources");
    ResourceLoader.setClientClassLoader(HistoricTotalPositionByCurrencyFXLauncher.class.getClassLoader());
              HistoricTotalPositionByCurrencyFXController mainController = new HistoricTotalPositionByCurrencyFXController();
    mainController.startup();
    Constant:
    package treeTable;
    import org.scopemvc.core.Selector;
    * Constants for the selectors and the control ids defined in PosCCYFX
    * @author Raymond Isip
    public interface HistoricTotalPositionByCurrencyFXConstants {
    // Selectors
    Selector CASH_STRUCT_TBL_SELECTOR = Selector.fromString("cashStructTBLList");
    Selector SELECTED_CASH_STRUCT_TBL_SELECTOR = Selector.fromString("selectedCashStructTBL");
    Selector OPTIONS_TBL_SELECTOR = Selector.fromString("optionsTBLList");
    Selector SELECTED_OPTIONS_TBL_SELECTOR = Selector.fromString("selectedOptionsTBL");
    Selector FXCASH_STRUCTURED_FWD_LBL_SELECTOR = Selector.fromString("fxcashStructuredFwdLBL");
    Selector CASH_LBL_SELECTOR = Selector.fromString("cashLBL");
    Selector STRUCT_FWDS_LBL_SELECTOR = Selector.fromString("structFwdsLBL");
    Selector OPTIONS_LBL_SELECTOR = Selector.fromString("optionsLBL");
    // Control IDs
    * The SAVE control ID for the save button
    String SAVE = "SAVE";
    * The RESET control ID for the reset button
    String RESET = "RESET";
    * The GOT_OPTIONS_TBL control ID for the optionsTBL field
    String GOT_OPTIONS_TBL = "GOT_OPTIONS_TBL";
    CashStructTBLItem:
    package treeTable;
    * Item for CashStructTBL
    * @author Raymond Isip
    public class CashStructTBLItem {
         String col1= new String();
         String col2= new String();
         String col3= new String();
         String col4= new String();
         String col5= new String();
         String col6= new String();
         String col7= new String();
         String col8= new String();
         String col9= new String();
         String col10= new String();
    * Constructor for the CashStructTBLItem object
         public CashStructTBLItem(Object[] data1) {
              setCol1((String)data1[0]);
              setCol2((String)data1[1]);
              setCol3((String)data1[2]);
              setCol4((String)data1[3]);
              setCol5((String)data1[4]);
              setCol6((String)data1[5]);     
              setCol7((String)data1[6]);
              setCol8((String)data1[7]);
              setCol9((String)data1[8]);     
              setCol10((String)data1[9]);
         * @return
         public String getCol1() {
              return col1;
         * @return
         public String getCol10() {
              return col10;
         * @return
         public String getCol2() {
              return col2;
         * @return
         public String getCol3() {
              return col3;
         * @return
         public String getCol4() {
              return col4;
         * @return
         public String getCol5() {
              return col5;
         * @return
         public String getCol6() {
              return col6;
         * @return
         public String getCol7() {
              return col7;
         * @return
         public String getCol8() {
              return col8;
         * @return
         public String getCol9() {
              return col9;
         * @param string
         public void setCol1(String string) {
              col1 = string;
         * @param string
         public void setCol10(String string) {
              col10 = string;
         * @param string
         public void setCol2(String string) {
              col2 = string;
         * @param string
         public void setCol3(String string) {
              col3 = string;
         * @param string
         public void setCol4(String string) {
              col4 = string;
         * @param string
         public void setCol5(String string) {
              col5 = string;
         * @param string
         public void setCol6(String string) {
              col6 = string;
         * @param string
         public void setCol7(String string) {
              col7 = string;
         * @param string
         public void setCol8(String string) {
              col8 = string;
         * @param string
         public void setCol9(String string) {
              col9 = string;
    OptionsTBLItem:
    package treeTable;
    * Item for OptionsTBL
    * @author Raymond Isip
    public class OptionsTBLItem {
         String col1= new String();
         String col2= new String();
         String col3= new String();
    * Constructor for the OptionsTBLItem object
         public OptionsTBLItem(Object[] data1) {
              setCol1((String)data1[0]);
              setCol2((String)data1[1]);
              setCol3((String)data1[2]);
         * @return
         public String getCol1() {
              return col1;
         * @return
         public String getCol2() {
              return col2;
         * @return
         public String getCol3() {
              return col3;
         * @param string
         public void setCol1(String string) {
              col1 = string;
         * @param string
         public void setCol2(String string) {
              col2 = string;
         * @param string
         public void setCol3(String string) {
              col3 = string;
    All I want is for the tree table renderers or editors to use the table created on the vieew part of this mvc
    i will greatly appreciates your help

    As a start point take sources of JTable (the component and datamodel) and rebuild them. I have made such component for my company product. To write it I spend 5 days and about two weeks for debugging. This code cannot be very simple. As it should be fully mutable. For example, each line should have bkcolor, fgcolor, font, etc. Each sell has bkcolor, fgcolor, font, insets, border, alighnment, visibility, etc. Each node has its cell, indent and array of data cells. To support fast scrolling the painting should be buffered. My components also supports text line wrapping. The tree component consists of three parts: the header, the left part and the matrix of data. This component can be printed (this is a secial code for paging and scaling).

  • CreateImage(int, int) problem -- or..?

    I'm trying to get a program double buffered, and have followed the structure for doing so provided by Sun. However, the program does not work correctly.
    Problem #1: I have to "manually" refresh the JFrame (put it behind a window, then bring it back to the foreground), and everything seems to work correctly.
    Problem #2: When the program first starts, I get 2 NPE's.
    Note: Both of these problems usually occur. Rarely, the entire thing runs perfectly with no problems at all.
    Here is how the code is structured:
    Graphics offScreen;
    Image offScreenImage;
    public void paint(Graphics screen)
    update(screen);
    public void update(Graphics toPaint)
    if( offScreenImage == null )
    offScreenImage = createImage(640, 480);     
    offScreen = offScreenImage.getGraphics();
    setBackground(Color.gray);          
    board.draw(offScreen);
    toPaint.drawImage(offScreenImage, 0, 0, null);     
    } //end draw()
    Also, the draw(Graphics) method from the board instance is:
    public void draw(Graphics offScreen)
    offScreen.drawImage(testImage, 25, 25, null);
    What could be causing these problems? Is there anything special that needs to be done if I'm using separate object files to draw? The NPE's are always flagged at this line:
         board.draw(offScreen);
    Any suggestions would be GREATLY appreciated.

    problem #1: Try moving the initializing code from update to paint or make paint to call update. Paint is the method that is called first to paint the component, update is called to repaint it.
    problem #2: "board.draw(offScreen);" can cause a NPE if a) board is null or b) offScreen is null. Which one is it?
    Also, in swing you should override the paintComponent-method instead of paint. (And aren't swing components double buffered by default? I'm not sure about that...)

  • Can not draw a solid line after drawing a dashed line

    I have been using a Graphics2D object in order to paint onto a buffered image and then transition that to a panel for viewing. The way the program works requires me to create the dashed line first through BasicStroke. After doing this I have tried to reset the setStroke with multiple new pens including BasicStroke(), BasicStroke(1.0f), and BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] {1,0}, 0.0f).
    Any ideas as to why I am still incapiable of drawing a solid line?

    Any ideas as to why I am still incapiable of drawing
    a solid line?Without seeing any code, I could guess, but my guess and a quarter won�t even buy you a newspaper around here now a days.
    Seriously though, you need to create a short, self contained, compilable example. Look here for an explanation on how to create this:
    http://www.physci.org/codes/sscce/

  • Netbeans wont allow JFrame resize

    Hi Guys,
    I have just started using Netbeans 6.1 and am new to the netbeans environment for Java. I have been writing a simple GUI and it has been working fine until now. The GUI displays a JFrame which consists of a few panels, etc and some painted components. All was fine until today when I modified one of the panels indivigually when I went back to the main JFrame it had been reduced to a really small size as in a size of 0. Any attempts to rezise the JFrame or run the program results in the Netbeans error:
    java.lang.IllegalArgumentException: Invalid size
         at org.jdesktop.layout.GroupLayout.checkResizeType(GroupLayout.java:223)
         at org.jdesktop.layout.GroupLayout.checkSize(GroupLayout.java:208)
         at org.jdesktop.layout.GroupLayout.access$500(GroupLayout.java:85)
         at org.jdesktop.layout.GroupLayout$GapSpring.<init>(GroupLayout.java:2851)
         at org.jdesktop.layout.GroupLayout$SequentialGroup.add(GroupLayout.java:1588)
         at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.fillGroup(SwingLayoutBuilder.java:317)
         at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.composeGroup(SwingLayoutBuilder.java:232)
         at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.fillGroup(SwingLayoutBuilder.java:253)
         at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.composeGroup(SwingLayoutBuilder.java:232)
         at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.fillGroup(SwingLayoutBuilder.java:251)
         at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.composeGroup(SwingLayoutBuilder.java:232)
         at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.fillGroup(SwingLayoutBuilder.java:253)
         at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.composeGroup(SwingLayoutBuilder.java:232)
         at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.createLayout(SwingLayoutBuilder.java:174)
         at org.netbeans.modules.form.layoutdesign.support.SwingLayoutBuilder.setupContainerLayout(SwingLayoutBuilder.java:107)
         at org.netbeans.modules.form.VisualReplicator.setupContainerLayout(VisualReplicator.java:791)
         at org.netbeans.modules.form.VisualReplicator.updateContainerLayout(VisualReplicator.java:324)
         at org.netbeans.modules.form.FormDesigner$FormListener.run(FormDesigner.java:2241)
         at org.netbeans.modules.form.FormDesigner$FormListener.processEvents(FormDesigner.java:2186)
         at org.netbeans.modules.form.FormDesigner$FormListener.formChanged(FormDesigner.java:2145)
         at org.netbeans.modules.form.FormModel.fireEvents(FormModel.java:1268)
         at org.netbeans.modules.form.FormModel.fireEventBatch(FormModel.java:1241)
         at org.netbeans.modules.form.FormModel.firePendingEvents(FormModel.java:1204)
         at org.netbeans.modules.form.FormModel.access$000(FormModel.java:62)
    [catch] at org.netbeans.modules.form.FormModel$2.run(FormModel.java:1184)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
         at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
         at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    This is probably a simple thing I have done wrong here but none of the properties seem to allow me to resize?
    any assistance would be much appreciated.
    cheers
    Tony

    Thanks mate, I reverterd to an older history when it was working and did the clean build seemed to fix the issue.
    Cheers

Maybe you are looking for

  • Can i merge two apple ids into one

    i have two apple IDs that i need to merge.  money is both accouts, paid apps on both accounts. What are my options? thanks

  • Mac Pro kernel panic, RAM does not seem to be problem

    My Mac Pro (late 2006) now has kernel panics at startup. Problem first happened while computer was in sleep mode, a second kernel panic happened about 10-15 minutes after reboot the first time. Now it happens at startup every time. Zapped PRAM multip

  • Error "system not configured as xmb" in transaction "sxmb_moni"

    Hi, when I send an IDoc from R3 to XI I get this error: system not configured as xmb" in transaction "sxmb_moni" also, in the adaptermonitor of the runtime workbench there is an error in the integration engine. "no rules for business-system are defin

  • Video App goes black

    Rented two movies last nite from Apple Store - the movies downloaded to 'Video' - tapped the movie I wanted to watch and the screen went not blank but black (like the iPAD was turned off but it wasn't!).  I gave up and went to bed. Tried it again thi

  • JavaServer Faces and Data Bases - Help me!

    I am beginning in JSF and I have that to create one aplication using JSF. somebody could indicate me a site or send for me code samples of JSF and data base, using insert, delete and update? since already I am thankful!