Results 1 to 7 of 7
  1. #1
    muhammad naim is offline Member
    Join Date
    Jul 2013
    Location
    Malaysia
    Posts
    4
    Rep Power
    0

    Default Button To Display Image And Text

    Hello , i'm newbie in java.

    how to display image and text when click button.. like this picture

    Button To Display Image And Text-soalan-4.png


    ** select pictures is title ..

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Button To Display Image And Text

    Read the API for JButton and follow the link to the Oracle tutorial on the subject.

    Also go through the section of the same tutorial titled How to Use Icons.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    muhammad naim is offline Member
    Join Date
    Jul 2013
    Location
    Malaysia
    Posts
    4
    Rep Power
    0

    Default Re: Button To Display Image And Text

    Quote Originally Posted by DarrylBurke View Post
    Read the API for JButton and follow the link to the Oracle tutorial on the subject.

    Also go through the section of the same tutorial titled How to Use Icons.

    db

    owh.. Thank's moderator..

    btw, can you share link 'tutorial How to Use Icons, i not found..
    Last edited by muhammad naim; 07-30-2013 at 11:32 AM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,123
    Rep Power
    20

    Default Re: Button To Display Image And Text

    The API for JButton has a link to the tutorial for how to use buttons.
    That has the list of Swing topics, one of which is to do with icons.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,165
    Rep Power
    6

    Default Re: Button To Display Image And Text

    To get to the API doc, google:

    java 7 JButton

    As an exercise I am not going to post the direct link to the actual documentation, just do the above and see for yourself how quick and easy it is to find information.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    muhammad naim is offline Member
    Join Date
    Jul 2013
    Location
    Malaysia
    Posts
    4
    Rep Power
    0

    Default Re: Button To Display Image And Text

    can help me,i don't to put coding image. see my coding


    Java Code:
    package buttonimage;
    
    /**
     *
     * @author mycom
     */
    import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.ImageIcon;
    
    public class MainFramei extends JFrame implements ActionListener {
        JPanel headerPanel;
        JPanel bodyPanel;
        JPanel panel1, panel2, panel3;
        JButton Image1, Image2, Image3;
        Container con;
        CardLayout clayout;
    public MainFramei() {
     //con=getContentPane();
            clayout = new CardLayout();
            headerPanel = new JPanel();
            bodyPanel = new JPanel(clayout);
    
            Image1 = new JButton("Button1");
            Image2 = new JButton("Button2");
            Image3= new JButton("Button3");
    
    //add three buttons to headerPanel
            headerPanel.add(Image1);
            headerPanel.add(Image2);
            headerPanel.add(Image3);
    
           Image1.addActionListener(this);
           Image2.addActionListener(this);
           Image3.addActionListener(this);
    
    panel1 = new JPanel();
            panel1.add(new JLabel("Stop"));
            panel1.setBackground(Color.WHITE);
            
            panel2 = new JPanel();
            panel2.add(new JLabel("Go"));
            panel2.setBackground(Color.WHITE);
            panel3 = new JPanel();
            panel3.add(new JLabel("Hello"));
            panel3.setBackground(Color.WHITE);
    
    //add above three panels to bodyPanel
            bodyPanel.add(panel1, "one");
            bodyPanel.add(panel2, "two");
            bodyPanel.add(panel3, "three");
    
            setTitle("Select Picture");
            setLayout(new BorderLayout());
            setSize(400, 250);
            add(headerPanel, BorderLayout.SOUTH);
            add(bodyPanel, BorderLayout.CENTER);
    //  headerPanel.setBounds(0,0,600,100);
            bodyPanel.setBounds(0, 100, 600, 500);
            setVisible(true);
    
    }
        public static void main(String args[]) {
            new MainFramei();
        }
    public void actionPerformed(ActionEvent e) {
    
    if (e.getSource() == Image1) {
                clayout.show(bodyPanel, "one");
            } else if (e.getSource() == Image2) {
                clayout.show(bodyPanel, "two");
            } else if (e.getSource() == Image3) {
                clayout.show(bodyPanel, "three");
            }
        }
    }
    somebody can help, i blur to typing coding.. huhu

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Button To Display Image And Text

    You've been given links to tutorials. Go through them. While you're there, also go through the section on Concurrency in Swing and learn how to invoke Swing constructors and methods in the EDT.

    Also, learn to respect the coding conventions; variable names should start with a lowercase letter.
    Code Conventions for the Java Programming Language: Contents

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Image display for individual radio button
    By akahafe in forum Advanced Java
    Replies: 2
    Last Post: 12-13-2011, 06:55 PM
  2. Replies: 1
    Last Post: 12-01-2010, 07:35 PM
  3. Replies: 1
    Last Post: 05-31-2010, 09:46 AM
  4. problem aligning both image/text inside a button
    By rick_cols in forum SWT / JFace
    Replies: 0
    Last Post: 09-18-2008, 09:20 PM
  5. How to display scrolling text and image on a JFrame
    By Abhi_vk in forum AWT / Swing
    Replies: 1
    Last Post: 06-20-2008, 11:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •