Problem displaying image in jpanel
Hi,I have posted this on the applet board, but I think its also a general programming problem, so apologies if it isn't relevant to this board, just say so and I'll remove it!
I've got an applet that receives a variable from a PHP page as a parameter. The variable is "map1.png" the map this variable refers to sits in the same folder as the applet.
I want to use this variable along with getDocumentBase() to create a URL which will then be used to display an image within a jPanel called mapPane.
the code I currently have is:
// get image url
String mapURL = getParameter("mapURL");
//set variable for image
Image map_png;
// set media tracker
MediaTracker mt;
//initialise media tracker
mt = new MediaTracker(this);
map_png = getImage(getDocumentBase(),mapURL);
// tell the MediaTracker to kep an eye on this image, and give it ID 1;
mt.addImage(map_png,1);
// now tell the mediaTracker to stop the applet execution
// until the images are fully loaded.
try
mt.waitForAll();
catch (InterruptedException e) {}
// draw image onto mapPane
mapPane.getGraphics().drawImage(map_png, 200, 200, null);
Currently the Parameter is being passed into the applet (i've written it out within the applet) but the image is not being displayed. Does anyone have any suggestions about what I'm doing wrong?
Cheers
Steve
hi,
No, don't get any exceptions, the Java Console has a message:
<terminated>JavaImageEditor[Java Applet]C:\Program Files\Java\jre1.6.0\bin\javaw.exe
Cheers
Steve
Similar Messages
-
Problems displaying image in JPanel
Hi, I've got an applet that receives a variable from a PHP page as a parameter. The variable is "map1.png" the map this variable refers to sits in the same folder as the applet.
I want to use this variable along with getDocumentBase() to create a URL which will then be used to display an image within a jPanel called mapPane.
the code I currently have is:
// get image url
String mapURL = getParameter("mapURL");
//set variable for image
Image map_png;
// set media tracker
MediaTracker mt;
//initialise media tracker
mt = new MediaTracker(this);
map_png = getImage(getDocumentBase(),mapURL);
// tell the MediaTracker to kep an eye on this image, and give it ID 1;
mt.addImage(map_png,1);
// now tell the mediaTracker to stop the applet execution
// until the images are fully loaded.
try
mt.waitForAll();
catch (InterruptedException e) {}
// draw image onto mapPane
mapPane.getGraphics().drawImage(map_png, 200, 200, null);Currently the Parameter is being passed into the applet (i've written it out within the applet) but the image is not being displayed. Does anyone have any suggestions about what I'm doing wrong?
Cheers
SteveHello,
after an update of the graphics card driver to the newest just released version the problem has vanished.
Regards -
Need to display image on JPanel
Hello
I am trying to implement a graphical version of the Knights Tour. I am done with the algorithm part of the problem itself. I am having problem with displaying the chess board. Although seemingly straightforward the images will not display on the JPanel. Below is a sample of what I am trying to do. Can anyone explain why the code does not work even though it seems okay. Thanks and best regards.
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
public class test extends JFrame {
public test(){
panel pane = new panel();
getContentPane().add(pane);
public static void main(String[]args){
test tst = new test();
tst.setSize(500,500);
tst.show();
public class panel extends JPanel{ // inner class
private Image img;
private ImageIcon icon;
public panel(){
icon = new ImageIcon("cross.gif");
img = icon.getImage();
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
System.out.println("I am here");
g.drawImage(img,40,40,this);
}package com.lc.util.swing ;
import java.awt.Color ;
import java.awt.Graphics ;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Dimension ;
import java.awt.image.ImageObserver ;
import javax.swing.JPanel;
import javax.swing.border.Border;
* Panel displaying an {@link Image}.
* <ul>
* <li>8 positions,</li>
* <li>
* can stretch image for filling the whole available area, or diminish
* its size if too large in width or height,
* </li>
* <li>respects borders (as defined by
* {@link javax.swing.JComponent#setBorder( javax.swing.border.Border ) JComponent.setBorder}
* </li>
* </ul>
* @author Laurent Caillette
* @version $Revision: 1.1.1.1 $ $Date: 2002/02/19 22:12:04 $
public class JImagePanel extends JPanel {
public JImagePanel() {
imageObserver = this ;
* Constructeur assignant une image.
public JImagePanel( Image image ) {
this() ;
setImage( image ) ;
private Image image ;
private ImageObserver imageObserver ;
public void setImage( Image image ) {
this.image = image ;
adjustPreferredSize();
public void setBorder( Border newBorder ) {
super.setBorder( newBorder ) ;
adjustPreferredSize() ;
private void adjustPreferredSize() {
if( image != null ) {
int w = image.getWidth( imageObserver ) ;
int h = image.getHeight( imageObserver ) ;
Border border = getBorder() ;
if( border != null ) {
Insets insets = border.getBorderInsets( this ) ;
if( insets != null ) {
w += ( insets.left + insets.right ) ;
h += ( insets.top + insets.bottom ) ;
Dimension dim = new Dimension( w, h ) ;
this.setPreferredSize( dim ) ;
private int placement = CENTER ;
public int getPlacement() { return placement ; }
public void setPlacement( int placement ) {
if( ( placement < CENTER ) || ( placement > STRETCH ) ) {
throw new IllegalArgumentException( "Unsupported placement value" ) ;
this.placement = placement ;
public void paint( Graphics gr ) {
// x of Image to draw
int x ;
// y of Image to draw
int y ;
// width of Image to draw
int iw ;
// height of Image to draw
int ih ;
// thickness of left border
int bl = 0 ;
// thickness of upper border
int bt = 0 ;
// thickness of right border
int br = 0 ;
// thickness of lower border
int bb = 0 ;
// width of drawable area
int pw = this.getWidth() ;
// height of drawable area
int ph = this.getHeight() ;
// Handle borders
Insets insets = null ;
Border border = getBorder() ;
if( border != null ) {
insets = getBorder().getBorderInsets( this ) ;
if( insets != null ) {
bl = insets.left ;
br = insets.right ;
bb = insets.bottom ;
bt = insets.top ;
pw = pw - bl - br ;
ph = ph - bt - bb ;
// Always display background, for supporting transparency.
super.paint( gr ) ;
if( image != null ) {
iw = image.getWidth( imageObserver ) ;
ih = image.getHeight( imageObserver ) ;
if( ( placement == STRETCH ) ||
( iw > pw ) ||
( ih > ph )
gr.drawImage(image, bl, bt, pw, ph, imageObserver ) ;
} else {
iw = image.getWidth( imageObserver ) ;
ih = image.getHeight( imageObserver ) ;
switch( placement ) {
case CENTER :
x = ( pw - iw ) / 2 ;
y = ( ph - ih ) / 2 ;
break ;
case NORTH :
x = ( pw - iw ) / 2 ;
y = 0 ;
break ;
case NORTHEAST :
x = pw - iw ;
y = 0 ;
break ;
case EAST :
x = pw - iw ;
y = (ph - ih ) / 2 ;
break ;
case SOUTHEAST :
x = pw - iw ;
y = ph - ih ;
break ;
case SOUTH :
x = ( pw - iw ) / 2 ;
y = ph - ih ;
break ;
case SOUTHWEST :
x = 0 ;
y = ph - ih ;
break ;
case WEST :
x = 0 ;
y = ( ph - ih ) / 2 ;
break ;
case NORTHWEST :
x = 0 ;
y = 0 ;
break ;
default :
throw new IllegalArgumentException(
"Unsupported placement value" ) ;
// Add border offset
x += bl ;
y += bt ;
gr.drawImage( image, x, y, this ) ;
public final static int CENTER = 0 ;
public final static int NORTH = 1 ;
public final static int NORTHEAST = 2 ;
public final static int EAST = 3 ;
public final static int SOUTHEAST = 4 ;
public final static int SOUTH = 5 ;
public final static int SOUTHWEST = 6 ;
public final static int WEST = 7 ;
public final static int NORTHWEST = 8 ;
public final static int STRETCH = 9 ; -
Display image in JPanel without saving any file to disk
Hi,
I am fetching images from database. I am saving this image, display in JPanel and delete it. But this is not actually I want.
I wish to fetch this image as stream , store in memory and display in JPanel without saving any fiel in disk.
I wonder if it is Possible or any used implementation that I can use in my project. Any idea or experienced knowledge is enough.
ThanksIn what format is the image coming to you from the database? If it's an InputStream subclass, just use javax.imageio.ImageIO:
InputStream in = getImageInputStream();
BufferedImage image = null;
try {
image = ImageIO.read(in);
} finally {
in.close();
// ... Display image in your JPanel as you have beenIf you receive the image as an array of bytes, use the same method as above, but with a ByteArrayInputStream:
byte[] imageData = getImageData();
ByteArrayInputStream in = new ByteArrayInputStream(imageData);
BufferedImage image = null;
try {
image = ImageIO.read(in);
} finally {
in.close();
// ... Display image in your JPanel as you have been -
Problem Displaying image from blob
Hi all,
I m using,
Database : 10g Rel 2
Frontend : DevSuite 10g
OS : WinXp
Browser : IE 6
Problem : In my forms i m displaying images from blob column but some of the images are not displayed. I have tried with all image formats available in combination with all available display quality but no luck. What could be the reason for it and how do i solve it?
Can anyone help me plz?
Thnx in advance.
ImtiazHello,
It is very difficult for us to "guess" what images you can read and what others you cannot.
Maybe you could provide more information on images that are not displayed ?
What is their native format ?
Francois -
Having trouble displaying image in JPanel
I want to display an image in jpanel making it to scale to the size of the panel.
And later i should be able to draw on that image , i am really new to all this , but i have to finish it soon.
This is the code i am compiling and getting error
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LocaterClient extends JFrame
JPanel panel;
public LocaterClient()
super("LocaterClient");
panel = new JPanel();
panel.setSize(374,378);
panel.setOpaque(false);
panel.setVisible(true);
getContentPane().add(panel);
/*JFrame f = new JFrame();
f.setSize(374,378);
f.getContentPane().add(panel);*/
public void paintComponent(Graphics g)
super.paintComponent(g);
ImageIcon img = new ImageIcon("World_MER.jpg");
ImageIcon fillImage = new ImageIcon(img.getImage().getScaledInstance
(getWidth(), getHeight(),Image.SCALE_REPLICATE));
g.drawImage(fillImage.getImage(), 0,0, this);
public static void main(String args[])
LocaterClient lc = new LocaterClient();
lc.setDefaultCloseOperation( EXIT_ON_CLOSE );
lc.pack();
lc.setVisible(true);
This is the error i am getting
LocaterClient.java:24: cannot resolve symbol
symbol : method paintComponent (java.awt.Graphics)
location: class javax.swing.JFrame
super.paintComponent(g);
^
1 error
If i remove super.paintComponent(g); line it compiles and runs but i get a tiny panel without the image.
PLease help me , i am not evn sure is this is the procedure should i follow , because i should be able to draw on that image later on .
Please provide me with some sample code.import javax.swing.*;
import java.awt.*;
public class ImagePainter extends JPanel{
private Image img;
public ImagePainter(){
img = Toolkit.getDefaultToolkit().getImage("MyImage.gif");
public void paintComponent(Graphics g){
g.drawImage(img,0,0,getSize().width,getSize().height);
public static void main(String[]args){
JFrame frame = new JFrame();
frame.getContentPane.add(new ImagePainter());
frame.setSize(500,500);
frame.show(); -
i have got buffered image from webcam using jmf. i want to display it on JPanel.
i override paint() but it doesn't display as it captures
when i maximize window it then displays
urgent help neededThe bounds of your JPanel may be incorrect. You should try the setBounds(int x, int y, int width, int height) method on it.
Please past your code for more help :p -
Problem Displaying Images in a JFrame
I am writing a program that displays images on a JFrame window. I have been reading the other postings about this topic however I have not been able to make my code work. I am hoping there is some obvious solution that I am not noticing. Please help, I am very confused!
public class WelcomeWindow {
private JLabel label;
private ImageIcon logo;
public WelcomeWindow() {
label = new JLabel();
logo = new ImageIcon("/images/logo.gif");
label.setIcon(logo);
this.getContentPane().add(label);Instead of a JLabel, have you tried to use a JButton containing the Icon?
Also (but I think you've done it already), you could do that :
File iconFile = new File("/images/logo.gif");
if (!iconFile.isFile()) {
System.out.println("Not a file");
That way you'll be certain that the path given is correct.
Hope this helps. -
Two problems with displaying images in JPanel
Hi,
I need to display some small rectangular images inside a JPanel. These images also need to be componenents as they will have listeners associated with them. I have never had any experience with images, so I might totally be down the wrong path. I was thinking of just creating a class which extends JComponent, and using the graphics drawImage method. However, I don't want each image component to have to know exactly where to draw the image associated with itself. Rather, I want the JPanel which holds all of the images to know how to lay them out.
Is there an easier way to use images?
Which brings me to my second problem. I want these images to overlap each other, so that only a small portion of each is showing (this way I can fit more on the screen), then when the user clicks on one, I can show more of it.
Unfortunately, I don't know of any layout managers which will allow me to overlap components. I could use the drawImage method mentioned above, but like I said, I would like to try to not have each image object try and figure out its location.
any help is greatly appreciated. Thanks!Hi
there is a better way ; it is called a JLabel ;-)
JLabel myJLabel = new JLabel(new ImageIcon("img/myLogo.gif"));for your second problem, don't use any layout manager like in this code :
myJPanel.setLayout(null);
myJPanel.add(myJLabel);
myJLabel.setBounds(new Rectangle(x, y, width, height);hope it helps
Nico -
Hi,
I'm trying to work out the best method to display a set of thumbnail images in a JPanel (similar to a Thumbnail view in windows XP) - at the moment I'm using a Tree, but am wondering whether this is the best way to go about it? I'm using a tree in combination with a TreeModel but am having some problems as the cells don't expand to fit the picture size. Any ideas appreciated!!
thanks
JonathanWhy dont you use a JTable?
-
Hi I am trying to make a mud and the one thing I wanted to make different was an actual image map. My code reads the map from a text file and then places it into an array which then is displayed using diffent images for different characters. I wanted to start out by reading in the map and displaying it. So far so good considering that the code works while running in the applet viewer in PCGrasp, but the problem comes in when the html is run. Is there anything that I need to add to the code to display the map. The textbox and the background display but nothing else. Maybe my background is being placed on top of my images? Well here is the code so far:
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.*;
public class ImageEx extends Applet implements Runnable
// Initialisierung der Variablen
int x_pos = 30; // x - Position des Balles
int y_pos = 100; // y - Position des Balles
int x_speed = 1; // Geschwindigkeit des Balles in x - Richtung
int radius = 20; // Radius des Balles
int appletsize_x = 300; // Gr��e des Applets in x - Richtung
int appletsize_y = 300; // Gr��e des Applets in y - Richtung
// Variablen f�r die Doppelpufferung
private Image dbImage;
private Graphics dbg;
private TextField commandLine;
// Bildvariable f�r den Hintergrund
Image Character;
Image backImage;
char array[][];
MediaTracker mt;
URL base;
public void init()
mt = new MediaTracker(this);
setBackground(Color.blue);
// Laden der Bilddatei
backImage = getImage(getDocumentBase(), "desert.gif");
Character = getImage(getDocumentBase(), "Test_Char.gif");
commandLine = new TextField(50);
add(commandLine,"South");
try
base = getDocumentBase();
TextReader textReader = new TextReader ("First Map.txt");
String s = textReader.readLine();
String t = textReader.readLine();
int z = Integer.parseInt(s);
int y = Integer.parseInt(t);
int x = 0, d = 0, c = 0;
String map[] = new String[z];
for(int j = 0; j < z; j++)
map[j] = textReader.readLine();
++x;
array = new char[z][y];
for(int a = 0; a < array.length; a++)
for(int b = 0; b < array[0].length; b++)
array[a] = map[d].charAt(c);
if(c != 21)
++c;
else
c = 0;
++d;
//System.out.print(array[0][3]);
catch (Exception e)
System.out.println(e.toString());
mt.addImage(backImage,1);
mt.addImage(Character,2);
// now tell the mediaTracker to stop the applet execution
// (in this example don't paint) until the images are fully loaded.
// must be in a try catch block.
try
mt.waitForAll();
catch (InterruptedException e)
public void start ()
// Schaffen eines neuen Threads, in dem das Spiel l�uft
Thread th = new Thread(this);
// Starten des Threads
th.start();
public void stop()
public void run ()
// Erniedrigen der ThreadPriority um zeichnen zu erleichtern
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
// Solange true ist l�uft der Thread weiter
while(true)
// Wenn der Ball den rechten Rand ber�hrt, dann prallt er ab
if(x_pos > appletsize_x - radius)
// �ndern der Richtung des Balles
x_speed = -1;
// Ball br�hrt linken Rand und prallt ab
else if(x_pos < radius)
// �ndern der Richtung des Balles
x_speed = +1;
// Ver�ndern der x- Koordinate
x_pos += x_speed;
// Neuzeichnen des Applets
repaint();
try
// Stoppen des Threads f�r in Klammern angegebene Millisekunden
Thread.sleep (20);
catch(InterruptedException ex)
// do nothing
// Zur�cksetzen der ThreadPriority auf Maximalwert
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
/** Update - Methode, Realisierung der Doppelpufferung zur Reduzierung des Bildschirmflackerns */
public void update(Graphics g)
// Initialisierung des DoubleBuffers
if(dbImage == null)
dbImage = createImage(this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics();
// Bildschirm im Hintergrund l�schen
dbg.setColor(getBackground ());
dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
// Auf gel�schten Hintergrund Vordergrund zeichnen
dbg.setColor(getForeground());
paint(dbg);
// Nun fertig gezeichnetes Bild Offscreen auf dem richtigen Bildschirm anzeigen
g.drawImage(dbImage, 0, 0, this);
public void paint (Graphics g)
mapDraw(g);
g.setColor (Color.red);
g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);
public void mapDraw(Graphics c)
int x_loc = 0;
int y_loc = 0;
for(int x = 0; x < array.length; x++)
for(int y = 0; y < array[0].length; y++)
switch(array[x][y])
case 'x': backImage = getImage(getDocumentBase(), "grass_dark.gif");
break;
case 'E': backImage = getImage(getDocumentBase(), "dungeon_door.jpg");
break;
case '#': backImage = getImage(getDocumentBase(), "desert.gif");
break;
case 'H': backImage = getImage(getDocumentBase(),"house.gif");
break;
case 'U': backImage = getImage(getDocumentBase(),"house.gif");
break;
c.drawImage(backImage, x_loc, y_loc,16,16, this);
x_loc += 16;
y_loc += 16;
x_loc = 0;
c.drawImage(Character,64, 32,16,16, this);
any help or constructive criticism would be greatly appreciatedsorry for not having the code tags I had to copy and paste and the tags didn't copy over! :-(
-
Hello, I am having problems trying to display an image on a Panel which is attached to a Frame. I can display an Image on the Frame with no difficulty, however nothing appears when I try to draw on the Panel.
Hope someone can help me with this.
Here is the code
import java.awt.*;
import java.awt.event.*;
class TestFrame extends Frame
Panel panel;
public TestFrame()
setSize(400,400);
panel = new Panel();
add(panel);
public class panel extends Panel
Image img;
public panel()
setSize(400,400);
setVisible(true);
img = Toolkit.getDefaultToolkit().getImage("C:\\red.gif");
public void paint(Graphics g)
g.drawImage(img,0,0,this);
public static void main (String[] args)
TestFrame f = new TestFrame();
f.setVisible(true);
}I took a look on your code and I find that 2 things might be wrong with it. See the comments below.
import java.awt.*;
import java.awt.event.*;
class TestFrame extends Frame
Panel panel;
public TestFrame()
setSize(400,400);
panel = new Panel(); /****You created a Panel object from the the awt package and not an object from the panel class that you defined below. Try using panel= new panel(); or use a anonymous class for this purpose. The picture will never show because it is not using the class that you defined************/
add(panel);
public class panel extends Panel /*******Try giving the panel class that you defined another name so as to not confuse you with java.awt.Panel classs. ********/
Image img;
public panel()
setSize(400,400);
setVisible(true);
img =
=
Toolkit.getDefaultToolkit().getImage("C:\\red.gif");
public void paint(Graphics g)
g.drawImage(img,0,0,this);
public static void main (String[] args)
TestFrame f = new TestFrame();
f.setVisible(true);
}Below is a panel class that i think can help. Just pass the appropriate parameters to it.
//container class for the image panel
public class ImagePanel extends Panel {
Image image;
public ImagePanel(Image image) {
this.image = image;
// display the image
public void paint( Graphics g )
// draw the original image
g.drawImage( image, 1, 1, this ); -
Simple and efficient way to display image on jpanel
AOA
What may be the simple and efficient way
to display a strored jpg image on a jpanel in an application.
i will appreciate more than one ways.
thanksJPanel panel = new JPanel() {
public void paintComponent(Graphics g) {
g.drawImage(......);
}; -
Persistent Problems displaying images
I thought I'd already managed to fix this problem but it doesn't seem to be the case. I have two tilelists that items can be dragged between and when each item is clicked the information and"largeImage" contained within it should display in the right hand panel however this works fine in previewing but when I actually change it into an air application and run it the images do not display in the right hand panel when each item within the tilelists is clicked.
What changes would I need to make to this code to make it work correctly when changed into an AIR app?
<?xml version="1.0" encoding="utf-8"?><mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initprofile1NewsAndSportSO()">
<mx:Script>
<![CDATA[
Bindable][
Embed(source="assets/images/bbcnews_small.png")]
public var image1:Class;
Bindable][
Embed(source="assets/images/itv_small.png")]
public var image2:Class;
Bindable][
Embed(source="assets/images/skynews_small.png")]
public var image3:Class;
]]>
</mx:Script>
<mx:Script>
<![CDATA[
import mx.collections.*;
import flash.net.SharedObject;
public var profile1NewsAndSportSO:SharedObject;
private var profile1NewsAndSportaddLinksFullAC:ArrayCollection = new ArrayCollection([{link:
"www.bbcnews.com", label:"BBC News", icon:"image1", largeImage:"assets/images/bbcnews_small.png", title:"BBC News", description:"BBC News description will go here"},{link:
"www.itv.com/", label:"ITV", icon:"image2", largeImage:"assets/images/itv_small.png", title:"ITV", description:"ITV Description will go here"},{link:
"www.skynews.com", label:"Sky News", icon:"image3", largeImage:"assets/images/skynews_small.png", title:"Sky News", description:"Sky News Description will go here"}]);
private var profile1NewsAndSportaddLinksAC:ArrayCollection = new ArrayCollection([{link:
"www.bbcnews.com", label:"BBC News", icon:"image1", largeImage:"assets/images/bbcnews_small.png", title:"BBC News", description:"BBC News description will go here"},{link:
"www.itv.com/", label:"ITV", icon:"image2", largeImage:"assets/images/itv_small.png", title:"ITV", description:"ITV Description will go here"},{link:
"www.skynews.com", label:"Sky News", icon:"image3", largeImage:"assets/images/skynews_small.png", title:"Sky News", description:"Sky News Description will go here"}]);
private function profile1NewsAndSportReset():void{resetprofile1NewsAndSportAC();
profile1NewsAndSportAddLinksTilelist.dataProvider
= profile1NewsAndSportaddLinksAC;
profile1NewsAndSportLinkChoice.dataProvider =
new ArrayCollection([]);}
private function resetprofile1NewsAndSportAC():void{profile1NewsAndSportaddLinksAC.removeAll();
for each(var obj:Object in profile1NewsAndSportaddLinksFullAC){profile1NewsAndSportaddLinksAC.addItem(obj);
private function initprofile1NewsAndSportSO():void{profile1NewsAndSportSO = SharedObject.getLocal(
"profile1NewsAndSport");
if(profile1NewsAndSportSO.size > 0){
if(profile1NewsAndSportSO.data.profile1NewsAndSportaddList){
if(profile1NewsAndSportSO.data.profile1NewsAndSportaddList != "empty"){
var profile1NewsAndSportaddList:Array = profile1NewsAndSportSO.data.profile1NewsAndSportaddList.split(",");
var profile1NewsAndSporttempAC1:ArrayCollection = new ArrayCollection();
for each(var str:String in profile1NewsAndSportaddList){
for each(var obj1:Object in profile1NewsAndSportaddLinksAC){
if(str == obj1.label){profile1NewsAndSporttempAC1.addItem(obj1);
continue;}
if(profile1NewsAndSporttempAC1.length > 0){profile1NewsAndSportAddLinksTilelist.dataProvider = profile1NewsAndSporttempAC1;
if(profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList){
var profile1NewsAndSportchoiceList:Array = profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList.split(",");
var profile1NewsAndSporttempAC2:ArrayCollection = new ArrayCollection();
for each(var str2:String in profile1NewsAndSportchoiceList){
for each(var obj2:Object in profile1NewsAndSportaddLinksAC){
if(str2 == obj2.label){profile1NewsAndSporttempAC2.addItem(obj2);
continue;}
if(profile1NewsAndSporttempAC2.length > 0){profile1NewsAndSportLinkChoice.dataProvider = profile1NewsAndSporttempAC2;
else{profile1NewsAndSportReset();
private function saveprofile1NewsAndSport(event:MouseEvent):void{
var profile1NewsAndSportaddList:String = "";
if(profile1NewsAndSportAddLinksTilelist.dataProvider){
if(ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).length > 0){
for each(var obj1:Object inprofile1NewsAndSportAddLinksTilelist.dataProvider){
profile1NewsAndSportaddList += obj1.label +
else{profile1NewsAndSportaddList =
"empty";}
profile1NewsAndSportSO.data.profile1NewsAndSportaddList = profile1NewsAndSportaddList;
var profile1NewsAndSportchoiceList:String = "";
for each(var obj2:Object inprofile1NewsAndSportLinkChoice.dataProvider){
profile1NewsAndSportchoiceList += obj2.label +
profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList = profile1NewsAndSportchoiceList;
profile1NewsAndSportSO.flush();
]]>
</mx:Script>
<mx:TileList id="profile1NewsAndSportAddLinksTilelist" fontWeight="bold" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="292" width="650" left="21" columnCount="5" rowHeight="145" columnWidth="125" itemClick="titleLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.title; websiteLinkLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.link; descLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.description; linkImage.source=profile1NewsAndSportAddLinksTilelist.selectedItem.largeImage;" itemDoubleClick="{navigateToURL(new URLRequest('http://' + profile1NewsAndSportAddLinksTilelist.selectedItem.link))}" doubleClickEnabled="true" backgroundColor="#000000" borderColor="#FFFFFF" color="#FFFFFF" borderSides="top right left" y="25"/>
<mx:Canvas id="SitePreviewArea" y="10" width="453" height="540" backgroundColor="#545050" cornerRadius="20" borderStyle="solid" x="692" borderThickness="2" dropShadowEnabled="true" borderColor="#000000">
<mx:Label x="45" y="309" text="Website Name:" width="150" height="52" fontSize="14" fontWeight="bold" color="#FFFFFF" left="10"/>
<mx:Label x="150.5" y="309" id="titleLabel" width="282.5" height="24" fontWeight="bold" fontSize="14" color="#FCFF00"/>
<mx:Label x="124.5" y="385" text="Website Description:" width="200" height="24" fontSize="14" fontWeight="bold" color="#FFFFFF" textAlign="center"/>
<mx:TextArea x="16" y="417" id="descLabel" width="421" height="69" textAlign="left" color="#FCFF00" borderThickness="0" backgroundColor="#545050" editable="false" enabled="true" disabledColor="#FFFFFF" backgroundDisabledColor="#545050" fontWeight="bold" fontSize="12"/>
<mx:Label x="61" y="342" text="Website Link:" width="150" height="52" fontSize="14" fontWeight="bold" color="#FFFFFF" left="10"/>
<mx:TextArea x="150.5" y="343" id="websiteLinkLabel" width="282.5" height="33" fontWeight="bold" fontSize="12" color="#FCFF00" borderThickness="0" backgroundColor="#545050" editable="false" enabled="true" disabledColor="#FCFF00" backgroundDisabledColor="#545050"/>
<mx:Button id="goToSiteButton" top="494" left="168" label="VISIT SITE" fontWeight="bold" fontSize="14" color="#000000" click="{navigateToURL(new URLRequest('http://' + websiteLinkLabel.text))}" fillAlphas="[1.0, 1.0]" fillColors="[#FFFFFF, #DCDCDC]" borderColor="#000000"/>
<mx:Canvas x="99.5" y="51" width="250" height="250" backgroundColor="#FFFFFF">
<mx:Image id="linkImage" click="{navigateToURL(new URLRequest('http://' + websiteLinkLabel.text))}" width="250" height="250" x="0" y="0" scaleContent="true" top="2" right="2" left="2" bottom="2"/>
No thats not what I meant sorry. I have two versions with the same code. One a regular Flex app and one an AIR version but the code is of course exactly the same except for the WindowedApplication part. I only posted the flex app version code incase someone could take a look at it and modify it for me. It's just that the application needs to use the shared object method like in that code but it also needs to display the relevant image on the right hand panel when the app is installed on a user's machine.
Here's the code for the AIR version:-
<?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initprofile1NewsAndSportSO()" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
Bindable][
Embed(source="assets/images/bbcnews_small.png")]
public var image1:Class;
Bindable][
Embed(source="assets/images/itv_small.png")]
public var image2:Class;
Bindable][
Embed(source="assets/images/skynews_small.png")]
public var image3:Class;
]]>
</mx:Script>
<mx:Script>
<![CDATA[
import mx.collections.*;
import flash.net.SharedObject;
public var profile1NewsAndSportSO:SharedObject;
private var profile1NewsAndSportaddLinksFullAC:ArrayCollection = new ArrayCollection([{link:
"www.bbcnews.com", label:"BBC News", icon:"image1", largeImage:"assets/images/bbcnews_small.png", title:"BBC News", description:"BBC News description will go here"},{link:
"www.itv.com/", label:"ITV", icon:"image2", largeImage:"assets/images/itv_small.png", title:"ITV", description:"ITV Description will go here"},{link:
"www.skynews.com", label:"Sky News", icon:"image3", largeImage:"assets/images/skynews_small.png", title:"Sky News", description:"Sky News Description will go here"}]);
private var profile1NewsAndSportaddLinksAC:ArrayCollection = new ArrayCollection([{link:
"www.bbcnews.com", label:"BBC News", icon:"image1", largeImage:"assets/images/bbcnews_small.png", title:"BBC News", description:"BBC News description will go here"},{link:
"www.itv.com/", label:"ITV", icon:"image2", largeImage:"assets/images/itv_small.png", title:"ITV", description:"ITV Description will go here"},{link:
"www.skynews.com", label:"Sky News", icon:"image3", largeImage:"assets/images/skynews_small.png", title:"Sky News", description:"Sky News Description will go here"}]);
private function profile1NewsAndSportReset():void{resetprofile1NewsAndSportAC();
profile1NewsAndSportAddLinksTilelist.dataProvider
= profile1NewsAndSportaddLinksAC;
profile1NewsAndSportLinkChoice.dataProvider =
new ArrayCollection([]);}
private function resetprofile1NewsAndSportAC():void{profile1NewsAndSportaddLinksAC.removeAll();
for each(var obj:Object in profile1NewsAndSportaddLinksFullAC){profile1NewsAndSportaddLinksAC.addItem(obj);
private function initprofile1NewsAndSportSO():void{profile1NewsAndSportSO = SharedObject.getLocal(
"profile1NewsAndSport");
if(profile1NewsAndSportSO.size > 0){
if(profile1NewsAndSportSO.data.profile1NewsAndSportaddList){
if(profile1NewsAndSportSO.data.profile1NewsAndSportaddList != "empty"){
var profile1NewsAndSportaddList:Array = profile1NewsAndSportSO.data.profile1NewsAndSportaddList.split(",");
var profile1NewsAndSporttempAC1:ArrayCollection = new ArrayCollection();
for each(var str:String in profile1NewsAndSportaddList){
for each(var obj1:Object in profile1NewsAndSportaddLinksAC){
if(str == obj1.label){profile1NewsAndSporttempAC1.addItem(obj1);
continue;}
if(profile1NewsAndSporttempAC1.length > 0){profile1NewsAndSportAddLinksTilelist.dataProvider = profile1NewsAndSporttempAC1;
if(profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList){
var profile1NewsAndSportchoiceList:Array = profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList.split(",");
var profile1NewsAndSporttempAC2:ArrayCollection = new ArrayCollection();
for each(var str2:String in profile1NewsAndSportchoiceList){
for each(var obj2:Object in profile1NewsAndSportaddLinksAC){
if(str2 == obj2.label){profile1NewsAndSporttempAC2.addItem(obj2);
continue;}
if(profile1NewsAndSporttempAC2.length > 0){profile1NewsAndSportLinkChoice.dataProvider = profile1NewsAndSporttempAC2;
else{profile1NewsAndSportReset();
private function saveprofile1NewsAndSport(event:MouseEvent):void{
var profile1NewsAndSportaddList:String = "";
if(profile1NewsAndSportAddLinksTilelist.dataProvider){
if(ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).length > 0){
for each(var obj1:Object inprofile1NewsAndSportAddLinksTilelist.dataProvider){
profile1NewsAndSportaddList += obj1.label +
else{profile1NewsAndSportaddList =
"empty";}
profile1NewsAndSportSO.data.profile1NewsAndSportaddList = profile1NewsAndSportaddList;
var profile1NewsAndSportchoiceList:String = "";
for each(var obj2:Object inprofile1NewsAndSportLinkChoice.dataProvider){
profile1NewsAndSportchoiceList += obj2.label +
profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList = profile1NewsAndSportchoiceList;
profile1NewsAndSportSO.flush();
]]>
</mx:Script>
<mx:TileList id="profile1NewsAndSportAddLinksTilelist" fontWeight="bold" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="292" width="650" left="21" columnCount="5" rowHeight="145" columnWidth="125" itemClick="titleLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.title; websiteLinkLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.link; descLabel.text=profile1NewsAndSportAddLinksTilelist.selectedItem.description; linkImage.source=profile1NewsAndSportAddLinksTilelist.selectedItem.largeImage;" itemDoubleClick="{navigateToURL(new URLRequest('http://' + profile1NewsAndSportAddLinksTilelist.selectedItem.link))}" doubleClickEnabled="true" backgroundColor="#000000" borderColor="#FFFFFF" color="#FFFFFF" borderSides="top right left" y="25"/>
<mx:Canvas id="SitePreviewArea" y="10" width="453" height="540" backgroundColor="#545050" cornerRadius="20" borderStyle="solid" x="692" borderThickness="2" dropShadowEnabled="true" borderColor="#000000">
<mx:Label x="45" y="309" text="Website Name:" width="150" height="52" fontSize="14" fontWeight="bold" color="#FFFFFF" left="10"/>
<mx:Label x="150.5" y="309" id="titleLabel" width="282.5" height="24" fontWeight="bold" fontSize="14" color="#FCFF00"/>
<mx:Label x="124.5" y="385" text="Website Description:" width="200" height="24" fontSize="14" fontWeight="bold" color="#FFFFFF" textAlign="center"/>
<mx:TextArea x="16" y="417" id="descLabel" width="421" height="69" textAlign="left" color="#FCFF00" borderThickness="0" backgroundColor="#545050" editable="false" enabled="true" disabledColor="#FFFFFF" backgroundDisabledColor="#545050" fontWeight="bold" fontSize="12"/>
<mx:Label x="61" y="342" text="Website Link:" width="150" height="52" fontSize="14" fontWeight="bold" color="#FFFFFF" left="10"/>
<mx:TextArea x="150.5" y="343" id="websiteLinkLabel" width="282.5" height="33" fontWeight="bold" fontSize="12" color="#FCFF00" borderThickness="0" backgroundColor="#545050" editable="false" enabled="true" disabledColor="#FCFF00" backgroundDisabledColor="#545050"/>
<mx:Button id="goToSiteButton" top="494" left="168" label="VISIT SITE" fontWeight="bold" fontSize="14" color="#000000" click="{navigateToURL(new URLRequest('http://' + websiteLinkLabel.text))}" fillAlphas="[1.0, 1.0]" fillColors="[#FFFFFF, #DCDCDC]" borderColor="#000000"/>
<mx:Canvas x="99.5" y="51" width="250" height="250" backgroundColor="#FFFFFF">
<mx:Image id="linkImage" click="{navigateToURL(new URLRequest('http://' + websiteLinkLabel.text))}" width="250" height="250" x="0" y="0" scaleContent="true" top="2" right="2" left="2" bottom="2" -
How to display image at jpanel in application GUI
i wana load an image from given location to my GUI when application starts.
according to my perception this code should load image but its not working.
Will any body kindly help me and point out the "reasons" for not working following piece of code from my application.
public class MainFrame extends JFrame
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
Image image = Toolkit.getDefaultToolkit().createImage("c:\\form-3.jpg");
javax.swing.JScrollBar jScrollBar1 = new JScrollBar();
BorderLayout borderLayout1 = new BorderLayout();
public MainFrame()
try
jbInit();
} catch (Exception ex)
ex.printStackTrace();
public static void main(String[] args)
MainFrame mainFrame = new MainFrame();
private void jbInit() throws Exception
//jbInit() defined here
public void paintComponent(Graphics g)
// jPanel1.getGraphics().drawImage(image,0,0,jPanel1);
Graphics2D g2D = (Graphics2D) g;
BufferedImage bi = (BufferedImage) createImage(getWidth(),getHeight());
bi.createGraphics().drawImage(image, 0,0, jPanel1);
// g.drawImage(image,0,0,jPanel1);
public void jButton2_mouseClicked(MouseEvent e)
public void jButton1_mouseClicked(MouseEvent e)
this.dispose();
System.exit( 0 );
/////////////////////////////////////////////////////////////////////////////this works OK
(stripped of everything unrelated to your question)
import javax.swing.*;
import java.awt.*;
class MainFrame extends JFrame
Image image = Toolkit.getDefaultToolkit().createImage("test.gif");
public static void main(String[] args)
MainFrame mainFrame = new MainFrame();
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setSize(200,200);
mainFrame.setVisible(true);
public void paint(Graphics g)//<-----heavyweight component
super.paint(g);
g.drawImage(image,50,50,this);
}
Maybe you are looking for
-
After Leopard update, my G4 thinks it's a G5 and I can't log in!!
Hoping you can help: I installed the latest software update on Friday, then when I restarted my Powerbook G4 I found myself with a login screen with my username and space for password (I'm usually logged in automatically). Entering my password sent m
-
Myself a Lenovo user from India, recently moved to Aus for Job purposes. Thought of buying the Lenovo, (I do think its a good pick among the top guys and had an excellent service from India (I miss my country!!) ). bought a B590. Had an issue with ba
-
PDF Portfolio on IPAD using Adobe X does not record notes and highlights
Hello I have uploaded a PDF Portfolio and ADOBE Reader X to my IPAD and cannot highlight or annotate the documents. The pencil tool is greyed out. Is there a setting that I am forgetting to create? Thank you!
-
Enterprise SecMgr: Can't add Database Schema Mapping to OracleDefaultDomain
Hello, I'm trying to configure Enterprise Users (using a shared schema) and within EntSecMgr, I select... Realms / MyID realm / Enterprise Domains / OracleDefaultDomain / Enterprise Roles / OracleDefaultDomain / Database Schema Mapping and from there
-
Project Settlement @ Project Systems
Hi Experts I am working on how to settle a Project in Project Systems. Could you please provide me guidelines how to do it. I am also looking for the connection/relation between Project Systems and Result Analysis of Product Costing. Thank you regar