Custom text painting using JTextField

Greetings all!
I would like to implement a custom JTextField that displays text in gradient colors instead of the usual solid colors.
I guess I would need to override the default painting mechanism in JTextField, but I'm not sure how to go about it.
Would appreciate if anyone can give me any suggestions/tips!
Thanks so much!
Dora
public class GradientTextField extends JTextField {
}

it will work only if the size of the textfield is large enough (no scrolling).Good point. Here's a newer version that seems to work ok, assuming the text is left justified.
import java.awt.*;
import javax.swing.*;
public class GradientTextField extends JTextField
    private Color from;
    private Color to;
    private Insets insets;
    private Point view = new Point();
    public GradientTextField(Color from, Color to)
        this.from = from;
        this.to = to;
        insets = getInsets();
    public void paintComponent(Graphics g)
        setForeground( getBackground() );
        super.paintComponent(g);
        //  Get the text to paint, assuming left justification
        getInsets( insets );
        view.x = insets.left;
        view.y = insets.top;
        int offset = viewToModel( view );
        String text = getText().substring(offset);
        //  Create the GradientPaint object
        FontMetrics fm = g.getFontMetrics();
        int width = fm.stringWidth( text );
        int x = insets.left;
        int y = fm.getAscent() + insets.top;
        GradientPaint paint = new GradientPaint(x, 0, from, x + width, 0, to);
        //  Use the GradientPaint object to overwrite the existing text
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(paint);
        g2d.drawString(text, x, y);
    public static void main(String[] args)
        JTextField textField = new GradientTextField(Color.blue, Color.green);
        textField.setText("ABCDEFGHIJKLMNOPQRSTUVWZYZ");
        JFrame frame = new JFrame("Gradient Text Field");
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.getContentPane().add(textField, BorderLayout.SOUTH);
        frame.pack();
        frame.setLocationRelativeTo( null );
        frame.setVisible(true);
}It's probably not a complete solution, but it may be helpful is specific situations.

