Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Oracle Georaster another commercial GIS softwares

473423Nov 26 2008 — edited Nov 26 2008
Hi,
I have a doubt about others commercial GIS softwares.
there is some GIS software which understand images stored in the Oracle Spatial Georaster? for example AutoCad Map, Geomedia, MapInfo, ArcGis.
I know that there is a pack in the Geomedia 6.1 for Oracle Georaster.
and about the other softwares?

somebody know about it?

thanks
Olga

Comments

799716
like this: [http://www.java2s.com/Code/Java/Swing-JFC/Panelwithbackgroundimage.htm]
807589
I have use that code too but it is still not giving me the image.
Here is the code you suggested:
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class NewClass3 {

  public static void main(String[] args) {
    ImagePanel panel = new ImagePanel(new ImageIcon("C\\myimage.jpeg").getImage());

    JFrame frame = new JFrame();
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
  }
}

class ImagePanel extends JPanel {

  private Image img;

  public ImagePanel(String img) {
    this(new ImageIcon(img).getImage());
  }

  public ImagePanel(Image img) {
    this.img = img;
    Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
    setPreferredSize(size);
    setMinimumSize(size);
    setMaximumSize(size);
    setSize(size);
    setLayout(null);
  }

  public void paintComponent(Graphics g) {
    g.drawImage(img, 0, 0, null);
  }
Anything the problem. Can you please help me to get the image.
Thanks

Edited by: m_l on Nov 14, 2008 7:44 AM
799716
ImagePanel panel = new ImagePanel(new ImageIcon("C\\myimage.jpeg").getImage());
guess the missing ':' and the 'e' was a typo!?
807589
There was no missing "e" and ":".
I have checked again but no missing think.
Any ideas why i am not getting it.
799716
ImagePanel panel = new ImagePanel(new ImageIcon("C:\\myimage.jpg").getImage());
ImagePanel panel = new ImagePanel(new ImageIcon("C\\myimage.jpeg").getImage());
see the difference? I do not say that is the error... but check it out!
807589
yes, i have seen the difference and i have fixed it, but it did not make any difference. i am still not getting the background image.
Any idea please?
Thanks
camickr
In the future, Swing related questions should be posted in the Swing forum.

I tested out the code posted in reply 2 and it works fine for me, so you path name or file name must be wrong.

But then I don't use NetBeans. So try your code outside of NetBeans to see if it works.
807589
The image is working in eclipse, but it is not working in netBeans. I don't know why it is not working in netbeans.
I have develop a GUI with buttons and now i want the image as a background of the GUI.
Here is the code for the GUI:
/*
 * GUI.java
 *
 * Created on November 15, 2008, 2:44 AM
 */
package GUITest;



/**
 *
 * @author  user
 */


public class GUI extends javax.swing.JFrame {

    /** Creates new form GUI */
    public GUI() {
        
        initComponents();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Test1 Query");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Test2 Query");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Test3 Query");

        jButton4.setText("Test4 Query");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addGap(32, 32, 32)
                .addComponent(jButton2)
                .addGap(18, 18, 18)
                .addComponent(jButton3)
                .addGap(34, 34, 34)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(253, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// TODO add your handling code here:
}                                        

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// TODO add your handling code here:
}                                        

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUI().setVisible(true);
            }
        });
    }

    
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    // End of variables declaration                   

}
now where do you think i can place the code i wrote for the Image to be a background so that the image can appear?
here is the code for the background:
	import java.awt.Dimension;
	import java.awt.Graphics;
	import java.awt.Image;
	 
	import javax.swing.ImageIcon;
	import javax.swing.JFrame;
