aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JComboBox on Background Image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComboBox on Background Image" Watch "JComboBox on Background Image" New topic
Author

JComboBox on Background Image

Kaveh Ghahremani
Greenhorn

Joined: Aug 16, 2001
Posts: 1
Can someone please give me a piece of sample code that places a JComboBox on top of a background picture.
I've been trying with a number of different layout managers and panels and JDektopPanes etc. but I had no luck.
Thank you in advance
Kaveh
Meghna ks
Ranch Hand

Joined: Mar 15, 2001
Posts: 122
Hi Try this piece of code. I dould'nt get it if you wanted the combobox to have a background image or if the combobox needed to be placed on a container that has a Background image. The code is for the latter one.
import java.awt.*;
import javax.swing.*;
import symantec.itools.multimedia.ImageViewer;
import symantec.itools.awt.ImagePanel;
/**
* A basic extension of the javax.swing.JApplet class
*/
public class JApplet1 extends JApplet
{
public void init()
{
// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
symantec.itools.lang.Context.setApplet(this);

// This line prevents the "Swing: checked access to system event queue" message seen in some browsers.
getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);

// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
getContentPane().setLayout(null);
setSize(421,266);
getContentPane().add(box);
box.setBounds(108,156,228,24);
try {
image.setImageURL(new java.net.URL("file:///D:/Images/nature19.jpg"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
try {
image.setStyle(symantec.itools.awt.ImagePanel.IMAGE_SCALED_TO_FIT);
}
catch(java.beans.PropertyVetoException e) { }
image.setLayout(new BorderLayout(0,0));
getContentPane().add(image);
image.setBounds(60,48,291,90);
//}}
image.add(box, BorderLayout.NORTH);
}
//{{DECLARE_CONTROLS
javax.swing.JComboBox box = new javax.swing.JComboBox();
symantec.itools.awt.ImagePanel image = new symantec.itools.awt.ImagePanel();
//}}
}
Meghna
Amit Rosner
Greenhorn

Joined: Dec 03, 2001
Posts: 22
Here a small sample that does that:
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JApplet;
import javax.swing.JComboBox;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class TestApplet extends JApplet
{
public void init()
{
String[] test = {"test"};
JComboBox button = new JComboBox(test);

ImagePanel ip = new ImagePanel(new ImageIcon("test.jpg").getImage());
ip.add(button);
setContentPane(ip);
}
class ImagePanel extends JPanel
{
private Image image;

public ImagePanel(Image image)
{
this.image = image;
}

public void paintComponent(Graphics g)
{
if (image != null)
{
g.drawImage(image, 0, 0, getSize().width, getSize().height, this);
}
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JComboBox on Background Image
 
Similar Threads
JCombo.setBackground()
How to restrict data in JTextField?
Change color of JFileChooser
Can I change the back/foreground color of a disabled JComboBox?
drop down menu