I am totally new in Java. My teacher told me to develop a simple project which includes ADD,EDIT,DELETE etc features. I have done successfully all the features but when I add any image it doesn't fit into the jLabel which I take into a Desktop Pane. It displays as its actual size not according to the jLabel size. I tried a lot with the help of internet but its not working. Here is the code I've done so far,
I know it is a newbie type question and I am sorry for that but I really tried a lot but can't figure out what is the problem and how to solve it. Anyone please help me?
Database connectivity part is not important with respect to this issue. The main thing what we would like to see is how you are initializing the frame/panel etc. For e.g. what is the size of the JLabel that is showing the picture.
but when I add any image it doesn't fit into the jLabel
That isn't how Swing works.
A Swing component determines its preferred size based on the properties of the component. So when you create a button or checkbox or label. The preferred size of the component is determined by the size of the text and/or Icon you add to the component.
So when you add a label to the frame and then pack the frame the size of the frame will be the size of the label.
If the user then resizes the frame, the image will not grow/shrink. If you need this functionality then you need to create a custom component to paint the image and dynamically scale the image as the size of the component changes.
For example you can check out the Background Panel. It is a custom panel that displays an image as a background. You can then add components on top of the image. You can check out the logic for the "scaled" background to see how to do the custom painting.
OK will you please look at this link kindly? Here in the 1st image is the size of the jLabel into which I want to display the image but when I click any stored data from jTable it gives me result like 2nd,3rd image.
I am totally confused that how can I make you understand what exactly I wanted. I think now I can make myself clear that what I wanted? :/