Results 1 to 3 of 3
- 04-27-2008, 04:57 PM #1
Member
- Join Date
- Apr 2008
- Location
- Prague, CZE
- Posts
- 4
- Rep Power
- 0
- 04-27-2008, 05:46 PM #2
If you can get the dimension of your picture, then you can also do it....
Initialize the GUI.
Get the picture's dimension,
Resize the frame.
Resize the panel. and other components if affected.
Draw the picture,
update the GUI.freedom exists in the world of ideas
- 04-27-2008, 07:51 PM #3
The JPanel will report its preferredSize to its parent container. You can use the setPreferredSize method _or_ override the getPreferredSize method to set the preferredSize of the panel. If the panel is added to a container whose layout manager respects the preferredSize of its children, ie, tries to display the children at their preferredSize, the panel should appear at the same size as the image.
In java this could look something like this:
Java Code:class Pseudo extends JPanel { BufferedImage image; Dimension size = new Dimension(); Pseudo(BufferedImage image) { this.image = image; size.setSize(image.getWidth(), image.getHeight()); // Option 1: use [i]setPreferredSize[/i] method. setPreferredSize(new Dimension(image.getWidth(), image.getHeight())); } protected void paintComponent(Graphics g) { super.paintComponent(g); // just in case g.drawImage(image,0,0,this); } /** Option 2: override [i]getPreferredSize[/i] method. */ public Dimension getPreferredSize() { return size; } }
Similar Threads
-
The Funny Pictures Thread(this means a lot of pictures...)
By joshua in forum EntertainmentReplies: 22Last Post: 07-25-2012, 09:51 PM -
JPanel in agreement with dimension of pictures
By KamilR in forum AWT / SwingReplies: 1Last Post: 04-28-2008, 07:38 AM -
Arraylist to a 2- dimension array conversion
By mars123 in forum New To JavaReplies: 1Last Post: 12-06-2007, 11:24 AM -
Help Loading Up Pictures
By marco in forum Java AppletsReplies: 3Last Post: 08-14-2007, 10:32 PM -
Help with pictures en Java
By susan in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 04:36 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks