How to switch two buttons at same place?

Hi everyone,
I'm changing the GUI of my project. The following is a test program. It want to switch jButton2 and jButton3 at same place when you click jButton1. But it cannot display jButton3. What's problem? Who can help me?
Thank you very much.
CODE ----------------------------------------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JFrame {
JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
BorderLayout borderLayout1 = new BorderLayout();
JButton jButton3 = new JButton();
public Test() {
try {
jbInit();
catch(Exception e) {
e.printStackTrace();
private void jbInit() throws Exception {
jButton1.setText("jButton1");
jButton1.addActionListener(new Test_jButton1_actionAdapter(this));
jButton2.setText("jButton2");
jPanel1.setLayout(borderLayout1);
jButton3.setText("jButton3");
jPanel1.add(jButton1, BorderLayout.NORTH);
jPanel1.add(jButton3, BorderLayout.CENTER);
jPanel1.add(jButton2, BorderLayout.CENTER);
getContentPane().add(jPanel1);
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
public static void main(String[] args)
Test t = new Test();
t.setSize(100,100);
t.show();
void jButton1_actionPerformed(ActionEvent e) {
if (jButton2.isVisible())
jButton2.setVisible(false);
jButton3.setVisible(true);
else
jButton3.setVisible(false);
jButton2.setVisible(true);
class Test_jButton1_actionAdapter implements java.awt.event.ActionListener {
Test adaptee;
Test_jButton1_actionAdapter(Test adaptee) {
this.adaptee = adaptee;
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}

Try this:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JFrame {
JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
BorderLayout borderLayout1 = new BorderLayout();
public Test() {
try {
jbInit();
catch(Exception e) {
e.printStackTrace();
private void jbInit() throws Exception {
jButton1.setText("jButton1");
jButton1.addActionListener(new Test_jButton1_actionAdapter(this));
jButton2.setText("jButton2");
jPanel1.setLayout(borderLayout1);
jPanel1.add(jButton1, BorderLayout.NORTH);
jPanel1.add(jButton2, BorderLayout.CENTER);
getContentPane().add(jPanel1);
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
public static void main(String[] args)
Test t = new Test();
t.setSize(100,100);
t.show();
void jButton1_actionPerformed(ActionEvent e) {
if (jButton2.getText().equals("jButton2")) jButton2.setText("jButton3"); else jButton2.setText("jButton2");
class Test_jButton1_actionAdapter implements java.awt.event.ActionListener {
Test adaptee;
Test_jButton1_actionAdapter(Test adaptee) {
this.adaptee = adaptee;
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
The idea is to change the appearance of a single button instead of dealing with two separate buttons. If you want the second button to perform different task, you can use the getText() method and check to see whether is says jButton2 or jButton3.
;o)
V.V.
PS: If this helps, don't for get the Dukes.

Similar Messages

  • How to display two grids in same screen using SALV Method

    Hi Freinds,
    Please let me know how to display two grids in same screen using SALV Method.
    Thank you
    Regards,
    SDV

    Using the same concept as described in How to dispaly Three Internal Table  Data (One below another) in ALV OOPS .
    All you need to add is passing your new containers as r_container parementer of factory method.
    "1st one
          cl_salv_table=>factory(
             EXPORTING
               R_CONTAINER    = g_top_container
    "2nd one
          cl_salv_table=>factory(
             EXPORTING
               R_CONTAINER    = g_bottom_container
    Regards
    Marcin

  • How to separate two contact with same name

    Hi, anyone knows how to separate two contacts with same name in Contacts?  Actually they are two persons from two gmail contacts with same name but different contact numbers, different emails....etc, but Contacts assume they are same person and merge them as one!

    FG,
    In Lion, you have the File > Duplicate option. You will then have two copies of your document open, and the one on top will have the temporary filename "OriginalFileName copy", and your next responsibility is to File > Save (or Command-S) and rename the duplicate. At this point, you edit the copy's name, to perhaps ...copy 1, or whatever you wish. The document you had open when you initiated the File > Duplicate will still be there on your screen, waiting for you to Close it or continue editing.
    Jerry

  • Two buttons in same jsp page

    hello to java people
    My ? is, jsp page named as login.jsp, In this page i want to use two buttons.
    If i click on one buton it will goto sucess.jsp and for another button it will go to find.jsp.
    i.e, two actions in same page, is it possible ?
    help me by giving sample code.
    thanks

    thanks balu for ur answer.
    pure java ?
    But my doubt is see we take one form
    <form action="sucess.jsp">
    <input text...>
    <input text...>
    <input type=submit name=sucess>
    <input type=submit name=find>
    </form>
    means whether i take two buttons as submit and names r diff..
    but at top only one action is there .
    how can they know to which page it has to go?
    do u understand my ?
    can u please give some sample code so that i can understand
    thanks

  • Problem in Adding two buttons under same column header (in JTable)

    Hi,
    I have a JTable and to a particular column i want to add two buttons.
    Here the two buttons should be under the same column header and i need to add listners to these.
    Any idea how to do this?
    Thanks & regards
    Neel

    Of course as your header is drawn by a renderer, the buttons don't actually work, but you can listen for mouse clicks within the area of the header and see which button the mouse position was over.
    See the Java Table Sorter Demo code for how to add a mouse listener to the header...
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/index.html#TableSorterDemo
    ....and from there you should be able to determine where in the component the click occured by using the getX() and getY() methods of the MouseEvent to determine which button in the renderer component was clicked. Use something like Rectangle.contains() to match the click location against the buttons.

  • I have a white screen on my ipod.  i have tried pushing the two buttons at same time but it doesn't work. i tried restoring on itunes but can't because of the password on ipod

    My ipod 4th gen. has a white screen.  i have tried pushing the two buttons but it didn't work.    I have tried to restore on i tunes but because there is a pass code on the ipot, it won't let me.  Any ideas?

    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    If recovery mode does not work try DFU mode.                        
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings        
    For how to restore:
    iTunes: Restoring iOS software

  • How to write two triggers on same table how it works?

    Hello sir..
    I have to write two triggers on same table for auditing different columns of different pages (may be different modules).
    I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_ val,timestamp)
    Now different users from different pages will update the data on same table may be same columns!
    If we write directly, we will not be able to know which column is updated from different pages.
    My question is how can we control the triggers to raise based on the pages

    A trigger is executed whenever the table is inserted / updated / deleted (depend on trigger definition). It won't know what 'page' caused the operation. You can prepare a trigger for one page.
    In order to fulfill your need, you need some way to tell the trigger where you are. There are many ways to accomplish this. Some possible methods are (please check the documents for detail)
    DBMS_SESSION.SET_IDENTIFIER
    DBMS_APPLICATION_INFO.SET_MODULEFor example, you can call DBMS_SESSION.SET_IDENTIFIER to set an ID from your page, and then call sys_context to read the ID back:
    In Page:
    exec dbms_session.set_identifier('Page1');
    ...In Trigger
    pageid  := sys_context('USERENV', 'CLIENT_IDENTIFIER') ;
    ...Note that if you use a connection pool, you may need to properly reset the session information before return, in order to avoid messing up the session information when the connection is used next time.

  • How to give two values of same field in read Statment

    Hi,
    Please Tell me how to give the two values of same field in read statements Condition.
    i.e
      Read table it_tab with key matnr = '1' or matnr = '2'.
    With Regards
    Kesavaperumal

    Hi Kesavaperumal,
    <li>You can not use OR operator with READ TABLE statement.
    <li>You have to use different fields of the internal table in where condition.
    <li>If you want to compare with two values, you need to use LOOP statement.
    LOOP AT it_mara WHERE matnr = '1' or matnr = '2'.
    "Write code
    ENDLOOP.
    Thanks
    Venkat.O

  • How to switch two Digital IO in a DAQmx as a output

    Hello, i need to switch two Digital IO in a DAQmx (Output in a PXI-6528).
    LabVIEW launch next error:
    Error -200014 occurred at DAQmx Create Channel (DO-Digital Output).vi
    Possible reason(s):
    Terminal cannot appear multiple times within a single digital input or output task.
    Physical Channel Name: port3/line0
    Virtual Channel Name: PXI1Slot3/port3/line0
    Task Name: MyDigitalOutTask

    Hi Andreu,
    the best way to analyze your question is to post a short example on the programming language that you´re using in order to investigate a little bit.
    Moreover, under NI Find Examples of LabVIEW (if you programm with LabVIEW), you can find several examples how you can programm your digital port about (you can type "Write" or "digital" under Search tab).
    One example would be: "Write Dig Chan-Int Clk-Dig Start.vi".
    Regards
    Diego M.

  • I can get the apple logo on the phone but nothing else. Have tried resetting by pressing the two buttons at same time but no response. Any ideas please?

    iphone only displays logo, nothing beyond this. any suggestions please other than two buttons pressed at same time? thanks, stu

    See Here for Device Unresponsive
    http://support.apple.com/kb/ts1445
    The Basic Troubleshooting Steps are:
    Restart..  Reset..  Restore from Backup..  Restore as New...
    Try this First... You will Not Lose Any Data...
    Turn the Phone Off... ( if it isn’t already )
    Press and Hold the Sleep/Wake Button and the Home Button at the Same Time...
    Wait for the Apple logo to Appear and then Disappear...
    Usually takes about 15 - 20 Seconds... (But can take Longer...)
    Release the Buttons...
    Turn the Phone On...
    If that does not help... See Here:
    Backing up, Updating and Restoring
    http://support.apple.com/kb/HT1414

  • How to merge two views of same criteria in Answers

    Hi All,
    Is there any way we can merge two views of same criteria in Answers.
    I have two pivot tables built from same criteria. But in the final report I want to show the two reports as a single report. Is this possible?
    Best Regards,
    BTK.

    Hi,
    I cannot use "Combine with Similar Request". I need drilldown also. When I use "Combine with Similar Request", then drill down is getting disabled.
    Best Regards,
    BTK.

  • How to use other keybord with Imac? what to do with "cmd" key and "microsoft windos logo button in same place on keyboard?

    ?

    Found!
    Thanks to newzealandnz here:
    https://discussions.apple.com/message/17977379#19776692
    Hold "fn" Press "3" and they standard keyword shows
    But actually for me it didn't work but I found another one:
    PRESS THE EJECT BUTTON! ⏏
    And the virtual keybord will appear, even if you have a Bluetooth Keyboard connected.

  • How to submit two forms at same time?

    Have a client that requires their members to update their profile information and some of the details from that form need to also populate a WebApp.
    I've seeded the CRM with basic (first name, last name, email address, Your ID, and EntityID) member data.
    Members would log in and be asked to update their profile. [action="/MemberProcess.aspx"]
    This submission should update their CRM record *AND* create a WepApp record at the same time.
    I tried the AJAX + jQuery method, including the second WebApp form [action="/CustomContentProcess.aspx?...] fields as type="hidden", and using {tag_FIELD NAME}; but this isn't working for me, I'm admittedly not a real programmer.
    Any thoughts? Thank you very much, in advance for any and all help!
    p.s. the reason for wanting to do this, is so that members do not have to update their CRM profile and then also input their data specific to the WebApp form (it's a member listing) as a separate task.
    p.p.s. after I get through the above hurdle... how can I ensure that a CRM user has one and only one WebApp item (their listing) and that they can edit it? Another issue I'm having now is that users create a new listing in the WebApp if they submit another record and in the future I fear that simply editing their CRM profile will create new WebApp listings too. This site is like a phone book, there should only be one listing for each unique email address (in this case).
    -Will

    You can use Jquery + AJAX to submit as many forms as you want to as many places as you want. Don't use the HTML to submit and have a second javascript submitter as the Javascript might not have time to complete before the page is submitted.
    I wrote this quickly just now, this wont work on the JSfiddle site because you can't form POST / GET anything on it (AJAX included it seems). it will submit to other URLs the same data. It is done in parallel and because we don't know which one will finish quicker, both calls check if all calls are complete before confirming everything is complete. I have not tested it but it would get you 99% of the way there.
    <form id="signup_register" action="" method="post">
        Firstname<br/><input type="text" name="firstname"><br/>
        Lastname<br/><input type="text" name="lastname"><br/>
        <button onclick="formsubmit(this);">Save</button>
    </form>
    <script>
        var url1='http://google.com';
        var url2='http://gmail.com';
        var complete1=false;
        var complete2=false;
        FinishedTwoFormSubmits=function(){
            alert('Finished submit - redirect or whatever you need to do.');   
        formsubmit=function(el){
            var data = $('form#signup_register').serializeArray();
            PostSubmit(url1,data, function(){ complete1=true; if (complete1 && complete2){ FinishedTwoFormSubmits() } });
            PostSubmit(url2,data, function(){ complete2=true; if (complete1 && complete2){ FinishedTwoFormSubmits() } });
        PostSubmit=function(url,data,cb){
              var ret=false;
            var noerror=false;
                        $.ajax({
                                    type: 'POST',
                                    url: url,
                                    cache: false,
                                    data: data
                                  }).done(function(msg) {
                                            try{ noerror=true; }
                                            catch(e){ alert(e+'\n\n'+msg); }
                                            if (noerror){ cb() }
                        return ret;
    </script>

  • How to sync two ipods on same pc

    My husband and I both have an iPod Touch. We are using the same computer, and set up separate email accounts on each touch. However, when syncing both of our contact lists sync on both iPods. We are both using a Yahoo email acct. If I delete his contacts online via my Yahoo acct, then it syncs back when I plug in the iPod. I've tried unchecking the sync contacts button on iTunes but it didn't help.
    I cannot modify, add or delete any contacts because they just go back when syncing. Please help because this is very annoying and frustrating.

    This info discusses setting up the music. Will creating a new user account resolve the syncing of contacts problem?
    How can I be certain that if I delete his contacts in my Yahoo acct, it won't then delete them in his Yahoo acct?

  • How to install two iTunes on same PC for two iPods?

    My family now proudly owns 2 iPods, but we only one PC. So it needs to host two iPods, with their resepctive iTunes on it.
    I thought this was going to cause problems, and worried that installing iTunes for the most recently purchased iPod would overwrite the existing programme, wipe the music off it and cause my middle daughter to kill me. The guy in the shop said, no problem - create a new User Account and install the new iTunes on that, and it would be OK. So I did.
    I got a bit worried when the install prog wanted me to put the new iTunes into the same folder that the old one was in, (even though I was logged in as a different, new user) so I found a new location for it and went ahead.
    Guess what - it wiped the old iTunes anyway. When I opened up the old one, it had been overwritten anyhow.
    I did a system restore to try and get it back to the previous setting - deleting the new user I had created. And went back into the old version of iTunes to see if the music files had come back. But it wouldn't even run - saying that some files were now missing.
    This is doing my head in, it's happened before (and I had to buy Copypod to restore the stuff on my iPod).
    How can you get two copies of iTunes on the same PC running two separate iPods?!! And how can I get the overwritten files back?
    Various   Windows XP Pro  
    Various   Windows XP Pro  
    Various   Windows XP Pro  

    You don't need two copies of iTunes. There are a couple of methods for using more than one iPod on a single computer. Have a look at the article linked below. Method one is to have two Mac or Windows user accounts which by definition would give you two completely separate libraries as each account using iTunes will have it's own iTunes Music Folder. Method two is to set your preferences so each iPod is updated with only certain playlists within one library. Have a look anyway and see what you think and go for whichever you feel suits your needs best: How To Use Multiple iPods with One Computer

Maybe you are looking for

  • Iphone in recovery mode, and it disconnects every time I try to restore. HELP!!

    I tried to update my Iphone with the latest software update, but it crashed during the update and was stuck for hours without getting any further along in the process, so i disconected it. My phone is now in recovery mode. When i tried to restore it

  • I wanted to connect my pc screen to my mac book pro.

    I wanted to connect my pc screen to my mac book pro. so i brougth a dvi adapter. when i put the cabels in it was working, but every time i put the cables into the mac book pro my internett connection shuts down . why? pleas answer....

  • Is it possible to assign fixed internal IP address for Azure VM ?

    I setup win2008R2 Application server on Azure VM and setup Azure VPN for local address 10.0.0.0/24 and  VNET? for 10.0.1.0/24 and default gateway 10.0.1.0/25 though I do not get exact meaning of this  network settings. By default VM OS IP setting, it

  • IPhoto events missing after opening on Maverick

    I have an iPhoto library on an external drive.  When opening the library using Lion OS iPhoto '08 v 7.1.5 (378), I can see all the events.  But if I open the library using Maverick iPhoto v9.5.1 (902.17), I only see a few events and those events only

  • Animation problems in Adobe Flash CS3 for windows.

    I'm trying to save some .gif animations, but when I save them, they don't show the movie symbols animating, just the tweens in the main scene. Can someone help? I'll post an example. In 7-21-09 2 it is supposed to flailing it's arms around while movi