Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JButton "on" JLabel

Status
Not open for further replies.

fuadhamidov

Programmer
Sep 22, 2003
98
TR
hi

i have developed an applet. in applet i need to show a number element on image.

so my applet include a JPanel which include a JLabel ( big image ) and a number of JButton ( elements ) on label .

while i call applet from browser i see ONLY label image.
why button image (or second label image ) is not seen?

if i put an animated image on button, they can seen in applet. otherwise i can't show them.


Code:
package myproject.test;
public class JApplet extends javax.swing.JApplet {
    public void init() {
        initComponents();
    }
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel(
            new javax.swing.ImageIcon(
                getClass().getResource( "/images/bigimage.gif" )
            )
        );
        jButton1 = new javax.swing.JButton(
            new javax.swing.ImageIcon(
                getClass().getResource( "/images/e1.gif" )
            )
        );
        jLabel2 = new javax.swing.JLabel(
            new javax.swing.ImageIcon(
                getClass().getResource( "/images/e2.gif" )
            )
        );

        getContentPane().setLayout(null);

        jPanel1.setLayout(null);

        jLabel1.setOpaque(true);
        jPanel1.add(jLabel1);
        jLabel1.setBounds(0, 70, 370, 270);

        jButton1.setOpaque(false);
        jPanel1.add(jButton1);
        jButton1.setBounds(270, 80, 42, 30);

        jPanel1.add(jLabel2);
        jLabel2.setBounds(80, 80, 0, 30);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 370, 370);

    }

    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;

}
 
ok.

the first added element is shown on the "most front".
in order to change front to back order list, use
Code:
add(Component, i); //don't use add(Component);

if i is -1, the element will be shown at the "most back".
if i is a positive integer, it will be the order of element.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top