• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

JComboBox on Background Image  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}
}
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!