How at add closd function in the JButton??

Hi, sir:
I hope to add a closd function in the JButton, ie, like a JPanel or JFrame, there is a "X" sign icon on the right upper coner, when we click this X sign,
whole window or JPanel or JFrame will be closed, here I hope to add a "x" sign in JButton, when I click it, itthis button b2 will be vanished.
I update following code, but looks like not work, I hope Text and its icon on the leading Left, but closed sign is on the extreme end of right.
Can guru help??
Thanks
import javax.swing.AbstractButton;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import javax.swing.GroupLayout.Alignment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
* ButtonDemo.java requires the following files:
*   images/right.gif
*   images/middle.gif
*   images/left.gif
public class ButtonDemo2 extends JPanel  implements ActionListener {
    protected JButton  b2,bclosed;
    public ButtonDemo2() {
         Icon closedIcon  = new ImageIcon("images/ActionButton/closed.PNG");
        ImageIcon middleButtonIcon = new ImageIcon("images/little.gif");
        JLabel label1 = new JLabel("Image and Text", middleButtonIcon, JLabel.CENTER);
        bclosed = new JButton(closedIcon);
        bclosed.setBorder(null);
        bclosed.setToolTipText("closed");
        b2 = new JButton("Middle button", middleButtonIcon);
        b2.setText("Middle button");
        b2.setVerticalTextPosition(AbstractButton.BOTTOM);
        b2.add(bclosed, -1);
        b2.setIcon(middleButtonIcon);
        b2.setHorizontalTextPosition(AbstractButton.LEFT);
        b2.setAlignmentX(LEFT_ALIGNMENT);
        b2.setMnemonic(KeyEvent.VK_M);
          b2.setToolTipText("This middle button does nothing when you click it.");
        //Add Components to this container, using the default FlowLayout.
        add(label1);
        add(b2);
    public void actionPerformed(ActionEvent e) {
        if ("disable".equals(e.getActionCommand())) {
            b2.setEnabled(false);
        } else {
            b2.setEnabled(true);
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("ButtonDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        ButtonDemo2 newContentPane = new ButtonDemo2();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
}

Thanks, I add as follows:
package a.border;
import javax.swing.AbstractButton;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import javax.swing.GroupLayout.Alignment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
* ButtonDemo.java requires the following files:
*   images/right.gif
*   images/middle.gif
*   images/left.gif
public class ButtonDemo2 extends JPanel  implements ActionListener {
    protected JButton  b2,bclosed;
    public ButtonDemo2() {
         Icon closedIcon  = new ImageIcon("images/ActionButton/closed.PNG");
        ImageIcon middleButtonIcon = new ImageIcon("images/little.gif");
        JLabel label1 = new JLabel("Image and Text", middleButtonIcon, JLabel.CENTER);
        bclosed = new JButton(closedIcon);
        bclosed.setBorder(null);
        bclosed.setToolTipText("closed");
        bclosed.setActionCommand("closed");
        b2 = new JButton("Middle button", middleButtonIcon);
        b2.setText("Middle button");
        b2.setVerticalTextPosition(AbstractButton.BOTTOM);
        b2.add(bclosed, -1);
        b2.setIcon(middleButtonIcon);
        b2.setHorizontalTextPosition(AbstractButton.LEFT);
        b2.setAlignmentX(LEFT_ALIGNMENT);
        b2.setMnemonic(KeyEvent.VK_M);
        bclosed.addActionListener(this);
        b2.setToolTipText("This middle button does nothing when you click it.");
        //Add Components to this container, using the default FlowLayout.
        add(label1);
        add(b2);
    public void actionPerformed(ActionEvent e) {
        if ("disable".equals(e.getActionCommand())) {
            b2.setEnabled(!b2.isEnabled());
        if             ("closed".equals(e.getActionCommand())) {
              System.out.println("OK closed is pressed");
              remove(b2);
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("ButtonDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        ButtonDemo2 newContentPane = new ButtonDemo2();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
}But I cannot see the First Image I add in b2 such as little.gif and "Image and Text" on it, only I can see bclosed icon.
what is wrong here??
Thanks a lot
Good weekend

Similar Messages

  • How to add scroll function in  the applet launched by  Java Web Start?

    I have Java Web Start installed in order for the applet to launch.The applet size: width:700 height:1000
    my compuer resolution:800*600
    the applet launched by Java Web Start can only be seen partly,especially height.How to add scroll function in the applet launched by Java Web Start?
    Thanks for help.
    email:[email protected]

    You can very easily add a JScrollPane manually between the Applet and your content. Perhaps it would be beter if javaws did this automatically. In the browser, an applet can be any size. In Java Web Start an applet is directly contained within a JFrame, so it cannot be smaller than the minimum size of a JFrame, or Larger than the max.

  • How to Add Partner function in the main screen of the Sales order???????

    Hello All,
    I am working on ECC 6.00 SD module
    I want to add partner function in the main screen of the sales order, that mean add more partner function beside Sold to party and the ship to party to be in the order header, Is it possible and how?
    Regards
    Jacopo Françoise

    Hi
    If you want in the sales order , above the sold to party as the  box then you need to go for enhancements
    Regards
    Srinath
    Edited by: sri nath on Jun 11, 2008 6:56 PM

  • How do I get an Apple License to add Mac functions to the keyboard my company manufactures?

    I'm writing to inquire about the process for obtaining a VID license to add mac functions to the keyboard my company manufactures. I've called serveral numbers (Apple Support, Apple Software Licensing, Apple Legal, Apple Corporate, Apple Developers, etc as well as emailed all these departments and more) with no response or instructions on how to move forward. Is what we're hoping for even possible???
    The mac functions we want to add to our keyboard are: the ability to touch one key to open the dashboard, same for the expose feature- rather than needing to press two keys- fn plus the F1-F12 key needed (this is a mac function that can be set up in the control panel on any mac). We would like our keyboards to be work in this manner, just as a mac keyboard would.
    We do not need to use the Dashboard or expose keycap images (I already know there are no current licenses for those), just the functions.
    Does anyone know the process for obtaining this sort of license? The cost? Any information would be helpful. I've been put on hold for over two hours, on several occassions, lead to empty voicemail systems that lead to no-one, and written over a dozen emails with only automated responses- none of which applicable to our question.
    I just want to know if this is possible ! Please help!
    Thank you in advanced.

    "...you don't have to press two keys to do any of that on a Mac keyboard." That is our goal, we are not a mac keyboard, but manufacture PC and Mac compatible keyboards.... since we are not an apple product, to utilize those hot and media keys we've had to press fn first...
    we want our next keyboard release to do as mac keyboards do and by that only press one button for those functions. We are advised to first recieve apple permissions to manufacture a keyboard like this.
    Also, I have been all over the site linked above, I've emailed and called these guys several times (from the link):
    Apple Inc.
    Software Licensing Dept
    12545 Riata Vista Circle
    MS:198-3SWL
    Austin, TX 78727
    (also their phone is 512.674.2645)
    No one there has been able to answer my question, or be able to offer any help regarding this type of license (contrary to the department name).
    Thanks for responding, but unfortunately it doesn't really help us answer our question.

  • How can i add a function to the Home button?

    I'm developing an app and in order to make it work, i need to add a function to the Home button when the user is in a specific screen.

    I would not say "impossible", but certainly not an app that would ever be available via the iTunes App Store.

  • CRM  IC Winclient - How to add new fields in the BP Search of TRX CIC0

    Hello Experts,
    I want to know how to add new fields in the BP Search of TRX CIC0. In the HTML that we're using here I need to add the URL of the BP.
    Can you help me?
    Thanks in advance.
    Caíque Escaler

    Hi
    make append to tables in se11 - CCMBP1FIELDS, CCMBP2FIELDS
    in spro in Define customer-specific search control -> mark fields with X.
    and enhance html template CRM_CIC_SEARCH_DISPLAY. -> tcode smw0, look for package CRM_CIC_COMPONENTS for html CRM_CIC_SEARCH_DISPLAY. export it from SAP, edit, and import.
    you will need to enhance function module used for searching - you will find him in spro in Search Strategies.
    Regards
    Radek

  • How to add new fields to the DME file in F110

    Hi,
    We have a requirement add new fields to the file that is used in  F110.
    .I did go in to DMEE transaction but I hae no idea how to add new fileds to the existing file.
    Can anybody please help me in resolving the issue.
    Thanks
    Venkat
    Edited by: Venkat R on Jun 8, 2009 8:45 AM

    Hi,
    There is no function module for that, We have created our own function module and attached to that field.
    Refer the below code. This will fetch the document number.
    DATA: lwa_item   TYPE dmee_paym_if_type,
            l_fpayp   TYPE fpayp,
            l_fpayhx TYPE fpayhx,
            first_flag TYPE c,
            lv_lifnr   TYPE lifnr,
            voucher_id TYPE string,
            voucher TYPE string,
            invoice_id TYPE belnr_d,
            voucher_len1 TYPE i,
            voucher_len TYPE i.
      TYPES:
      BEGIN OF lt_regup,
            xblnr TYPE xblnr1,
            belnr TYPE belnr_d,
      END OF lt_regup.
      DATA: lt_regup TYPE STANDARD TABLE OF regup,
            lv_regup TYPE regup.
    Hope this helps.
    Raja.A
    Edited by: Raja.A on Feb 16, 2011 7:17 PM

  • How to add F4 help for the custom field of a custom table

    Hi All,
    How to add F4 help to the custom table field? in the table maintainance when user clicks on F4 i want to provide possible values for this field I am trying to write the code in the screen of table maintainace like the following
    PROCESS ON VALUE-REQUEST.
      FIELD ZTEST_MAH_F4-KUNNR MODULE zVALUE_kunnr .
    But when i am double clicking on module it's giving options to create include program but after that it's giving user is currently editing the table i am not getting this can some body clarify my doubt it's gr8 if some body give some examp code
    Thanks&Regards
    mahesh

    Hi,
    Create a subroutine under the event and call the following FM
    1. Select all the related data into an itab, for ex i_kunnr
    2.    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
          EXPORTING
        DDIC_STRUCTURE         = ' '
           retfield               = 'KUNNR'
        PVALKEY                = ' '
           dynpprog               = sy-repid
           dynpnr                 = '1000'
           dynprofield            = <selection screen field>
        STEPL                  = 0
        WINDOW_TITLE           =
        VALUE                  = ' '
           value_org              = 'S'
        MULTIPLE_CHOICE        = ' '
        DISPLAY                = ' '
        CALLBACK_PROGRAM       = ' '
        CALLBACK_FORM          = ' '
        MARK_TAB               =
      IMPORTING
        USER_RESET             =
          TABLES
           value_tab              = <b>i_kunnr</b>
        FIELD_TAB              =
           return_tab             = < return table >
        DYNPFLD_MAPPING        =
         EXCEPTIONS
           parameter_error        = 1
           no_values_found        = 2
           OTHERS                 = 3

  • How to add a page in the SAP Scripts

    Hi All,
    I want to know how to add a page in the sap scripts. there is already sap script developed by some other person.
    Now I have to add a page in front of that and have to add some more data.I added a page in page windows but thats not at all working.
    Please help me out in this.
    Thanks,
    Praveen

    new page will create in sap scripts using new page command.
    you have to set condition like after some number of records displayed in page new page has to be trigger.
    ex:YOU HAVE SO MANY RECORDS FOR PRINTING BUT YOU WANT TO DISPLAY 100 RECORDS IN FIRST PAGE REMAINING IN SECOND PAGE LIKE THAT.
    Here you can use NEW PAGE COMMAND .
    IT IS OPPOSITE PURPOSE OF PROTECT AND ENDPOTECT.
    Reward if useful.

  • How to add log messages in the sever/webui objects?

    Hi,
    I am new to the OA Framework.
    Can any one share any information in how to add log messages in the sever/webui objects?
    What are the beans I need to use to show in the diagnostic page?
    Can I get sample code for this log staments?
    Thanks in advance,
    Padma

    Hello. This forum is for reporting problems with the published Oracle documentation. You have a better change of getting a reply if you post your question on the Database - General forum.
    Regards,
    Diana

  • How to add an item into the Newsstand

    How to add an item into the Newsstand.  Please do NOT reply using  "tech-language." Use standard- normal everyday English. Thanks,
    Don Otlin
    Franklin Square, NY

    Open Newsstand. Tap on the "Store" button in the upper right. Any newspaper or magazine you download from the store will appear in Newsstand.

  • How to add new fields to the system form (Ex.expenses to a/r invoice form)

    hi
    can any one tell me how to add new fields to the system form (Ex.expenses to a/r invoice form)
    i want to add expenses field to system a/r invoice form and connect data base also.
    i used the code of samples\11.system form manipulation(vb.net) but i'm not able to get it....so can any one help with code or concepts.
    reply soon plz..
    thankQ

    If I understood you correctly, you are just trying to add new fields to the invoice form and then use them in your form. you should first go and add the field to your tables, which you would do by going to Tool --> User Defined Fields --> Manage User Fields. There are different documents or categories given. For ex. for invoices, Sales Orders you would add your field under the Marketing Documents. If you want the field to be just one per invoice, add it to the Title, otherwise if you want a field per invoice or Sales Order line, add it to the Rows section. Once you have done that then you can just create a edit box or drop down to represent the field and set the datasource for that to your field. If you want example code to do that, let me know.

  • How to add new fields in the EBP front end..

    Hi All,
    Can any one let me know the process of how to add new fileds in the shopping cart creation screens by using the "Tag Browser" option in the Object navigator.
    Best Regards,
    Mahesh. J

    Hi
    <b>Please go through the following links for more details and examples -></b>
    http://help.sap.com/saphelp_47x200/helpdata/en/a2/8c6eeb2d8911d596a000a0c94260a5/frameset.htm
    http://help.sap.com/saphelp_47x200/helpdata/en/d3/5ecbe22a8a11d5991f00508b6b8b11/frameset.htm
    This will definitely help.
    <u>For adding customer fields to the Shopping cart, you need to refer SAP OSS Bote 672960 and 485891.</u>
    Do let me know, incase you need any other details.
    Regards
    - Atul

  • How to use SQL functions in the queries

    hey guys i wanna know how to use SQL functions in the queries is it possible or not .

    Hi,
    Wat exactly that set values are?
    those from sql query?
    How to use count():
    The COUNT() function returns the number of rows that matches a specified criteria.
    SQL COUNT(column_name) Syntax
    The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:
    SELECT COUNT(column_name) FROM table_name
    SQL COUNT(*) Syntax
    The COUNT(*) function returns the number of records in a table:
    SELECT COUNT(*) FROM table_name
    SQL COUNT(DISTINCT column_name) Syntax
    The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:
    SELECT COUNT(DISTINCT column_name) FROM table_name
    The IN function helps reduce the need to use multiple OR conditions.
    The syntax for the IN function is:
    SELECT columns
    FROM tables
    WHERE column1 in (value1, value2, .... value_n);

  • How to Add multiple entry to the group policy security filtering

    How to Add multiple entry to the group policy security filtering
    Is there any way we can add multiple entry to the Domain group policy Security filtering tab.Currently its not allowing to add more then one entry at a time.
    Getting Error like "only one name can be entered,and the name cannot contain a semicolon.Enter a valid name"

    Hi
    Are you trying to add more users or groups through Group Policy Management Security Filtering tab?
    Try right clicking on the policy and then edit
    Then in Editor Right click on the name of the policy and Properties
    Security tab and add user or group from this tab. Just make sure if you are adding user or groups "Select this object type" has
    the correct option also "From this Location" is set to your entire directory not the local server.
    Update us with the above.
    Thanks

Maybe you are looking for