import javax.swing.JPanel;
	 
	public class u {
	 
	  public static void main(String[] args) {
	    ImagePanel panel = new ImagePanel(new ImageIcon("C:\\myimage.jpg").getImage());
	 
	    JFrame frame = new JFrame();
	    frame.getContentPane().add(panel);
	    frame.pack();
	    frame.setVisible(true);
	  }
	}
	 
	@SuppressWarnings("serial")
	class ImagePanel extends JPanel {
	 
	  private Image img;
	 
	  public ImagePanel(String img) {
	    this(new ImageIcon(img).getImage());
	  }
	 
	  public ImagePanel(Image img) {
	    this.img = img;
	    Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
	    setPreferredSize(size);
	    setMinimumSize(size);
	    setMaximumSize(size);
	    setSize(size);
	    setLayout(null);
	  }
	 
	  public void paintComponent(Graphics g) {
	    g.drawImage(img, 0, 0, null);
	  }
Can someone help me on this Please
Thanks

Edited by: m_l on Nov 14, 2008 11:37 AM

Edited by: m_l on Nov 14, 2008 11:39 AM
camickr
It works for me and it works in Eclipse, so this is NOT a Java problem.

This is a NetBeans configuration problem.

So find a NetBeans forum and ask someone how to configure NetBeans properly.
807589
Is this not neatbeans forum?
Can someone then help me to configure netbeans please/
Thanks
807589
Hi Experts,
I am still struggling with this thread and i still can't get it work in Netbeans. Can someone help me on this issue please.
Thanks
799716
try to compile and run it outside netbeans.
807589
How can i compile and run it outside netbeans,I have my GUI created in Netbeans. I just run the code in eclipse and it works fine but not on the GUI because i don't have the GUI in eclipse. So now how can i have the background image code on my GUI in Netbeans? Is there anyway i can run this in netbeans?
Thanks
799716
read this: [http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html#win32-2b] (assuming you're using windows!)
807589
I have followed your link but still could not get it. Can you check my code to see if you can modify it please
thanks
799716
Nevermind!

Edited by: phdk on 15-11-2008 13:06
807589
Sorry i don't understand what you mean by " Nevermind!". Do you mean you going to try modifying it or what? I am really still struggling with it using your link as a resource. But still to get it. I will be grateful if you can help.
Thanks
799716
I had a look at your code... this works for me.
/**
 *
 * @author PHDK
 */
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class NewClass1 extends JFrame {

  public NewClass1() {
    initComponents();

  }

  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

      public void run() {
        NewClass1 frame = new NewClass1();
        frame.setVisible(true);
        frame.setBounds(20, 20, 600, 400);
        frame.setDefaultCloseOperation(NewClass1.EXIT_ON_CLOSE);
        frame.setSize(200, 689);

      }
    });
  }

  private void initComponents() {
    ImageIcon image = new ImageIcon("your_Path");
    JLabel background = new JLabel(image);
    background.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
    getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
    JPanel panel = new JPanel();
    panel.add(background);
    panel.setOpaque(false);
    setContentPane(panel);
  }
}
EDIT: removed my image path!

Edited by: phdk on 15-11-2008 13:30
799716
BTW:
public class NewClass1 extends javax.swing.JFrame {
    public NewClass1() {
        /********* Here you call initComponents(); ************/
        initComponents();
            /*
            some code
            */
    }
    public static void main(String args[]) {
        /*
        some code
        */
    }
 
    private void initComponents() {
        /*** CRASH! ***/
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
807589
I have created a GUI with buttons on them. I also created used a code to get an image on the background of my GUI, but anytime i run the program, The image shows on the bacground of the GUI i created with the buttons, but the GUI is not active. I cannot even close the GUI or click on the button. I had to close the whole Netbeans for the GUI to close. What am i doing wrong. can you check the code below to see if u can see my error ?
Here is the code:
 * GUI.java
 *
 * 
package ad6581gui;

/**
 *
 * @author  user
 */
import javax.swing.*;
public class GUI extends javax.swing.JFrame {

    /** Creates new form GUI */
  
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        Load = new javax.swing.JButton();
        Meet = new javax.swing.JButton();
        Query = new javax.swing.JButton();
        Reset = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("GUI");
        setEnabled(false);
        setFocusTraversalPolicyProvider(true);

        Load.setText("Load Data");
        Load.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoadActionPerformed(evt);
            }
        });

        Meet.setText("Meet");

        NN.setText("Query");

        Reset.setText("Reset");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(Load, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
                .addComponent(Meet)
                .addGap(38, 38, 38)
                .addComponent(NN)
                .addGap(18, 18, 18)
                .addComponent(Reset, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(459, 459, 459)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(NN, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Reset, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Meet, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(Load, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>                        

private void LoadActionPerformed(java.awt.event.ActionEvent evt) {                                     

}                                    
public GUI() {
     ImageIcon image = new ImageIcon("C:\\myimage.jpg");
    JLabel background = new JLabel(image);
    background.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
    getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
    JPanel panel = new JPanel();
    panel.add(background);
    panel.setOpaque(false);
    setContentPane(panel);
    initComponents();
    
   
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                GUI frame = new GUI();
                frame.setVisible(true);
                frame.setBounds(20, 20, 600, 400);
                frame.setDefaultCloseOperation(GUI.EXIT_ON_CLOSE);
                frame.setSize(200, 689);
                new GUI().setVisible(true);
            }
        });
    }
    
          
My problem is "initComponents();". If i remove it, the image does not show on the GUI with the buttons, but is actived. But if i leave it there, i get what i want and that is the image shows on the GUI with the buttons, but it is not activated.

Is there anything i am missing?
how can i get the GUI actived after running the program so that i can click on the buttons. can someone help me on this please?
Thanks

Edited by: m_l on Nov 15, 2008 9:32 AM

Edited by: m_l on Nov 15, 2008 9:49 AM
807589
Thanks phdk, your reply helped me get the image on the Background, but i am still struggling with the problem in reply 20 above. I still can't figure it out.
Can someone tell me why the problem is happening please.
Thanks
807589
I tried to show an image in backgroung of the frame using NetBeans and found it hard also.......

I guess from your earlier posts that you simultaneously want to show a background image and also use NetBeans' Form editor to place controls (like buttons) where ever you want. So, to achieve that you have to do the following....... I tried many methods before getting this workaround.........:

The logic is:_
1- Create a new JPanel Form (which you can use to place controls anywhere).
2- Override its paintComponent() method to display the background image.
3- Create a JFrame form (don't use its form editor to place controls)..... u just have to change its constructor a bit....
4- In the constructor set the JPanel form created in 1&2 as the contentPane of the this frame.

In place of 3, u can use a simple java class which extends JFrame and then change its constructor......

This is JPanel form:
/**
 *
 * @author  talha
 */
public class ImagePanel extends javax.swing.JPanel {
    
    BufferedImage image;
    /** Creates new form NewJPanel */
    public ImagePanel(BufferedImage image) {              // edit the constructor to get an image from frame 
        this.image = image;                                          // or just hard code the image here, as you wish......... 
        this.setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));
        initComponents();
    }
    
    @Override                                                       
    protected void paintComponent(Graphics g) {         // override to paint the image also.....
        super.paintComponent(g);                                // very important method, don't miss it :-)
        g.drawImage(image, 0, 0, this);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("jButton2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jButton2)
                .addContainerGap(293, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(175, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(152, 152, 152))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(54, 54, 54)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addContainerGap(194, Short.MAX_VALUE))
        );
    }// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:                                                // add code for action here...
}
     // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;                    // I have added just two buttons... add as many components as you want...
    // End of variables declaration
    
}
This is JFrame code:
/**
 *
 * @author  talha
 */
