Button Event Handler in a JList, Please help.

Hi everyone,
I have created a small Java application which has a JList. The JList uses a custom cell renderer I named SmartCellRenderer. The SmartCellRenderer extends JPanel and implements the ListCellRenderer. I have added two buttons on the right side inside the JPanel of the SmartCellRenderer, since I want to buttons for each list item, and I have added mouse/action listeners for both buttons. However, they don't respond. It seems that the JList property overcomes the buttons underneath it. So the buttons never really get clicked because before that happens the JList item is being selected beforehand. I've tried everything. I've put listeners in the Main class, called Editor, which has the JList and also have listeners in the SmartCellRenderer itself and none of them get invoked.
I also tried a manual solution. Every time the event handler for the JList was invoked (this is the handler for the JList itself and not the buttons), I sent the mouse event object to the SmartCellRenderer to manually check if the point the click happened was on one of the buttons in order to handle it.
I used:
// Inside SmartCellRenderer.java
// e is the mouse event object being passed from the Editor whenever
// a JList item is selected or clicked on
Component comp = this.getComponent (e.getX(), e.getY())
if(!(comp instanceof JButton)) {
          System.out.println("Recoqnized Event, but not a button click...");
          //return;
} else {
          System.out.println("Recognized Event, IT IS A MOUSE CLICK, PROCESSING...");
          System.out.println("VALUE: "+comp.toString());
What I realized is that not only this still doesn't work (it never realizes the component as a JButton) it also throws an exception for the last line saying comp is null. Meaning with the passed x,y position the getComponent() returns a null which happens when the coordinates passed to it are outside the range of the Panel. Which is a whole other problem?
I have yet to find an example on the web, using Google, that demonstrated using buttons inside a JList.
Can anyone help me with this. Thanks.

A renderer is not a component, so you can't click on it. A renderer is just used to paint a representation of a component at a certain position in your JList.
I have yet to find an example on the web, using Google, that demonstrated using buttons inside a JList.Thats probably because this is not a common design. The following two designs are more common:
a) Create a separate panel for your JButtons. Then when you click on the button it would act on each selected row in the JList
b) Or maybe like windows explorer. Select the items in the list and then use a JPopupMenu to perform the desired functionality.
I've never tried to add a clickable button to a panel, but this [url http://forum.java.sun.com/thread.jspa?threadID=573721]posting shows one way to add a clickable JButton as a column in a JTable. You might be able to use some of the concepts to add 2 button to the JPanel or maybe you could use a JTable with 3 columns, one for your data and the last two for your buttons.

