0

I am trying to get 20 images displayed on a jframe in jlabels using a gridlayout. I have added a while loop but still i am only am to see 1 image, please can you help me to display more than image in jlabels on a jframe?

setSize(600, 600);
setDefaultCloseOperation(HIDE_ON_CLOSE);
Container pane = getContentPane();
pane.setLayout(new GridLayout(4,4));
connection = getConnection();
try { // table name:image and second image is field name
statement = (PreparedStatement) connection
.prepareStatement("select content from  images");
result = statement.executeQuery();
byte[] image = null;

while (result.next()) {
image = result.getBytes("image");
}
Image img = Toolkit.getDefaultToolkit().createImage(image);
img = img.getScaledInstance(100, 200, Image.SCALE_SMOOTH);
ImageIcon icon = new ImageIcon(img);
JLabel lPhoto = new JLabel();
lPhoto.setIcon(icon);
Comments
seriously?
4
Contributors
7
Replies
40
Views
3 Years
Discussion Span
Last Post by JamesCherrill
Featured Replies
  • stultuske: downvotes without a comment are, by design, anonymous, so beware of assuming you know who voted. However, stressedout overstepped the mark by re-posting the same question, then posting two entries containing personal abuse, so I have banned him. This thread is therefore dead. JC Read More

  • 1

    considering every reply on one of his threads got downvoted, ... pretty obvious. chances of someone else going to all the trouble of searching out one persons threads and downvoting each and every one reply in it, not of the OP's, are generally very slim. true, there is the oft … Read More

0

you only wrote code to display one single image, what did you think would happen?

Image img = Toolkit.getDefaultToolkit().createImage(image);
img = img.getScaledInstance(100, 200, Image.SCALE_SMOOTH);
ImageIcon icon = new ImageIcon(img);
JLabel lPhoto = new JLabel();
lPhoto.setIcon(icon);

you only get the last image, because you read them all, override each previous value, and use the last to set the image.

Edited by stultuske

0

stresstedout: why did you (yet again) downvote my post? because I answered your question?
if you don't want people to answer your questions, or explain what you're doing wrong ... here's a radical thought: don't ask questions.

2

stultuske: downvotes without a comment are, by design, anonymous, so beware of assuming you know who voted.
However, stressedout overstepped the mark by re-posting the same question, then posting two entries containing personal abuse, so I have banned him. This thread is therefore dead.
JC

1

considering every reply on one of his threads got downvoted, ... pretty obvious.
chances of someone else going to all the trouble of searching out one persons threads and downvoting each and every one reply in it, not of the OP's, are generally very slim.
true, there is the oft chance, but I doubt it. if not, he could have replied in his previous thread that he wasn't the one downvoting.
anyway, I posted my previous reply before I noticed his 'banned' status, otherwise, I wouldn't have.

Comments
You are right
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.