Similar Messages

  • Hello, I am trying to use a photo,that I've opened up in pages on a blank landscape, taken from my camera roll and use it as album cover art. All the custom text's will not paste when I copy.  Pic and texts are saved as a PDF, how can I paste the doc ?

    Hello, I am trying to use a photo,that I've opened up in pages on a blank landscape, taken from my camera roll and use it as album cover art. All the custom text's will not paste when I copy.  Pic and texts are saved as a PDF, how can I paste the doc ?

    Hello, I am trying to use a photo,that I've opened up in pages on a blank landscape, taken from my camera roll and use it as album cover art. All the custom text's will not paste when I copy.  Pic and texts are saved as a PDF, how can I paste the doc ?

  • Using xsl stylesheet with List View Web Part to display custom text

    Hi 
    i have an xsl stylesheet with sharepoint listview webpart. The list view shows some items based on a filter. I want to display custom text such as "No Items" when there are zero items in the list view using the xsl stylesheet. How do i achieve
    this. I have spent hours searching but couldnt find the exact answer. Please help me out. I am a light user not a hard core developer so I dont use Visual Studio. Thanks in advance

    Hi 
    I have customised the list view webpart using a custom xsl file by including it in the xsl link of the list view webpart. So i think i need to include the condition in the xsl file itself else it wont work. Since the list view webpart isnt using the default
    xsl. Please let me kknow if you have any idea about including a condition in xsl to check if there are not items in view. 
    The code of the xsl is included below.
    <!--
    This section is the set up and can be used at the top of any external XSLT stylesheet file
    -->
    <xsl:stylesheet
    xmlns:x="http://www.w3.org/2001/XMLSchema"
    xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
    version="1.0"
    exclude-result-prefixes="xsl msxsl ddwrt"
    xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
    xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
    xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:SharePoint="Microsoft.SharePoint.WebControls"
    xmlns:ddwrt2="urn:frontpage:internal">
    <xsl:output method="html" indent="no"/>
    <xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema">
    <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
    <table>
    <xsl:for-each select="$Rows">
    <xsl:call-template name="dvt_1.rowview"></xsl:call-template> 
    </xsl:for-each>
    </table>
    </xsl:template>
    <xsl:template name="dvt_1.rowview">
        <tr>
      <td><img height="78" width="60"><xsl:attribute name="src"><xsl:value-of select="@Photo"/></xsl:attribute></img></td>
        <td>
        <table style="margin-left:10px;">
        <tr><td><xsl:value-of select="@FullName"/></td></tr>
        <tr><td><xsl:value-of select="@DOBinWords"/></td></tr>
        </table>
        </td>
      </tr>
    </xsl:template>
    </xsl:stylesheet>

  • Using XPATH to populate a drop down with custom text enabled?

    Hello,
    I am using the custom state field provided by Adobe Form Designer 7.1, and I checked the option to allow custom text entry.
    Within my workflow, I have script that will access the XDP path and set the state to a string. I get the _state value from a DB query (where _state = _rs.getString(#)), but here I'll use a static value to provide a good example:
    String xdproot = "/process_data/appform/form-data/data/xdp/datasets/data/App";
    String _state = "Fl";
    patExecContext.setProcessDataValue( xdproot + "/State", _state );
    When I received the form from the workflow (via email) my other fields were set properly, but the state field was blank.
    Should I use setProcessDataStringValue?
    Thanks for your help!
    Rob

    Hi Rob
    I don't believe using StringValue will make any difference. If you're passing a string, it should amount to the same thing.
    Some things to try:
    Try setting the value using the SetValue QPAC - does that work?
    Try testing your form by setting an XML file containing "Fl" in the state field as your preview data (In Designer, File/Form Properties)
    Try using the Variable Logger to check the data in your form is set correctly.
    http://www.avoka.com/Avoka/qpac_library.shtml
    Are you using Reader 8.1. We've experienced several problems with DropDowns in 8.1. Try using 7.0.5 or greater.
    Good luck...
    Howard
    http://www.avoka.com

  • Text Variable using Customer Exit .

    Hello Friends. I have a requirement to create Text Variable using Customer Exit . So I created the Text Variable as "ZVRBMS" and assigned that with YTD &ZVRBMS& in the Structure of Query Desigener . so that Out put will YTD AUTO
    OR YTD RETAIL
    Now this Auto And Retail comes from Version that user choose via variable ZFIBMSVER IN User Promt. if ZFIBMSVER = 10
    then ZVRBMS = auto . and if ZFIBMSVER = 20
    then ZVRBMS = RETAIL
    Please correct my ABAP code in customer exit and let me know to make this work
    when 'ZVRBMS'.
        if I_STEP = 2.
          clear LOC_VAR_RANGE.
          loop at I_T_VAR_RANGE into LOC_VAR_RANGE.
            if LOC_VAR_RANGE-VNAM = 'ZFIBMSVER'.
          if SY-SUBRC = 0 OR LOC_VAR_RANGE-LOW = '10'.
            L_S_RANGE-LOW = 'AUTO'.
          elseif LOC_VAR_RANGE-LOW = '20'.
            L_S_RANGE-LOW = 'RETAIL'.
          L_S_RANGE-SIGN ='I'.
          L_S_RANGE-OPT  = 'EQ'.
          append L_S_RANGE to E_T_RANGE.
      endif.
      endif.
      exit.
          endloop.
    endif.
    Thanks
    Soniya

    The code should be:
    when 'ZVRBMS'.
    if I_STEP = 2.
    clear LOC_VAR_RANGE.
    loop at I_T_VAR_RANGE into LOC_VAR_RANGE.
    if LOC_VAR_RANGE-VNAM = 'ZFIBMSVER'.
    if LOC_VAR_RANGE-LOW = '10'.
    L_S_RANGE-LOW = 'AUTO'.
    elseif LOC_VAR_RANGE-LOW = '20'.
    L_S_RANGE-LOW = 'RETAIL'.
    endif.
    L_S_RANGE-SIGN ='I'.
    L_S_RANGE-OPT = 'EQ'.
    append L_S_RANGE to E_T_RANGE.
    endif.
    exit.
    endloop.
    endif.

  • Custom Text disappears on exit when using Dynamic Forms

    If you have a dropdown list and you tick the box to "Allow Custom Text Entry" in a Dynamic form format, it will not hold the custom value when you leave that field.
    If you save the Dynamic form as a Static Form the custom entries work fine.
    I need help ASAP with this as it is very annoying.
    Thanks in Advance

    I need help with this. I followed these instructions to the T as far as I am aware but I cannot get it to work. I get the error message:
    "Script failed (language is formcalc; context is
    xfa[0].form[0].form1[0].#subform[0].DropDownList1[0])
    script=addEnteredValue(sDropdown_XFA, svalue)
    var oDD = xfa.resolveNode(sDropdown_XFA);
    if ((null == sValue) || ("" == sValue))
    return;
    var sLBValue = "";
    var bFoundValue = false;
    for (var i = 0; i < xfa.resolveNode(sDropdown_XFA + ".#items").nodes.length; i++)
    sLBValue = xfa.resolveNode(sDropdown_XFA + ".#items.#text[" + i + "]").value;
    if (sValue == sLBValue)
    bFoundValue = true;
    if (!bFoundValue)
    oDD.addItem(sValue);
    oDD.rawValue = sValue;
    addEnteredValue("form1.#subform[0].DropDownList1", gDropDownTemp.value);
    gDropDownTemp.value = "";
    Error: function 'addEnteredValue' on line1, column 38 is unknown. "
    Obviously I'm doing something wrong. How do you make it recognize the addEnteredValue function? -- When I added "gDropDownTemp;" to the File-->Form Properties-->Variables tab it said that it MUST have a value so I put 0, it wouldn't allow me to not enter a value even though instructions say otherwise. I'm new to this and I know what I want but getting to that point is another story it seems. Any help would be greatly appreciated.

  • How can I add a new message(custom text message) to the holiday approval em

    How can I add a new message(custom text message) to the holiday approval email-notification sent to the manager?
    TIA

    The answer is 'not very easily', unless the information you want to display is the employee's leave balances. In 12.1.3 Oracle have delivered functionality that allows you to include the leave balances in the approval notifications out-the-box, ie, without customization.
    For any other information you're probably going to have to customize the standard delivered HRSSA workflow. Within this workflow, the Leave of Absence functionality uses the Notify Approver (Embedded) (HR_APPROVER_NTF) notification. The body of this notification is set to the Notify Approver (Embedded) (HR_NTF_EMBEDDED_REGION) attribute. This in turn defaults to:
    JSP:/OA_HTML/OA.jsp?OAFunc=-&HR_EMBEDDED_REGION-&NtfId=-&#NID-
    So essentially you can change the HR_APPROVER_NTF notification. The problem with changing this notification is that it's generic - it's used for all SSHR functions and not just Leave of Absence. That means you have to make other, more substantial, customizations to the workflow to ensure the changes you make only applies to LOA.
    The other option is to personalize the review page (ie, the region referenced in &HR_EMBEDDED_REGION) to include whatever messages you want. But that means they'll appear on the Review page and all LOA approval notifications and that might not be what you want.
    It's usually better to live with what Oracle deliver and find an alternative solution! What's the content of the message you want to include?

  • Short Dump while including custom text

    Hi Guru's
                I am new to workflow and i have a requirement to include a custom text by replacing the standard one.
                I selected the user decision and navigated to control tab there i got the task number, i just copied the task
               number  by using the transaction pftc_cop and reassigned the custom task number.Now i can view the
               custom text in the preview but while doing the check it shows "1 warnings and 0 errors" and while
               activation it goes to short dump can you please resolve my issue as soon as possible.

    Hi Suresh,
                   I checked in SWU3. While performing automatic workflow customizing
                   it shows an information message as "Customizing already carried out".
    Below i had given the short dump description.Please have a look and make me clear
    What happened?
        The current application program detected a situation which really
        should not occur. Therefore, a termination with a short dump was
        triggered on purpose by the key word MESSAGE (type X).
    How to correct the error.
        Probably the only way to eliminate the error is to correct the program.
        If the error occures in a non-modified SAP program, you may be able to
        find an interim solution in an SAP Note.
        If you have access to SAP Notes, carry out a search with the following
        keywords:
        "MESSAGE_TYPE_X" " "
        "SAPLOLEA" or "LOLEAU02"
        "AC_SYSTEM_FLUSH"
        If you cannot solve the problem yourself and want to send an error
        notification to SAP, include the following information:
        1. The description of the current problem (short dump)
           To save the description, choose "System->List->Save->Local File
        (Unconverted)".
        2. Corresponding system log
           Display the system log by calling transaction SM21.
           Restrict the time interval to 10 minutes before and five minutes
        after the short dump. Then choose "System->List->Save->Local File
        (Unconverted)".
        3. If the problem occurs in a problem of your own or a modified SAP
        program: The source code of the program
           In the editor, choose "Utilities->More
        Utilities->Upload/Download->Download".
        4. Details about the conditions under which the error occurred or which
        actions and input led to the error.
    Regards,
    Manoj

  • Need help in populating Text ID using IDOC ORDERS05

    I have following scenario.
    PO is being send from ECC to EDI partner.
    and we received the PO feedback from the EDI partner
    For PO feed back, we are using ORDERS05 idoc type and ORDRSP message type.
    Custom Text Id(F01)  has been added to the Text tab of the header section of the Purchase order screen (ME23N).
    Custom Text id (F02)  has been added to the Text tab of the Item section of the purchase order screen.
    (Text ID F01 and F02 are in object EKKO - checked in transaction se75)
    Now, I m posting idoc with the following value but Text field (in header and item level) is not updating while displaying PO.
    Header - E1EDKT1                                   
         TDID -   F01
         TSSPRAS- E     
                         TDOBJECT - EKKO
                  E1EDKT2                                   
         TDLINE   -  "My Header Text"
    Item Level - E1EDKT1                                   
         TDID -   F02
         TSSPRAS- E     
                         TDOBJECT - EKKO
                  E1EDKT2                                   
         TDLINE   -  "My Item level Text"
    Can we update the Text Id in PO using IDOC ORDRSP.ORDERS05?  I have tried but it is not updating
    Any suggestion.
    Edited by: Chetankumar Patel on Mar 14, 2011 10:17 PM

    Have you tried with updating other Long texts ? While going through the code of inbound function module IDOC_INPUT_ORDRSP, it is mentioned that only limited fields are available for updation.  See remarks in line no : 88 of include LEINMF2O.
    read document and prepare for update P.O. Item fields
    * possible Update fields of EKPO: LABNR, IDNLF, NETPR

  • Replicating custom texts in BP from CRM to ECC systems

    Hi All,
    I'm trying to set up synchronisation of a custom text held against a business partner in CRM with our ECC system.  So, in CRM, if I go to transaction BP and go to change mode for a partner and then go to the long texts tab...  As well as the 2 standard Correspondance and Accounting Note text ID's my functional consultant has also configured a third text, with ID Z001.  We are trying to get this to synchronise with ECC.
    With a bit of debugging I can see the text is being sent in a BDOC across to ECC but it isn't being populated into the customer master.  On the ECC side the custom text has been set up against the sales area of the customer master - I'm not sure of what else has been done there.
    Has anyone done this before who can give us some help/advice?  Bear in mind I know almost nothing about CRM to ECC synchronisation and BDOC's so I'm struggling with this!
    Thanks in advance,
    Gareth.

    Hi Gareth,
    While researching this issue I came across note number 622133. https://websmp202.sap-ag.de/~form/handler?_APP=01100107900000000342&_EVENT=REDIR&_NNUM=622133&_NLANG=E
    Its an old note, but it pointed me in the general direction of FM 'PI_BP_MAP_TEXT_IDS_CRM_R3'. This FM looks in table 'CRMTEXTID' to check if any mappings were maintained. Now if you do a where-used on CRMTEXTID, you see that it is used in a view, V_CRMTXTID. So go to SM30, maintain that view, map your R/3 text IDs to CRM text IDs and you should be all set.
    There must be a more elegant way to get to this table, but in the short term, this should fix your problem. I haven't tested it yet on my system but I get the feeling this should work

  • How to set the text in a jtextfield to align to the left

    A quick simple question. I'm populating a jtextfield with text pulled from a record. However the text is too long to fit in the jtextfield and the alignment is set to the right rather than the left. How do I set the alignment of the text in the jtextfield to be on the left, so that the first character of the string is shown?
    I've tried using
    setHorizontalAlignmnet(JTextField.LEFT),
    but my text still appears right justified in the jtextfield. It means that the user has to scroll the text to go to the beginning of the string, rather than the usual of scrolling the right to go the end of the string.
    This has really gotten me stumped!

    HI thanks for the help. Unfortunately it doesn't work if the text is longer than the actual textfield. The textfield would still show the end of the text, rather than showing the beginning of the text.
    For e.g.
    |est text|
    is show rather than
    |test tex|
    which is my desired result.
    Any further suggestions please.

  • CRM Sold To Text ID transfer to R/3 Customer Text ID

    Hi All,
    Now I need your suggestion on how to transfer CRM BP Sold to Text to
    R/3 Customer Text. My first assumption, it's like in Order document where
    we just need to create same Text ID for both document in CRM and R/3.
    But it seems doesn't work for BP. I need to transfer BP Text from CRM to R/3.
    Does it require BDT to customize? (As far as I know it's only for additional field
    in CRM BP).
    Or do we have to use Text Object KNA1 in CRM BP? As we know that
    CRM BP using Text Object BUT000. How to switch to Text Object KNA1?
    Or can we use both Text Object BUT000 and KNA1 on CRM BP?
    Thanks in advance.
    Gun.

    Hi All,
    Now I need your suggestion on how to transfer CRM BP Sold to Text to
    R/3 Customer Text. My first assumption, it's like in Order document where
    we just need to create same Text ID for both document in CRM and R/3.
    But it seems doesn't work for BP. I need to transfer BP Text from CRM to R/3.
    Does it require BDT to customize? (As far as I know it's only for additional field
    in CRM BP).
    Or do we have to use Text Object KNA1 in CRM BP? As we know that
    CRM BP using Text Object BUT000. How to switch to Text Object KNA1?
    Or can we use both Text Object BUT000 and KNA1 on CRM BP?
    Thanks in advance.
    Gun.

  • Rich Text Editor with Custom Text Attribute

    Hello All,
    We are using the latest version of Oracle Portal 10G. I have a need to create custom Attributes of the type text to let people enter a lot of text. But when User are in edit mode of an item where this custom attribute is used, the Rich Text Editor is not shown for entering the Text for the Custom Text Attribute. It shows a normal html text area. Has anyone ever used RTE with Custom Attribute?
    I request you guys for help.
    Thanks.

    The Problem with the Custom Attribute is not solved, but I have now compromised with the Situation and now I am not using a Custom attribute.
    Rather, Now I am creating a Custom Item Type using Base Text Type (earlier i wanted to create custom item type at my own without any base item type). In this case now I will not be able to change the Lable of the RTE (that is "Text", when the Custom Item is in Edit Mode), but I hope that my users can understand that much.
    I have created a template for portal pages. In the Template I can edit the Region Properties. When I edit the Region property of the region where I want to display my Custom Items. I get two Tabs on the top, Main and Attributes/Style. ON the main tab I can tell what type of region it should be, width etc, in my case it is item type region. And on the Attributes/Style tab, I can select from the availabe Attributes as which all Attributes I want to display. Here if i select only "Associated Functions" Attribute then normally portal should not render anything by default on the Page. It should rather make a call to the procedure which is associated with the Custom Item and as when I was creating the custom item type, I had clicked on "Display Procedure Results With Item", so portal should now display the result of my Procedure. So far it works without problem.
    But the problem is that the Portal displays the text at its own also. As i have written that Portal should not display anything at its own, this doesn't work in this version of Portal for a Custom Item Type that is made using Base Text Item Type. For all others it has worked till now (I have create 50s of Custom item types).
    You can better understand by going to the following URL. Just have a look between the two dotted lines (Dotted line is also a seperate Custom Item Type). Between the two Dotted Lines is a custom item, in general it would be a Custom News Item having title, image and so on.
    http://sunnode1.edvz.sbg.ac.at:7778/portal/page?_pageid=79,56047&_dad=portal&_schema=PORTAL
    I have really programmed a lot with portal but now at this stage where I am near to end, I am getting problems which are coming from Product. I request you for help.

  • How to add custom text on ISA B2B Order

    Hi,
    On Order page of ISA B2B I have created a custom text field  "Shipping Attention".When I try to add this text in the header like
    header.addExtensionData("Z123","Value") in Z_BasketRefreshAction which extends MaintainBasketDispatcherAction, it is not reflecting in the "Shipping Attn"(created in the text tab in CRM)  field in CRM system.
    The flow:
    /b2b/maintainbasket --> Z_BasketRefreshAction --> /b2b/basketrefresh --> MaintainBasketRefreshAction --> b2b/updatedocumentview
    Please let me know if I missing something...
    Thanks in Advance.
    Regards,
    Muthu

    Hello,
    You have covered the first two layers of the request - response cycle cake - the View (JSP) and the Control (Java) layers. The icing is done in the backend BAdI and using the right function module. I am assuming the CRM backend.
    A typical request-response in the application goes like this. I will give example for the header extensions.
    Added the custom variable in the HTML layer (JSP page)
    Traversed through the Dispatcher, Parser and get the input value from the JSP page variable and added it to the Business Object (Header) using addExtensionData.
    The java application layer actually makes an "Update Header" call during the update cycle - like when you click that "Update" button.
    In the SAP E-Commerce design, during this "update" cycles, the application flows through specific BAdI call sequence. It calls what I call the Header BAdI CRM_ISA_BASKET_HEAD when the header information is updated. You have to extend this BAdI and implement at least two methods.
    It has two methods - which are called during this request - response cycle. First method CHANGEHEAD_SET_DATA is called during the request cycle - that is from ISA to CRM (when update is clicked). This is where your extension data has to be transferred from the Java layer to the backend layer (model). You will essentially read from the table IT_EXTENSION and call SAVE_TEXT function module. Since your requirement is to update text, this is the FM to be called. Many other cases use the FM mentioned by Mike. This is where the data from the web layer is persisted in the backend model.
    And the other method GETHEAD_GET_DATA is called during the response cycle. In this method, you will essentially read from the model - in your case READ_TEXT and set it back in the extension layer CT_EXTENSION
    The update header call from the Java layer will now receive the data back from the model and will automagically transfer the values from the backend (ABAP layer) back to the Java layer to be accessible by you in the JSP using getExtensionData call.
    What you have to do are the steps .5 and 6 in order to complete the request-response cycle.
    Easwar Ram
    http://www.parxlns.com

  • On and iPad how to Allow User To Enter Custom Text  (Dropdown only) Enables users to enter a value other than the ones in the list.

    On an iPad, how do I :
    Allow User To Enter Custom Text
    (Dropdown only) Enables users to enter a value other than the ones in the list.'?

    Are you using the built-in Currency option under the Format tab? If so,
    what you're describing should not happen.

Maybe you are looking for

  • Filter on SAP ABAP Initial Loads

    Hi all, I'm trying to put a filter on the pass "ReadABAPuser" of an ABAP Initial Load. My SAP ABAP System has over 10000 users and I need only part of them. I tried so to add "FILTER" entry (as on ReadABAProle for example) on Source tab of the pass "

  • T.code CN43N (Adding the PRPS-AEDAT) on selectoin screen

    Hi Experts, I need to add a field (PRPS-AEDAT [The person who last changed the object]) on the selection screen and after adding it need to validate in the program. I broke my head but even couldn't able to find the place; where excatly that selectio

  • Alerts Display problem

    Hi,   I have done alert configuration and everything is fine Alerts are getting triggerrd properly..    but the problem is in alert mail its not displaying the Container variables information. Ex sender party,Error code, interface name. these informa

  • Does this have GPS or not?

    I've been reading some other posts, all about the GPS and A-GPS or Assisted GPS, which basically assists the GPS receiver in aquiring your position quicker. So if that's the case, then how could a position be off by miles? That makes me think that it

  • Excel Tables

    Using Excel and creating a table. How do I print off a table with all the lines in bold  ?