Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Image not being displayed in Jpanel  RSS feed

 
Dave McNamara
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Trying to get an image to display in a GUI.



But nothing is happening in the GUI. I have stepped through and bufferedimage contains the data, but its not being displayed.
Whats happening is, an image is being transmitted to serial port of laptop, so i'm taking it in and storing it in a BufferOutputStream and then trying to open it in my GUI class.
I assuming it something small i'm missing

Dave
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


First you add the label to the frame. Then you add the label to the panel.

A component can only be added to a single component so now your label is on the panel, but you never add the panel to the frame.

1) Don't use setBounds(). The layout manager will determine the size/location of the component.
2) Get rid of the panel, it is not needed.
3) Read the section from the Swing tutorial on How to Use Labels for a simple working example. Read through the tutorial for all the Swing basics.
 
Dave McNamara
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob, thanks for the reply.

I had a look at the tutorial and now have it displaying an image from my hard drive.

So I'm getting an image transferred from a raspberry Pi and is being transmitted in packets to the PC,

I want to be able to view this image in the JFrame once it has been fully transmitted.

So I have a ByteArrayOutputStream in my Transfer image class which writes data to this array from serial port.

Once data is finished transferring it triggers a boolean statement to true which in turn triggers an if loop in my GUI class.

I've debugged and once image is finished transmitting, its goes into this if loop, but no image appears on the GUI.

I've also tried opening the same file I could open prior to trying this but it doesn't open. Same code except in an If loop.

I need to have this code in an If loop because if I don't I get a null pointer exception on this line

The file needs to be available before this line is executed.

Any ideas or tips?

Dave

 
Dave McNamara
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resolved,

Added an eventhandler for displaying image in GUI class. Seems to work now.

Thanks.

Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!