public class NewJFrame extends javax.swing.JFrame {
   
    /** Creates new form NewJFrame */
    public NewJFrame() throws IOException {                                         //just create a new JFrame form and add the 3-4 line I have added
        initComponents();                                                                        // you don't even need this 
        // create a new Image panel discussed above
        ImagePanel p=new ImagePanel(ImageIO.read(new File("C:\\Users\\talha\\Pictures\\background2.jpg")));   // change image path...                                                                                      
        //set content Pane
        setContentPane(p); 
        validate();
        repaint();
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new NewJFrame().setVisible(true);
                } catch (IOException ex) {
                    Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify
    // End of variables declaration

}
After all this, I should say it would be better if we use pure Swing programming to design forms, instead of NetBeans' Form Editor.

Thanks!
P.S.: remember to add imports as told by NetBeans (one of the many things, NetBeans is good at)

Edited by: T.B.M on Nov 16, 2008 11:50 AM
darrylburke
I tried to show an image in backgroung of the frame using NetBeans and found it hard also.......
Piece of cake once you know where to look :-)

-- Display the "Design" tab
-- From the Properties window, go to "Custom creation code"
-- Type any junk ;-)
-- Go to the "Source" tab and look for the junk you typed (it'll be in a collapsed guarded block).
-- Figure out what they mean by "Custom creation code"
-- Go back and put the code you need there.

For a JPanel as an anonymous inner class that overrides paintComponent, it'll be something like
new JPanel() {
   public void paintComponent(Graphics g) {
      super.paintComponent(g);
      // do other stuff with g
   }
};
Then go back to the source tab, right-click and select "Fix Imports"

db
807589
Thankyou Daryl.............got it working in the first go......... but I took time to get to custom creation code......
-- Display the "Design" tab
OK
-- From the Properties window, go to "Custom creation code"
In NetBeans 6.1 there is no such thing......instead you have to right click on the component and select "Customize code"
-- Type any junk ;-)
I changed the declaration as you suggested......used inner class....
jPanel1 = new javax.swing.JPanel(){
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(image, 0, 0, this);
            }
        };
-- Go to the "Source" tab and look for the junk you typed (it'll be in a collapsed guarded block).
Yes..... I found it there.........NetBeans is simply wonderful !!
-- Figure out what they mean by "Custom creation code"
Yeah........thats simple.............

So..............if we want to display a background image simply........
1- add a JPanel to the JFrame form.
2- override JPanel's paintComponent() method using "Customize code" to paint image.
3- add all the components to the JPanel .......then make it as the content pane of the Frame in the JFrame's constructor.

Yes!!! Got it!! Thanks once again!!
1 - 24
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 24 2008
Added on Nov 26 2008
1 comment
728 views