How can I show vertical text?

Hi all, does any body knows how can I show a vertical text using g2.drawString() method?
For example:
g2.drawString("Help", x, y);
I want the text appear like:
p
l
e
H
of course with the correct rotation of each character.
thanks in advance

Here's the code we use in the JFreeChart project:
     * A utility method for drawing rotated text.
     * <P>
     * A common rotation is -Math.PI/2 which draws text 'vertically' (with the top of the
     * characters on the left).
     * @param text  the text.
     * @param g2  the graphics device.
     * @param x  the x-coordinate.
     * @param y  the y-coordinate.
     * @param rotation  the clockwise rotation (in radians).
    public static void drawRotatedString(String text, Graphics2D g2,
                                         float x, float y, double rotation) {
        if ((text == null) || (text.equals(""))) {
            return;
        AffineTransform saved = g2.getTransform();
        // apply the rotation...
        AffineTransform rotate = AffineTransform.getRotateInstance(rotation, x, y);
        g2.transform(rotate);
        // workaround for JDC bug ID 4312117 and others...
        TextLayout tl = new TextLayout(text, g2.getFont(), g2.getFontRenderContext());
        tl.draw(g2, x, y);
        // replaces this code...
        //g2.drawString(text, x, y);
        g2.setTransform(saved);
    }That bug workaround is causing trouble in some JDKs, try the original code and see if it works for you.
Regards,
Dave Gilbert
www.jfree.org

Similar Messages

  • How can I show only text edits and not text formatting when using print comments summary?

    Acrobat 9.3.0 for Mac.
    Here is the scenario: I used the Compare command to see the changes between 2 PDFs. The resulting file some edits are inserts and some are deletions. I want to print a comments summary only showing the text edits. In the Compare Option pane, I select Text and deselect Images, Annotations, Formatting, Headers/Footers, and Backgrounds. Now on the screen I see inserts are highlighted in blue and deletions are marked with sort of a caret and vertical bar symbol. So all looks good at this point. However, when I show the Comments List, I see addtional comments that indicate "Replace - The following text attributes were changed: fill color." Those comments do not appear in the page view unless I check the Formatting check box to show them. With Formatting unchecked, I print a comments summary and all of the "Replace - Fill Color" comments" appear on the resulting comments summary.
    I only want to show text edits, not text formatting changes. So questions are:
    1. Why, when the Formatting checkbox is unchecked, do the text formatting comments still appear in the comments list when they do not appear on the page display.
    2. How can I print only the text content edits and not show the text formatting changes when using Print Comments Summary.

    Hi,
    You can set ExecuteWithParams as default activity in the task flow then method activity to return total no of rows passing to Router activity if your method has value 0 then call Create insert operation else do directly to page.
    Following idea could be your task flow
    Execute With param (default) > SetCurrentRowWithKey > GetTotalNoOfRows (VOImpl Method)
    |
    v
    Router
    1. If pageFlowScope outcome is 0 then call CreateInsert > MyPage
    2. if pageFlowScope outcome > 0 then MyPage
    hope it helps,
    Zeeshan

  • How can I show the Text variable in WAD 7.0

    Hi All,
    How I can show the text variable in WAD 7.0??
    Kinsly suggest me..
    Re

    Hi,
    As far as i know u do not need any special web item to display the text variable as such. have a analysis item in u r WAD and assign query to the same. Ur variables appear as per the configuration u have made in the query designer. WAD has nothing to do.
    Regards

  • How can i show input text when no row present in database.

    Hi All,
    I am using Jdeveloper 11g Release1(11.1.1.4.0)
    I have created EO and VO which is based on that EO.
    By using Vo i have designed .jspx page ,on that page i have taken adf form which is based on that VO.
    My problem is when database table is blank (i.e zero row) then input text on page not displayed.
    I want to show blank input text when such condition occurs.
    Thanks
    Imran.

    Hi,
    You can set ExecuteWithParams as default activity in the task flow then method activity to return total no of rows passing to Router activity if your method has value 0 then call Create insert operation else do directly to page.
    Following idea could be your task flow
    Execute With param (default) > SetCurrentRowWithKey > GetTotalNoOfRows (VOImpl Method)
    |
    v
    Router
    1. If pageFlowScope outcome is 0 then call CreateInsert > MyPage
    2. if pageFlowScope outcome > 0 then MyPage
    hope it helps,
    Zeeshan

  • How do I add vertical text in a cell

    How can I add vertical text within a cell. In Ecel it is easy as pie but I can't seem to find a quick fix in "numbers"?

    Rotation of text in a table cell is not supported in Numbers.
    The most often recommended workarouns is to use a floating text box. Rotate the box 90° (or other desired value), make sure that Wrap is set to 'none', then place the text box in front of the cell.
    For other suggestions, see some of the posts in the "more like this" list to the right.
    Step 2 is to make a request to Apple that this feature be added. Go to the Numbers menu in Numbers, choose Provide Numbers Feedback (or use the link), make your request that this feature be added to future versions of Numbers.
    Regards,
    Barry

  • How can i make the text go vertically in numbers

    How can I make the text vertical in numbers?  I have merged the cells and cannot find an option for making it go vertical as opposed to horizontal.

    I already gave two tools to fit this kind of needs.
    tip #1 :
    --{code}
    --[SCRIPT write_vertically]
    Enregistrer le script en tant que Script : write_vertically.scpt
    déplacer le fichier ainsi créé dans le dossier
    <VolumeDeDémarrage>:Utilisateurs:<votreCompte>:Bibliothèque:Scripts:Applications :Numbers:
    Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
    Saisir dans une cellule le mot à écrire verticalement puis le sélectionner.
    ATTENTION, il ne faut pas sélectionner la cellule mais le mot qui doit apparaitre surligné.
    Aller au menu Scripts , choisir Numbers puis choisir “write_vertically”
    Le script colle dans la cellule le mot apès avoir inséré un return entre tous les caractères.
    Pour mon usage personnel j'associe un raccourci à ce script grace à FastScripts.
    --=====
    L’aide du Finder explique:
    L’Utilitaire AppleScript permet d’activer le Menu des scripts :
    Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case “Afficher le menu des scripts dans la barre de menus”.
    Sous 10.6.x,
    aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript
    puis cocher la case “Afficher le menu des scripts dans la barre des menus”.
    --=====
    Save the script as a Script: write_vertically.scpt
    Move the newly created file into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
    Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
    In a cell, type a word to write vertically then select it.
    CAUTION, don’t select the cell but the word which must be highlighted.
    Go to the Scripts Menu, choose Numbers, then choose “write_vertically”
    The script insert in the cell the word after inserting a return between every characters.
    For my own use, I link a shortcut to the script thank to FastScripts.
    --=====
    The Finder’s Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the “Show Script Menu in menu bar” checkbox.
    Under 10.6.x,
    go to the General panel of AppleScript Editor’s Preferences dialog box
    and check the “Show Script menu in menu bar” option.
    --=====
    Yvan KOENIG (VALLAURIS, France)
    2011/12/17
    2012/01/01 no longer use a local variable, use result
    --=====
    on run
    Clear the clipboard *)
      set the clipboard to ""
    Copy the selection in the clipboard *)
              my raccourci("Numbers", "c", "c")
    Loop waiting that the clipboard is really filled *)
              repeat
                        try
                                  if (the clipboard as text) is not "" then exit repeat
                        on error
                        end try
              end repeat
    Extract the clipboard's content *)
      the clipboard as text
    Insert return between every characters *)
              my recolle(every character of result, return)
    Fill the clipboard with the edited string *)
      set the clipboard to result
    Paste in the cell *)
              my raccourci("Numbers", "v", "cas")
    end run
    --=====
    on recolle(l, d)
              local oTIDs, t
              set oTIDs to AppleScript's text item delimiters
              set AppleScript's text item delimiters to d
              set t to l as text
              set AppleScript's text item delimiters to oTIDs
              return t
    end recolle
    --=====
    on activateGUIscripting()
      (* to be sure than GUI scripting will be active *)
              tell application "System Events"
                        if not (UI elements enabled) then set (UI elements enabled) to true
              end tell
    end activateGUIscripting
    --=====
    ==== Uses GUIscripting ====
    This handler may be used to 'type' text, invisible characters if the third parameter is an empty string.
    It may be used to 'type' keyboard raccourcis if the third parameter describe the required modifier keys.
    I changed its name « shortcut » to « raccourci » to get rid of a name conflict in Smile.
    on raccourci(a, t, d)
              local k
              tell application a to activate
              tell application "System Events" to tell application process a
                        set frontmost to true
                        try
                                  t * 1
                                  if d is "" then
      key code t
                                  else if d is "c" then
      key code t using {command down}
                                  else if d is "a" then
      key code t using {option down}
                                  else if d is "k" then
      key code t using {control down}
                                  else if d is "s" then
      key code t using {shift down}
                                  else if d is in {"ac", "ca"} then
      key code t using {command down, option down}
                                  else if d is in {"as", "sa"} then
      key code t using {shift down, option down}
                                  else if d is in {"sc", "cs"} then
      key code t using {command down, shift down}
                                  else if d is in {"kc", "ck"} then
      key code t using {command down, control down}
                                  else if d is in {"ks", "sk"} then
      key code t using {shift down, control down}
                                  else if (d contains "c") and (d contains "s") and d contains "k" then
      key code t using {command down, shift down, control down}
                                  else if (d contains "c") and (d contains "s") and d contains "a" then
      key code t using {command down, shift down, option down}
                                  end if
                        on error
                                  repeat with k in t
                                            if d is "" then
      keystroke (k as text)
                                            else if d is "c" then
      keystroke (k as text) using {command down}
                                            else if d is "a" then
      keystroke k using {option down}
                                            else if d is "k" then
      keystroke (k as text) using {control down}
                                            else if d is "s" then
      keystroke k using {shift down}
                                            else if d is in {"ac", "ca"} then
      keystroke (k as text) using {command down, option down}
                                            else if d is in {"as", "sa"} then
      keystroke (k as text) using {shift down, option down}
                                            else if d is in {"sc", "cs"} then
      keystroke (k as text) using {command down, shift down}
                                            else if d is in {"kc", "ck"} then
      keystroke (k as text) using {command down, control down}
                                            else if d is in {"ks", "sk"} then
      keystroke (k as text) using {shift down, control down}
                                            else if (d contains "c") and (d contains "s") and d contains "k" then
      keystroke (k as text) using {command down, shift down, control down}
                                            else if (d contains "c") and (d contains "s") and d contains "a" then
      keystroke (k as text) using {command down, shift down, option down}
                                            end if
                                  end repeat
                        end try
              end tell
    end raccourci
    --=====
    --[/SCRIPT]
    --{code}
    tip #2 :
    --{code}
    --[SCRIPT rotate_cell_contents]
    Enregistrer le script en tant que Script : rotate_cell_contents.scpt
    déplacer le fichier ainsi créé dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
    Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
    Sélectionner une cellule dont le texte doit être tourné de 90 degrés.
    Aller au menu Scripts , choisir Numbers puis choisir “rotate_cell_contents”
    --=====
    L’aide du Finder explique:
    L’Utilitaire AppleScript permet d’activer le Menu des scripts :
    Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case “Afficher le menu des scripts dans la barre de menus”.
    Sous 10.6.x,
    aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript
    puis cocher la case “Afficher le menu des scripts dans la barre des menus”.
    --=====
    Save the script as a Script: rotate_cell_contents.scpt
    Move the newly created file into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
    Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
    Select a cell whose contents must be rotated for 90 degrees.
    Go to the Scripts Menu, choose Numbers, then choose “rotate_cell_contents”
    --=====
    The Finder’s Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the “Show Script Menu in menu bar” checkbox.
    Under 10.6.x,
    go to the General panel of AppleScript Editor’s Preferences dialog box
    and check the “Show Script menu in menu bar” option.
    --=====
    Yvan KOENIG (VALLAURIS, France)
    2011/06/23
    2011/06/26 -- No longer use an auxiliary text box. Now keep the text attributes.
    2012/01/31 -- edited for Lion
    --=====
    on run
              local dName, sName, tName, rowNum1, colNum1, rowNum2, colNum2
              local le_texte, la_largeur, la_hauteur, myNewDoc
              my activateGUIscripting()
    Extract properties of the source/target cell *)
              set {dName, sName, tName, rowNum1, colNum1, rowNum2, colNum2} to my get_SelParams()
              tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
                        set selection range to range (name of column colNum1 & name of row rowNum1)
              end tell
    Cut*)
              my raccourci("Numbers", "x", "c")
    Trigger Preview *)
              tell application "System Events"
                        if "Preview" is not in (name of every application process) then launch application "Preview"
              end tell
      delay 0.2 -- required
    New document from the clipboard *)
              my raccourci("Preview", "n", "c")
    Rotate to left *)
              my raccourci("Preview", "l", "c")
    Copy *)
              my raccourci("Preview", "c", "c")
    Quit *)
              my raccourci("Preview", "q", "c")
              (system attribute "sys2") < 7
              if result then
    Click the [Don't Save] button in the warning sheet *)
                        tell application "Preview" to activate
                        tell application "System Events" to tell application process "Preview" to tell window 1
                                  name of buttons
                                  repeat 50 times
                                            delay 0.1
                                            if exists sheet 1 then exit repeat
                                  end repeat
                                  tell sheet 1 to click button 2
                        end tell
              end if
    Back to Numbers *)
              tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
      -- just reset the focus on the table
              end tell
    Paste in the cell *)
              my raccourci("Numbers", "v", "c")
    end run
    --=====
    set { dName, sName, tName,  rowNum1, colNum1, rowNum2, colNum2} to my get_SelParams()
    tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
    on get_SelParams()
              local d_name, s_name, t_name, row_num1, col_num1, row_num2, col_num2
              tell application "Numbers" to tell document 1
                        set d_name to its name
                        set s_name to ""
                        repeat with i from 1 to the count of sheets
                                  tell sheet i to set maybe to the count of (tables whose selection range is not missing value)
                                  if maybe is not 0 then
                                            set s_name to name of sheet i
                                            exit repeat
                                  end if -- maybe is not 0
                        end repeat
                        if s_name is "" then
                                  if my parleAnglais() then
                                            error "No sheet has a selected table embedding at least one selected cell !"
                                  else
                                            error "Aucune feuille ne contient une table ayant au moins une cellule sélectionnée !"
                                  end if

  • How can I prevent my texts showing on another family members iPhone?

    How can I prevent my texts showing on another family members iPhone?

    Stop using the same apple ID for iMessage on both phones.
    Your question has already been asked and answered many many times. Search before posting please.

  • TS3999 In MONTH, (PC) iCal only clearly lists 2 items a day. The 3rd item is "faded" and bottom portion cut off, w/ a "more" triangle in the lower-right corner. How can I expand (vertically) so the 3rd line posts clearly, and ONLY shows "more" if 4+ event

    In MONTH, (PC) iCal only clearly lists 2 items a day. The 3rd item is "faded" and bottom portion cut off, w/ a "more" triangle in the lower-right corner. How can I expand (vertically) so the 3rd line posts clearly, and ONLY shows "more" if 4+ events?
    Better yet... as there's a lot of "wasted" space w/ too large Month title and empty space surrounding the Month title above and too much space surrounding the month/year slider bar below, how can I minimize these to allow me more usable / valuable calendar "contents" so I don't need to waste so much time clicking "more" just to see the bottom of the truncated third event and find out there are no 4+ events posted that date?  i.e. more "user-friendly" presentation?
    Thx!
    [email protected]

    In MONTH, (PC) iCal only clearly lists 2 items a day. The 3rd item is "faded" and bottom portion cut off, w/ a "more" triangle in the lower-right corner. How can I expand (vertically) so the 3rd line posts clearly, and ONLY shows "more" if 4+ events?
    Better yet... as there's a lot of "wasted" space w/ too large Month title and empty space surrounding the Month title above and too much space surrounding the month/year slider bar below, how can I minimize these to allow me more usable / valuable calendar "contents" so I don't need to waste so much time clicking "more" just to see the bottom of the truncated third event and find out there are no 4+ events posted that date?  i.e. more "user-friendly" presentation?
    Thx!
    [email protected]

  • How can I show text sentence on XY graph

    Hello,,,, anyone knows??? How can I show text sentence on XY graph?
    I just know that the only numeric data type can be the input data but my case I have both the number and message to show on the same graph.
    Thanks in advance
    Mannie

    You start out with an array of zero size. Since replace array subset does not change the size of an array, you stay with zero annotations. If nothing is there, you cannot replace it.
    Possible solutions:
    (A) Instead of reading the current annotation list (which is zero!), you could initialize the shift register with a diagram constant (right-click...create constant), expand it to the desired number of elements and make them all e.g. with a blank text.
    (B) Alternatively, you can manually create the desired number of annotation by right-clicking on the graph and select "data operations...create annotations". Now you start of with an array of the correct size if you read the annotation list with a property node and you can replace them programmatically with new annotations as desired.
    (C) You can also initialize the shift register with an empty array, then use built array to add annotations.
    LabVIEW Champion . Do more with less code and in less time .

  • How can we show data in rows when it is in Columns........

    I have strucked with a simple but a complex problem.
    I have a Report with data in vertical rows..need of the hour is how can we show that data into column structure.
    here is the table sample which i have in Database..
    Location      chrg_type    Effective_date
    xxxxxxx        xxxx          xx-xx
    thhis is the structure in effective date we have several months in it in a single column i want show the effective date or effective month in various columns instead of a single column.
    my required table is....
                                Effective_date     Effective_date
    Location      chrg_type     xx-xx              xx-xx
    xxxxxxx        xxxx          xx-xx
    any tough heads?????

    Hi Sunil,
    Your 1st problem is that you are going to need one more field to accomplish you goal. What type of data do want under your new date columns?
    Anyway, once you have that you need to move on to how to move the data out into columns based on date.
    Try something like this.
    0_Date = IF DATEPART('m',{tbl.Effective_date}) = DATEPART('m',CurrentDate) AND
    DATEPART('yyyy',{tbl.Effective_date}) = DATEPART('yyyy',CurrentDate)
    THEN {tbl.DataField}
    1_Date = IF DATEPART('m',{tbl.Effective_date}) = DATEPART('m',DATEADD('m', -1, CurrentDate)) AND
    DATEPART('yyyy',{tbl.Effective_date}) = DATEPART('yyyy',DATEADD('m', -1, CurrentDate))
    THEN {tbl.DataField}
    2_Date = IF DATEPART('m',{tbl.Effective_date}) = DATEPART('m',DATEADD('m', -2, CurrentDate)) AND
    DATEPART('yyyy',{tbl.Effective_date}) = DATEPART('yyyy',DATEADD('m', -2, CurrentDate))
    THEN {tbl.DataField}
    ... Repeat this process until you have all of the columns you need, following this format.
    Hope this works for you,
    Jason

  • How can i show 2 videos at once imovie09?

    How can i show 2 videos at once using imovie 09?

    camro1050 wrote:
    Yes I mean 2 video side by side. How do I do that in iMovie 11?
    From iMovie Help:
    To add a side-by-side clip:
    Make sure Advanced Tools are turned on.
    Open the project you want to add the side-by-side clip to so that it’s showing in the Project browser.
    In the Event browser, select a video clip or a frame range that you want to use as a side-by-side clip, and then drag it over a clip in your project.When you see the green Add symbol, release the mouse button.
    In the contextual menu that appears, choose “Side by Side.”In the Project browser, the side-by-side clip appears with a blue border around it above the video clip you added it to, at roughly the spot where you added it (toward the beginning, middle, or end of the clip).
    Depending on the length of the side-by-side clip you added, it may extend beyond the clip you added it to (only if there’s another clip after the clip you added the side-by-side clip to). You can drag the split-screen clip so that it begins at a different point in the main clip. To reposition where the split-screen clip appears in the project, drag it to a different clip.
    Play back the effect by placing the playhead (the red vertical line) anywhere before the side-by-side clip in the Project browser, and then pressing the Space bar.Press the Space bar again to stop playback.
    John

  • How can I show message from server?

    Has anyone idea, how can I show message from server? I want to show message after some files are uploaded via FTP.

    Hi,
    You can use OPEN DATASET for this purpose.
    Try this code:
    <b>****************************************</b>
    Data:
    A_FILE TYPE RLGRAP-FILENAME,   "Application server
    P_FILE TYPE RLGRAP-FILENAME.   "Presentation server
    DATA: BEGIN OF ITAB OCCURS 0,
    LINE TYPE STRING,
    END OF ITAB.
    DATA: FILENAME TYPE STRING.
    FILENAME = P_FILE.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                = FILENAME
      TABLES
        DATA_TAB                = ITAB[]
      EXCEPTIONS
        FILE_OPEN_ERROR         = 1
        FILE_READ_ERROR         = 2
        NO_BATCH                = 3
        GUI_REFUSE_FILETRANSFER = 4
        INVALID_TYPE            = 5
        NO_AUTHORITY            = 6
        UNKNOWN_ERROR           = 7
        BAD_DATA_FORMAT         = 8
        HEADER_NOT_ALLOWED      = 9
        SEPARATOR_NOT_ALLOWED   = 10
        HEADER_TOO_LONG         = 11
        UNKNOWN_DP_ERROR        = 12
        ACCESS_DENIED           = 13
        DP_OUT_OF_MEMORY        = 14
        DISK_FULL               = 15
        DP_TIMEOUT              = 16
        OTHERS                  = 17.
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    OPEN DATASET A_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    LOOP AT ITAB.
      TRANSFER ITAB-LINE TO A_FILE.
    ENDLOOP.
    <b>*****************************************</b>
    Hope this helps,
    Regards,
    Pragya

  • How can I create a text pop up window in my Pages document? I want text to pop up when the reader hovers his/her cursor over a certain word.

    How can I create a text pop up window in my Pages document? I want text to pop up when the reader hovers his/her cursor over a certain word in the document. I am teacher. So for example when a student came to word he/she did not know, if he/she hovered the cursor over the word, a defintion or other information would appear.  You can do this in Word using bookmarks/hyperlinks but I can't figure this out in Pages. I can link it to another point in my Pages document but I just need the text to pop up - not take the reader to another location.  THANK YOU!!!!!!

    Have you tried Word for Mac?
    You will need to test if links survive export or printing to .pdf
    Peter

  • How can I get the "text" field from the actionEvent.getSource() ?

    I have some sample code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.ArrayList;
    public class JFrameTester{
         public static void main( String[] args ) {
              JFrame f = new JFrame("JFrame");
              f.setSize( 500, 500 );
              ArrayList < JButton > buttonsArr = new ArrayList < JButton > ();
              buttonsArr.add( new JButton( "first" ) );
              buttonsArr.add( new JButton( "second" ) );
              buttonsArr.add( new JButton( "third" ) );
              MyListener myListener = new MyListener();
              ( (JButton) buttonsArr.get( 0 ) ).addActionListener( myListener );
              ( (JButton) buttonsArr.get( 1 ) ).addActionListener( myListener );
              ( (JButton) buttonsArr.get( 2 ) ).addActionListener( myListener );
              JPanel panel = new JPanel();
              panel.add( buttonsArr.get( 0 ) );
              panel.add( buttonsArr.get( 1 ) );
              panel.add( buttonsArr.get( 2 ) );
              f.getContentPane().add( BorderLayout.CENTER, panel );
              f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              f.setVisible( true );
         public static class MyListener  implements ActionListener{
              public MyListener() {}
              public void actionPerformed( ActionEvent e ) {
                   System.out.println( "hi!! " + e.getSource() );
                   // I need to know a title of the button (which was clicked)...
    }The output of the code is something like this:
    hi! javax.swing.JButton[,140,5,60x25,alignmentX=0.0,alignmentY=0.5,
    border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@1ebcda2d,
    flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,
    disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=14,bottom=2,
    right=14],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=true,
    rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=first,defaultCapable=true]
    I need this: "first" (from this part: "text=first" of the output above).
    Does anyone know how can I get the "text" field from the e.getSource() ?

    System.out.println( "hi!! " + ( (JButton) e.getSource() ).getText() );I think the problem is solved..If your need is to know the text of the button, yes.
    In a real-world application, no.
    In a RW application, a typical need is merely to know the "logical role" of the button (i.e., the button that validates the form, regardless of whether its text is "OK" or "Save", "Go",...). Text tends to vary much more than the structure of the UI over time.
    In this case you can get the source's name (+getName()+), which will be the name that you've set to the button at UI construction time. Or you can compare the source for equality with either button ( +if evt.getSource()==okButton) {...}+ ).
    All in all, I think the best solution is: don't use the same ActionListener for more than one action (+i.e.+ don't add the same ActionListener to all your buttons, which leads to a big if-then-else series in your actionPerformed() ).
    Eventually, if you're listening to a single button's actions, whose text change over time (e.g. "pause"/"resume" in a VCR bar), I still think it's a bad idea to rely on the text of the button - instead, this text corresponds to a logical state (resp. playing/paused), it is more maintainable to base your logic on the state - which is more resilient to the evolutions of the UI (e.g. if you happen to use 2 toggle buttons instead of one single play/pause button).

  • Forms 6.0-- How can I show records in a block in different colours.

    In a multi record block, how can I show few records in one colour and few more in a different colour depending on a condition.

    Use DISPLAY_ITEM.
    This will change the visual attribute of the item in the current(!) record,
    set_item_property changes the attributes of the item in all(!) records.

Maybe you are looking for