Solved

Image not changing??

Posted on 2004-09-01
4
159 Views
Last Modified: 2010-03-31
Hi..

I am doing a small GUI application a movie ticket vending machine..

I have this combo box...Inside the combo box are 3 Movie titles..

I want my program to trigger when a user selects a movie my program should display an image...

To trigger im using a actionListner... Here are my codes below..I do not know why my image doesnt seem to change...

selectTitleList.addActionListener( new ActionListener() {
     public void actionPerformed(ActionEvent evt) {
     
         String pic = selectTitleList.getSelectedItem() + ".jpg";
        displayTextPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 1));
        imageLabel1 = new JLabel(new ImageIcon(pic));
        displayTextPanel.add(imageLabel1);
        bookingDisplayArea = new JTextArea(12,50);
        displayTextPanel.add(bookingDisplayArea);      
                                                     
        }
});

I have tried using repaint() but it doesntwork...Please help me..

Thanks
0
Comment
Question by:segar123
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 20 total points
ID: 11958692
>       imageLabel1 = new JLabel(new ImageIcon(pic));
>        displayTextPanel.add(imageLabel1);
>       bookingDisplayArea = new JTextArea(12,50);
>        displayTextPanel.add(bookingDisplayArea);      

replace those lines with:

       imageLabel1.setIcon(new ImageIcon(pic));
       displayTextPanel.setText("");

0
 
LVL 12

Expert Comment

by:Giant2
ID: 11961102
displayTextPanel is visible in your Frame, Dialog, Panel (or someother Container)?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now