This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
The code for icon positioning in NORTHEAST
Posted by swapnil on November 27, 2000 at 6:28 AM
D/FAROOQ, hello, This is swapnil. pl. find the code for ur query. note that the sh.gif should be very small gif file in size(i.e. height and width ) in order to see the image position w.r.t. to the text. ................................................................. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class test extends JFrame { public static void main(String[] args) { test t=new test(); t.setLocation(200,200); t.show(); } JPanel base,canvas,control; JButton play,imp; JLabel jl;int x,y; public test() { super("hello Demo"); setSize(300,300); base=new JPanel(); base.setLayout(new FlowLayout()); Image img=Toolkit.getDefaultToolkit().getImage("baby2.jpg"); Graphics g=base.getGraphics(); jl=new JLabel(new ImageIcon("sh.gif")); JButton jb=new JButton ("hello",new ImageIcon("sh.gif")); jb.setVerticalTextPosition(SwingConstants.TOP); jb.setHorizontalTextPosition(SwingConstants.LEFT); //jl.setBounds(x+20,x+20,100,100); //addKeyListener(new keylisten()); base.add(jb); base.add(jl); //g.drawImage(img,20,20,this); //setVisible(true); Container mycontentpane=getContentPane(); mycontentpane.add(base); } class keylisten extends KeyAdapter { public void keyPressed(KeyEvent ke) { int k=ke.getKeyCode(); if(k==37) { System.out.println("key pressed on the image"); jl.setBounds(x+5,20,100,100); x=x+5; } } } } ................................................................ hope this helps. regards swapnil
Replies:
|