Similar Messages

  • How to get a form field valud in delete PL/SQL Button Event Handler

    Hi Friend,
    I have a form. when user clicks delete button. we want to remove system dodelete function
    and add a delete script
    Under delete-top category,
    how can I get value of form EVENT_NUMBER field in form at delete PL/SQL Button Event Handler?
    DELETE FROM PTEAPP.PTE_EVENTS WHERE eventnumber = EVENT_number
    But when I try to save this form and get message as
    1721/15 PLS-00201: identifier 'EVENT_NUMBER' must be declared
    Thanks for any help!
    newuser

    I did something similar but wasn't using a stored procedure. Couldn't you set a flag variable once you know you're not doing the insert and in the "before displaying the form" section put an IF to check if your flag was set, and if so do an HTP.Print('You are overpaid buddy!');
    Then just reset your flag.

  • How to add a custom PL/SQL code for a button event handler

    Hi All,
    I am a toddler in using Oracle Portal. So please forgive me for my ignorance.
    Q : How do I add a custom PL/SQL code for a button event handler?
    Basically, I would like to write MY PL/SQL function and call it. I could see that we can write "CUSTOM" code as "PL/SQL button event handler" in the form design window. But the question is that it expects only a "call" to procedure. But where do I define the procedure then? If I insert the procedure from the backend, it gets flushed the next time I compile my form.
    Hope I am able to explain my point.
    Thanks in advance,
    Abbas.

    Hi All,
    I am a toddler in using Oracle Portal. So please forgive me for my ignorance.
    Q : How do I add a custom PL/SQL code for a button event handler?
    Basically, I would like to write MY PL/SQL function and call it. I could see that we can write "CUSTOM" code as "PL/SQL button event handler" in the form design window. But the question is that it expects only a "call" to procedure. But where do I define the procedure then? If I insert the procedure from the backend, it gets flushed the next time I compile my form.
    Hope I am able to explain my point.
    Thanks in advance,
    Abbas.

  • How to show a message in a form 'PL/SQL Button Event Handler'

    We need validate the sal of an employee, and if it is bigger the value musts
    not be inserted.
    We trying a code like the one shown in the note 134312.1 'HOW TO PASS A
    PARAMETER FROM A PORTAL FORM TO A STORED PROCEDURE' and it works in the insert event of the insert button (using 'PL/SQL Button Event Handler') and it works, but we need to show a message that says the data wasn't inserted. How can we do this?
    The code we used is:
    declare
    v_deptno scott.emp.deptno%type;
    v_empno scott.emp.empno%type;
    v_sal scott.emp.sal%type;
    mySal scott.emp.sal%type;
    v_string varchar2(256);
    blk varchar2(10):='DEFAULT';
    begin
    select sal into mySal from scott.emp where empno=7369;
    v_deptno:=p_session.get_value_as_number(p_block_name=>blk,
    p_attribute_name=>'A_DEPTNO');
    v_empno:=p_session.get_value_as_number(p_block_name=>blk,
    p_attribute_name=>'A_EMPNO');
    v_sal:=p_session.get_value_as_number(p_block_name=>blk,
    p_attribute_name=>'A_SAL');
    v_string:='You just inserted empno: '||to_char(v_empno) ||'to deptno ->
    '||to_char(v_deptno);
    if mySal < v_sal then
    doInsert;
    else
    -- We want to display a message here, when mySal > v_sal
    end if;
    end;
    ----------------------------------

    I did something similar but wasn't using a stored procedure. Couldn't you set a flag variable once you know you're not doing the insert and in the "before displaying the form" section put an IF to check if your flag was set, and if so do an HTP.Print('You are overpaid buddy!');
    Then just reset your flag.

  • I tried updating my iPhone3g through itunes. Now i'm stuck in recovery mode and i've EVERYTHING even websites and such but nothing worked out! I've also tried restarting and fiddling with the home button but nothing still worked. Please help!

    I tried updating my iPhone3g through itunes. Now i'm stuck in recovery mode and i've EVERYTHING even websites and such but nothing worked out! I've also tried restarting and fiddling with the home button but nothing still worked. Please help! What should I do??

    Well, if you've indeed tried EVERYTHING, then you'll need to bring your phone to Apple for evaluation.

  • Custom Button Event Handler

    I'm working on a form that inserts data into my database. The normal Insert PL/SQL just does "doInsert". I want to add in the PL/SQL Button Event Handler a condition statement as follows:
    IF :new.name_id != null THEN
    doInsert;
    ELSE
    "do something else"
    END IF;
    "name_id" is one of the form items. I want to check the value in name_id before I insert it into the database. What is the correct verbage in order for this condition to work -- :new.name_id does not work.
    Thanks
    Susan

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Susan Miller ([email protected]):
    I'm working on a form that inserts data into my database. The normal Insert PL/SQL just does "doInsert". I want to add in the PL/SQL Button Event Handler a condition statement as follows:
    IF :new.name_id != null THEN
    doInsert;
    ELSE
    "do something else"
    END IF;
    "name_id" is one of the form items. I want to check the value in name_id before I insert it into the database. What is the correct verbage in order for this condition to work -- :new.name_id does not work.
    Thanks
    Susan<HR></BLOCKQUOTE>
    null

  • Htp.p doesn't work from the custom button event handler ...

    Hi,
    I am trying to pop up an alert from the custom button event handler. I created a button and put the following code.
    htp.p('<script language='JavaScript1.3">
    alert ("Test Message");
    </script>;
    But alter doesn't show up after clicking the button.
    Thanks

    OK i've attached them and copy/pasted the relevent parts. The parent window is the SFLB file.
    -----------------------------------------here's the code in the parent window
    private function editServerPool():
    void
    serverPoolPUW = PopUpManager.createPopUp(
    this,popups.ServerPoolPopup,true);PopUpManager.centerPopUp(serverPoolPUW
    as IFlexDisplayObject); 
    if (newServerPool.SecondarySPAlgorithm != null){
    serverPoolPUW.enableSSCheckBox.selected =true;serverPoolPUW.DisplaySecondaryServerPool();
    serverPoolPUW.bigResize.play();// serverPoolPUW.height = 602; //yes...i know i need to move thisserverPoolPUW.switchoverPolicyCB.selectedItem = newServerPool.SwitchOverPolicy;
    serverPoolPUW.switchoverThresholdTI.text = newServerPool.SwitchOverThreshold;
    ----------------------here's the code in teh popup window (popups.ServerPoolPopup.mxml)
    <mx:Resize id = "bigResize" heightFrom="506" heightTo="602" target="{this}" /> 
    <mx:Resize id = "littleResize" heightFrom="602" heightTo="506" target="{this}"/>
     public function DisplaySecondaryServerPool():void{
    //make the screen large if the secondary server checkbox is selected; otherwise small.  
    if (enableSSCheckBox.selected){
    //display secondary server pool tab, expand the screen 
    //note that we cannot attach a data provider to the data grid until the grid creation is  
    //completed. This is done in an event handler.secondaryPanel.enabled =
    true; switchoverPolicyCB.visible =
    true;switchoverThresholdTI.visible =
    true;thresholdFI.visible =
    true;policyFI.visible =
    true;bigResize.play();
    else
     <mx:CheckBox label="Enable a Secondary Server Pool" width="264" fontWeight="bold" click="DisplaySecondaryServerPool()" id="
    enableSSCheckBox" fontSize="12" x="83" y="40"/>

  • Execute procedure in pl/sql button event handler

    i have a demo application which consists of text boxes
    eg : when i enter department no in first text box and click proc
    it should display dname and loc in the below text boxes.
    my proc is working fine in sql*plus but its showing errors in pl/sql button event handler.
    any ideas
    my proc is create or replace procedure proc1 (no number)
    as
    DNAME1 dept.dname%type;
    LOC1 dept.loc%type;
    begin
    select DNAME,LOC into DNAME1,LOC1 from scott.dept where deptno = no;
    DBMS_OUTPUT.PUT_LINE (DNAME1);
    DBMS_OUTPUT.PUT_LINE (LOC1);
         Exception When No_Data_Found then
    dbms_output.put_line('Entred name is not found');
    When Others then
    Null;
    End;
    /

    Hi,
    you have to use
    htp.p('<SCRIPT LANGUAGE="Javascript1.1">
    document.all("FORMNAME.DEFAULT.ATTRIBUTENAME.01").value="'||DNAME1||'";
    document.all("FORMNAME.DEFAULT.ATTRIBUTENAME.01").value="'||LOC1||'";
    </SCRIPT>
    instead of
    DBMS_OUTPUT.PUT_LINE (DNAME1);
    DBMS_OUTPUT.PUT_LINE (LOC1);
    where formname is your form name and attribute name is the field name on the page.

  • TS3682 I started updating my iPhone 4, but it went black screan and then started turning on and off non stop. I tried to hold the two buttons, but nothing different happened. Please, help! What should I do?!

    I started updating my iPhone 4, but it went black screan and then started turning on and off non stop. I tried to hold the two buttons, but nothing different happened. Please, help! What should I do?!

    First see if placing the iPod in Recovery Mode will allow a restore.
    Next try DFU mode and restore.
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    If not successful then time for an appointment at the Genius Bar of an Apple store. You are not alone with this problem.

  • My iPad stop working suddenly i see black screen only pressing the home? and sleep button dose not solve the  problem please help?

    My iPad stop working suddenly i see black screen only pressing the home and sleep button dose not solve the problem please help ?

    Frozen or unresponsive iPad
    Resolve these most common issues:
        •    Display remains black or blank
        •    Touch screen not responding
        •    Application unexpectedly closes or freezes
    http://www.apple.com/support/ipad/assistant/ipad/
    iPad Frozen, not responding, how to fix
    http://appletoolbox.com/2012/07/ipad-frozen-not-responding-how-to-fix/
    iPad Frozen? How to Force Quit an App, Reset or Restart Your iPad
    http://ipadacademy.com/2010/11/ipad-frozen-how-to-force-quit-an-app-reset-or-res tart-your-ipad
    Black or Blank Screen on iPad or iPhone
    http://appletoolbox.com/2012/10/black-or-blank-screen-on-ipad-or-iphone/
    What to Do When Your iPad Won't Turn On
    http://ipad.about.com/od/iPad_Troubleshooting/ss/What-To-Do-When-Your-Ipad-Wo-No t-Turn-On.htm
    iOS: Not responding or does not turn on
    http://support.apple.com/kb/TS3281
    Home button not working or unresponsive, fix
    http://appletoolbox.com/2013/04/home-button-not-working-or-unresponsive-fix/
    Fixing an iPad Home Button
    http://tinyurl.com/om6rd6u
    iPad: Basic troubleshooting
    http://support.apple.com/kb/TS3274
     Cheers, Tom

  • I put a disc in my Imac and it doesn't recognize it, and i can't eject it. I tried to restart it and hold the mouse button, but that didn't work.Please help.

    I put a disc in my Imac and it doesn't recognize it, and i can't eject it. I tried to restart it and hold the mouse button, but that didn't work.Please help.

    Try restarting your iMac by holding down the eject button on your keyboard.  http://support.apple.com/kb/TS2097

  • 'Call' in PL/SQL button event handler

    I have created a form with only one 'Custom' button on it.
    In the PL/SQL button event handler, in 'Custom' event item, I
    inserted some PL/SQL code and, at the end, a call like the
    following:
    my_url:= 'PORTAL30.wwv_component_control.run_as_portlet?'
    || 'p_module_id=' || '2836550185';
    call(my_url,return_url);
    I have a compilation error:
    "PLS-00201: identifier 'CALL' must be declared"
    I also tried to put this code in 'On successful submission of a
    form'. I have no compilation error but it doesn't work.
    Anybody knows hw to solve this problem?
    Thanks.

    Hello Antonnella,
    I have a good tip for you:
    write the next scirp in the 'On successful submission of a
    form'field in the form where you want to call the component:
    declare
    l_url varchar2(2000);
    begin
    l_url := 'the url of the component you want to call' ;
    PORTAL30.wwa_app_module.set_target(l_url,'CALL');
    end;
    you can get the url from:
    develop -> call interface:show -> Example of Call from URL .
    Success,
    Haseeb

  • How to copy the text from textfield to jlist(please help me)..

    hi to all,i am making chat application , in my program user enters ip in the text field to connect to other computer.whenever user wants to send the message ,he has to enter ip in the text field , all i want to do is to copy the ip from text field to jlist , so user does'nt enter same ip every time , he can just select from the jlist . please help me in this ,can u tell me code for that , i would be thankful to u
    Thankyou
    Naresh

    You've asked a lot of questions the last few days. I think its time you do some reading. The Swing tutorial titled "Creating a GUI Using JFC/Swing: has sections on every component and example code of how to use them. You can even download the entire tutorial and all the example from the following link:
    http://java.sun.com/docs/books/tutorial/
    Here's the link specific link to the section on "Using Lists"
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

  • Command or Canvas Events for Recording ?? Please Help..

    Hi I am Abhijith I am a total newbie to the j2me world, And I am learning it now,
    My project topic is "Bluetooth Walkie Talkie " , And I am trying my best and putting
    all my efforts to code incrementally by learning , Before I could implement bluetooth,
    I thought let me complete the recording The audio and playing part first,
    The recording and playing of audio is working fine , But i would like to do it a real manner as Real Walkie talkie does, I want to record audio ONLY when the Key is being
    pressed , and when its released it should exit the player hence saving the recorded file,
    (Actually i dont want to save it in future,i would be sending the bytearray though the bluetooth , but for now , I want the Current module to be ready)
    I tried my best searching online to implement my requirement but the couldnot find
    such events I found Canva's KEYPRESS, KEYRELEASE , etc events but they dint not
    serve my purpose, Let me clearly tell where I am stuck , After the midlet starts(by launching it) then i would like to press a key( keypressed say No 5) for certain
    amount of time and the audio should be recorded only for the keypressed duration ,
    after I release , it should stop recording and save as a wav file .
    Whats happening is When i keep the key pressed , The midlet asks whether to allow
    the recording , for this purpose when I release key the control is going out, and
    i am not able to achieve the needed , I am posting the code here, Please Help me.
    I am not asking for the complete spoon feeding or ready made code, But as a beginner
    I need help from you all to learn and implement it.(at least it should satisfy me,i would feel i have learnt something then)
    Here below is my code ( i AM using WTK 2.5 )
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import java.io.*;
    import javax.microedition.media.control.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.io.file.*;
    public class Key extends MIDlet{
      private Display  display;
      private KeyCodeCanvas canvas;
      public Key(){
        display = Display.getDisplay(this);
        canvas  = new KeyCodeCanvas(this);
      protected void startApp(){
        display.setCurrent(canvas);
      protected void pauseApp(){}
      protected void destroyApp( boolean unconditional ){
        notifyDestroyed();
    class KeyCodeCanvas extends Canvas implements CommandListener{
      private Command exit;
         public StringItem message ;
         private Player player;
         private byte[] recordedAudioArray = null;
      private String keyValue = null;
      private Key midlet;
         Thread t = null;
         private String eventType = null;
      public KeyCodeCanvas(Key midlet){
        this.midlet = midlet;
        exit = new Command("Exit", Command.EXIT, 1);
        addCommand(exit);
        setCommandListener(this);
      protected void paint(Graphics g){
          g.setColor(255, 0, 0);
          g.fillRect(0, 0, getWidth(), getHeight());
        if (keyValue != null){
          g.setColor(0, 0, 255);
           g.drawString(keyValue + eventType+message, getWidth() / 2, getHeight() / 2,
         Graphics.TOP | Graphics.HCENTER);
      public void commandAction(Command c, Displayable d){
        String label = c.getLabel();
        if(label.equals("Exit"))
          midlet.destroyApp(true);
      protected void keyPressed(int keyCode){
         eventType = "pressed";
        keyValue = getKeyName(keyCode);
        repaint();
      public void keyReleased(int keyCode)
           try
                eventType = "released";
                keyValue = getKeyName(keyCode);
                repaint();
           catch (Exception e)
                System.out.print(e);
      public void keyRepeated(int keyCode)
           eventType = "repeated";
           keyValue = getKeyName(keyCode);
           try
                Thread t1 = new Thread()
                     public void run()
                          try
                               player = Manager.createPlayer("capture://audio?encoding=pcm");
                               player.realize();
                               RecordControl rc = (RecordControl)player.getControl("RecordControl");
                               ByteArrayOutputStream output = new ByteArrayOutputStream();
                               rc.setRecordStream(output);
                               rc.startRecord();
                               player.start();
                               eventType = "Recording";
                               message.setText("Recording...");
                               Thread.sleep(5000);
                               message.setText("Recording Done!");
                               rc.commit();
                               recordedAudioArray = output.toByteArray();
                               player.close();
                          catch (Exception e)
                }; t1.start();
           catch (Exception e)
           repaint();
         //Runnable r1 = new Runnable()
         //    public void run()
         //        try
         //            System.out.print(" here 1");
         //            message.setText(" here 1 ");
         //            player = Manager.createPlayer("capture://audio?encoding=pcm");
         //            player.realize();
         //            RecordControl rc = (RecordControl)player.getControl("RecordControl");
         //            ByteArrayOutputStream output = new ByteArrayOutputStream();
         //            rc.setRecordStream(output);
         //            rc.startRecord();
         //            player.start();
         //            eventType = "Recording";
         //            message.setText("Recording...");
         //            Thread.sleep(5000);
         //            message.setText("Recording Done!");
         //            rc.commit();
         //            recordedAudioArray = output.toByteArray();
         //            player.close();
         //        catch (Exception e)
    }I am really sorry at the end I messed with the code and its altered a Lot, But hope the
    logic Will is clear which is my requirement . I know the code for recording and
    playing is not complete as said, i Messed around a working code and tried adding Canavs
    for keyrepeat method,tried putting a thread around , AT last totally messed,
    I tried working on this for two days but couldn't be successfull , Please Help me!!
    The control goes out when midlet asks whether to allow recording ,
    I thank you anticipation ...
    -Abhijith Rao

    Midlet asking whether to allow the recording are typical permissions prompts specified by MIDP security policy. You need to sign the MIDlet and give it proper permissions.
    Problems like this were discussed in an older thread at WTK forum: *[MIDlet keeps asking for permission.|http://forums.sun.com/thread.jspa?threadID=5347313]* According to one of the posters in the thread, +"...I got it to work on the emulator by setting the permission to 'manufacturer'. It runs smoothly without annoying questions..."+
    If you're interested, check documentation and tutorials on MIDP security policy for more details.
    For events to record audio only when the key is being pressed, consider GameCanvas API, method getKeyStates.
    I am not certain though if doing it this way is a good idea. I doubt that phone users have same habits as those of walkie-talkies; for them it might be indeed more comfortable to use single simple key presses to start and finish recording.

  • My iphone 4's home button doesn't work properly..please help!!!

    i have an iphone 4, I have some problems with home button. I can hear the click of button but it respondes only when I hit it hard...please help me

    I just want to let you know this is a software issue.  The 4 and such has been having this issue all over this place since iOS 6 has come out, it's documented all over these forums but Apple does not want to admit it.  Yes if you check the steps on 'recalibrating' that will get your home button working for a bit.  In most cases wiping out everything on the phone brings it to normal working level.  Just saying, had this issue for a while and I've read way to many posts by Apple employees not understanding what is going on.

Maybe you are looking for

  • My ipod is not being detected on my dell latitude620

    I just got a dell latitude 620 laptop My ipod is being detected as a "device" My ipod will charge, but itunes does not recognize it. I've uninstalled itunes and reinstalled it twice. And tried about 90% of what apple support suggests There is nothing

  • Can I synch an ipod nano 6th generation with Mac OSX 10.4.11 with Itunes 8.02?

    Can I synch an ipod nano 6th generation with Mac OSX 10.4.11 with Itunes 8.02?

  • Error while starting SOA suite

    Hi All, i am unable to start SOA suite it is giving a error saying OPMN error how to come out of this Configuration information Running in C:\product\10.1.3.1\OracleAS_2 Operation mode:Startup, App Server, No Enterprise Manager, Single Instance Oracl

  • Help! I cannot get a server to work on my one game!

    On Garry's Mod, and Counter Strike: Source, i cannot make servers. I also am not very good with routers. Can someone please help me?

  • Condition based mtc

    Pm gurus Please bring ur thoughrs for my process req. we need to carry the Condition based mtc order for objects. Ex: In our Centrifugal fans we are measuring the vibration suppose while measurement it reaches 8 mm. the orders has to create by the sy