| Author |
Image problem
|
memati bas
Ranch Hand
Joined: Jan 29, 2006
Posts: 85
|
|
Hello, I add an image to the Panel via the Label object. But, my image does not cover all the Panel. So how can I make my image cover all the panel ?? Thanks
|
 |
Craig Wood
Ranch Hand
Joined: Jan 14, 2004
Posts: 1535
|
|
Here's one way to scale an image to fill a component. This approach is easy enough to adapt to AWT components. If you use a Label or Panel override "public void paint(Graphics g)". You may also have to override "public void update(Graphics g) { paint(g); }" to get it to work properly.
|
 |
memati bas
Ranch Hand
Joined: Jan 29, 2006
Posts: 85
|
|
Can any of you give more clear and explanatory soltuion ?? Thanks.
|
 |
samir Sadiki
Ranch Hand
Joined: Apr 22, 2006
Posts: 31
|
|
Hi, I don't know if there is a way to do what you wanna do using a Label. You could draw the image directly on the Panel if you want. Here is a sample code: import javax.swing.*; import java.awt.*; public class TestImage extends JPanel { public static void main(String[] args) { JFrame frame = new JFrame(); frame.getContentPane().add(new TestImage()); frame.setTitle("test image in panel"); frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } protected void paintComponent(Graphics g) { super.paintComponent(g); ImageIcon imageIcon = new ImageIcon("USA.gif"); Image image = imageIcon.getImage(); g.drawImage(image,0,0,getWidth(),getHeight(),this); } }
|
 |
memati bas
Ranch Hand
Joined: Jan 29, 2006
Posts: 85
|
|
Thanks very much for this... It is indeed what I am searching for one days. Again thanks very much, Best wishes.
|
 |
samir Sadiki
Ranch Hand
Joined: Apr 22, 2006
Posts: 31
|
|
You are very welcome my friend. Good luck!
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Image problem
|
|
|