How to set JTextField length?

pnlBkBorrow = new JLabel("Book borrowed");
pnlMain.add(pnlBkBorrow);
textBkBorrow = new JTextField(25);
pnlMain.add(textBkBorrow);I am using GridBagLayout, but the length is only 1 after compling

I'm not a swing expert (and never used GridBagLayout, actually) but as far as I know, you must use GridbagConstraints to do what you asked.
Look at this example with a JButton:
JButton button;
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
button = new JButton("Button 1");
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 0;
pane.add(button, c);
button = new JButton("Button 2");
c.gridx = 1;
c.gridy = 0;
pane.add(button, c);
button = new JButton("Button 3");
c.gridx = 2;
c.gridy = 0;
pane.add(button, c);
button = new JButton("Long-Named Button 4");
c.ipady = 40;      //make this component tall
c.weightx = 0.0;
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 1;
pane.add(button, c);
button = new JButton("5");
c.ipady = 0;       //reset to default
c.weighty = 1.0;   //request any extra vertical space
c.anchor = GridBagConstraints.PAGE_END; //bottom of space
c.insets = new Insets(10,0,0,0);  //top padding
c.gridx = 1;       //aligned with button 2
c.gridwidth = 2;   //2 columns wide
c.gridy = 2;       //third row
pane.add(button, c);and the result should be like this http://java.sun.com/docs/books/tutorialJWS/uiswing/layout/example-1dot4/GridBagLayoutDemo.jnlp

Similar Messages

  • Xsd:integer - how to set maximum length

    Hi,
    In a structure, I have set some of fields as xsd:integer.  my scenario is file to proxy.  while generating the inbound proxy, for those elements which are xsd:integer, the data dictionary fields are authomatically set to INT4.  Whereas the actual field length is 15.  so when i test with the data the proxy fails as there is a mismatch is the length.  how do i overcome this problem.
    can i set the length of the field when the data type is xsd:integer so that while generating the proxy automatically this field length is taken. or otherwise can i change the data type in the dictionary table.
    kindly advise.
    Bala

    experts,
    can anyone suggest how to deal with this issue.
    thanks in advance. bala

  • How to set gap length between regions?

    say i want 1 second between each region.. is there a way to select all regions and set gap length? thanks.

    Hi there Barry124,
    You may find the article below helpful,
    How to adjust audio gaps between songs in an album
    http://support.apple.com/kb/HT1900
    -Griff W.

  • How to set array length correctly in this case

      class RunJavaCode implements ActionListener{
        public void actionPerformed(ActionEvent e){
          try{
            Process proc=Runtime.getRuntime().exec("java javaapp");
            InputStream input=proc.getInputStream();
            byte[] b=new byte[3000];
            input.read(b);              
            String javaReport=new String(b);
            input.close();
            outputText.setText(javaReport);
          }catch(IOException ioex){System.out.println("IOException is "+ioex);}
      }how to set this array(byte[] b) length correctly? I mean this array length should not only save memory,but also enough to use('enough to use' mean that read outputed info from console to this byte array never overflow)

    Hi,
    you cannot know in advance, how many bytes will be read. But the read-method returns the number of bytes actually read and this is important!
    So at least you have to write:        int r = input.read(b);
            String javaReport=new String(b, 0, r); However, you still do not know, whether there is even more output available. You could however retrieve the data in a loop and append it e.g. to a StringBuffer, until EOF is encountered.

  • How to set max length for TextField ?

    how do i go about setting a max length for a TextField in jdk1.1.8 ?
    a while back there was a topic on this but it was for jdk1.0
    please help

    well if it works in 1.0 it will most likely also work in 1.1.8 if it is depricated you can use the -deprication option during compilation to see what is derpricated and what method i advised to use now.
    there may however be an easyer way in 1.1.8 but i don't know that.
    hope this helps you,
    Robert

  • How to set max length to textfield?

    I have a textfield. I want to set maxlength to this textfield. Example, length = 3.
    Help me?

    I succeeded. That link you sent very well. Thanks you. Then it's code:
    JTextFieldLimit.java
    import javax.swing.text.*;
    //import com.sun.java.swing.*;
    //import javax.swing.text.*;
    public class JTextFieldLimit extends PlainDocument {
       private int limit;
       // optional uppercase conversion
       private boolean toUppercase = false;
       JTextFieldLimit(int limit)
        super();
        this.limit = limit;
       JTextFieldLimit(int limit, boolean upper) {
        super();
        this.limit = limit;
        toUppercase = upper;
       public void insertString
         (int offset, String  str, AttributeSet attr)
           throws BadLocationException {
        if (str == null) return;
        if ((getLength() + str.length()) <= limit) {
          if (toUppercase) str = str.toUpperCase();
          super.insertString(offset, str, attr);
    tswing.java
    import java.awt.*;
    import javax.swing.*;
      //import javax.swing.*;
      public class tswing extends JApplet{
        JTextField textfield1;
        JLabel label1;
        public void init() {
          getContentPane().setLayout(new FlowLayout());
          label1 = new JLabel("max 10 chars");
          textfield1 = new JTextField(15);
          getContentPane().add(label1);
          getContentPane().add(textfield1);
          textfield1.setDocument
             (new JTextFieldLimit(10));
    TextField.html
    <html>
    <applet code=tswing width=500 height=500>
    </applet>
    </html>
    By tungld_c0701m+

  • How to set JTextField to show certain map scale (e.g. 1/2000)

    Hi,folks. I have a JTextField instance. How can I set the format to only allow user to only type the map scale(e.g. 1/2000). I can only use the JTextField component. Thank you in advance.

    I think the regex you're looking for is"1/[1-9]\\d*"Note that in the regex you posted"1[\\]\\d*"the closing bracket is quoted by the backslash, causing the error you mentioned. Not that you needed a backslash there anyways.
    You can try this, but note that since replace(...) invokes remove(...) and replace(...), pasting an apparently valid String will not succeed if the slash is part of the replacement. Also that setText or pasting are the only ways to set the initial content as you won't be able to type it in one character at a time.import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    import javax.swing.text.AttributeSet;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.PlainDocument;
    public class ScaleFactorTextField {
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new ScaleFactorTextField().makeUI();
       public void makeUI() {
          JTextField textField = new JTextField(10);
          textField.setDocument(new PlainDocument() {
             final Pattern p = Pattern.compile("1/[1-9]\\d*");
             @Override
             public void insertString(int offs, String str, AttributeSet a)
                   throws BadLocationException {
                String newText = getText(0, offs) + str +
                      getText(offs, getLength() - offs);
                if (isValidText(newText)) {
                   super.insertString(offs, str, a);
             @Override
             public void remove(int offs, int len) throws BadLocationException {
                String newText = getText(0, offs) +
                      getText(offs + len, getLength() - offs - len);
                if (isValidText(newText)) {
                   super.remove(offs, len);
             @Override
             public void replace(int offs, int len, String text,
                   AttributeSet attrs) throws BadLocationException {
                String newText = getText(0, offs) + text +
                      getText(offs + len, getLength() - offs - len);
                if (isValidText(newText)) {
                   super.replace(offs, len, text, attrs);
             private boolean isValidText(String text) {
                Matcher m = p.matcher(text);
                return m.matches();
          textField.setText("1/20000");
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(textField);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
    }db

  • How to set the length of the reverb? (GarageBand)

    Hey Guys,
    im from germany and im just mixing and recording some songs in my free time with garage band 11.
    When im recording my Voice and im using a reverb for it, i just can set the loudness of the reverb. but i want to set the lenght of it, i want to ask you guys how i can do that?
    thanks a lot

    Gern geschehen!    Take good care of the old GarageBand '11 and make sure you back up your system as it is now, just in case!
    i have another question, its almost the same content how is it about the echo? in the older version, i could easily change the type of the echo, for example in which tact it should be or how much it should be repeated and so on.. oh, I wish it wasstill as easy as before!!!
    The Smart Controls will allow you to change some effects on a track, but the available effects will depend on the patch you selected.  Get yourself HangTime's marvellous Effect Finder - this will help you to find out, which patches will have which effects: Download here:  http://www.bulletsandbones.com/GB/File%20Pages/DownloadsGB.html
    For the echo you can also use the automation curve on the track, just like for Reverb.
    -- Léonie

  • How to set field length in Dynamic IT tab

    Hi All,
                 I am creating 1 dynamic internal table with refrence of field catalog, but in the dynamic IT tab and work area i am gettinf field length is 10 char.
    But i want to change this into 15 or 20 char like this....  how can i change this
    Please help me .
    DATA: ep_tab TYPE REF TO data,
          new_line  TYPE REF TO data.
    FIELD-SYMBOLS: <l_table> TYPE table,
                   <l_line>  TYPE ANY.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          I_STYLE_TABLE   = c_char
          it_fieldcatalog = it_fieldcatalog
          I_LENGTH_IN_BYTE = ' '
        IMPORTING
          ep_table        = ep_tab.
      ASSIGN ep_tab->* TO <l_table>.
      CREATE DATA new_line LIKE LINE OF <l_table>.
      ASSIGN new_line->* TO <l_line>.
    This is my code.
    Regards,
    Arjun.

    Hi,
    try this
    ** ALV DECALRATION
    DATA : wa_lvc_cat TYPE lvc_s_fcat,
           gt_lvc_cat TYPE lvc_t_fcat.
    DATA : wa_fieldcat TYPE slis_fieldcat_alv,
           gt_fieldcat TYPE slis_t_fieldcat_alv.
    DATA : wa_slis_layout TYPE slis_layout_alv.
    PERFORM create_dynamic_itab.         " Fill fieldcatlog and create dynamic itab
    *&      Form  CREATE_DYNAMIC_ITAB
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM create_dynamic_itab .
      CLEAR g_pos .
      PERFORM fill_gt_lvc_cat_fld USING 'MATNR' 18 .  "fieldname outputlen.
      PERFORM fill_gt_fieldcat_field USING c_x 'MATNR'  'CHAR' 18   text-006.
      PERFORM fill_gt_lvc_cat_fld USING 'CODE' 40 .
      PERFORM fill_gt_fieldcat_field USING ' ' 'CODE'  'CHAR' 40  text-024.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gt_lvc_cat
        IMPORTING
          ep_table        = new_table.
    ENDFORM.                    " CREATE_DYNAMIC_ITAB
    *&      Form  FILL_gt_lvc_cat_FLD
    *       text
    *      -->P_0006   text
    *      -->P_18     text
    FORM fill_gt_lvc_cat_fld  USING   p_fieldname TYPE any
                                      p_outputlen TYPE any.
      wa_lvc_cat-fieldname =  p_fieldname .  " 'MATNR'
      wa_lvc_cat-outputlen =  p_outputlen.   " 18
      APPEND wa_lvc_cat TO gt_lvc_cat.
      CLEAR wa_lvc_cat.
    ENDFORM.                    " FILL_gt_lvc_cat_FLD
    *&      Form  FILL_GT_FIELDCAT_FIELD
    *       text
    *      -->P_C_X  text
    *      -->P_0012   text
    *      -->P_0013   text
    *      -->P_18     text
    *      -->P_TEXT_006  text
    FORM fill_gt_fieldcat_field  USING    p_key        TYPE any
                                          p_fieldname  TYPE any
                                          p_datatype   TYPE any
                                          p_outputlen  TYPE any
                                          p_seletext_m TYPE any.
      g_pos = g_pos + 1.
      wa_fieldcat-col_pos    = g_pos.        " 1.
      wa_fieldcat-key        = p_key .       " c_x.
      wa_fieldcat-fieldname  = p_fieldname.  " 'MATNR'.
      wa_fieldcat-datatype   = p_datatype.   " 'CHAR'.
      wa_fieldcat-outputlen  = p_outputlen.                     " 18.
      wa_fieldcat-seltext_m  = p_seletext_m. " text-006.   "'Material'.
      APPEND wa_fieldcat TO gt_fieldcat.
      CLEAR wa_fieldcat.
    ENDFORM.                    " FILL_GT_FIELDCAT_FIELD
    PERFORM fill_output_layout.          " Fill the output data into field symbol
    *&      Form  FILL_OUTPUT_LAYOUT
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM fill_output_layout .
      ASSIGN new_table->* TO <fs_table>.
      CREATE DATA new_line LIKE LINE OF <fs_table>.
      ASSIGN new_line->* TO <fs_line>.
      LOOP AT  gt_mseg INTO wa_mseg.
          ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fs_line> TO <fs_field>.
          <fs_field> = wa_mseg-matnr.
        READ TABLE  gt_grdtrans INTO wa_grdtrans WITH KEY mawerk = wa_mseg-WERKS
                                                             matnr  = wa_mseg-matnr
                                                             mat_doc = wa_mseg-mblnr binary search.
            IF sy-subrc = 0.
            LOOP AT gt_qmfe INTO wa_qmfe WHERE qmnum = wa_grdtrans-qmnum.
             READ TABLE gt_qpct2 INTO wa_qpct2 WITH KEY  codegruppe   = wa_qmfe-fegrp
                                                         code        = wa_qmfe-fecod
                                                         BINARY SEARCH .
              IF sy-subrc = 0.
              ASSIGN COMPONENT 'CODE' OF STRUCTURE <fs_line> TO <fs_field>.
              <fs_field> = wa_qpct2-kurztext.
             ENDIF.
             endloop.
             clear wa_qmfe.
            ENDIF.
    ENDLOOP.
        CLEAR wa_mseg.
    PERFORM fill_layout.                 " Filling the layout of REUSE_ALV_GRID_DISPALY
    *&      Form  FILL_LAYOUT
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM fill_layout .
      wa_slis_layout-zebra             = c_x.
      wa_slis_layout-colwidth_optimize = c_x.
    ENDFORM.                    " FILL_LAYOUT
    Edited by: ShaliniSinha on Mar 30, 2009 1:49 PM
    Edited by: ShaliniSinha on Mar 30, 2009 1:55 PM

  • How to set maximum length for TextEdit

    Hi all,
        I have a TextEdit UI element in my webdynpro page and I want to set the maximum number of characters that can be entered in this TextEdit. How can I do this?
    Thanks,
    Satyajit.

    Hi Arun,
         thanks for the reply. But I also want to use the same scenario for an Inputfield. Now I used the same method here and when viewed in the browser, the entire InputField has been stretched. How can I keep the view of the InputField as default but still have a restriction on the number of characters that can be entered in this InputField? It works for TextEdit.
    Thanks,
    Satyajit.

  • How to set field length

    Hi,
    im using sap crystal report version 13.0.2000.0...
    i kept one sting field in details section, in stored procedure its length is 50 characters but in my report it is displaying only 10 characters..how to format this field,is there any formula for this?

    ya i followed your suggestion but im not getting full data in report
    ..this is my stored procedure
    ALTER PROCEDURE [dbo].[GetSecretarywiseConsolidatedPurchases]
         -- Add the parameters for the stored procedure here
         @Fromdate datetime,
         @ToDate datetime,
         @TraderID int
    AS
    BEGIN
              DECLARE @temptb TABLE     
              (TBID int IDENTITY(1,1) NOT NULL,
                   EntDate datetime,
                   BillNo nvarchar(50),
                   URDQuintals Decimal(18,2),
                   URDValue Decimal(18,2),
                   RDQuintals Decimal(18,2),
                   RDValue Decimal(18,2),
                   NLQuintals Decimal(18,2),
                   NLValue Decimal(18,2),
                   ISQuintals Decimal(18,2),
                   ISDValue Decimal(18,2),               
                   MarketFee Decimal(18,2),
                   TraderName nvarchar(100),
                   LicenseNo nvarchar(100)
              --Inserts URD Purchases
              insert into @temptb (EntDate,BillNo,URDQuintals,URDValue,MarketFee)
              (SELECT     Purchase.EntryDate, Purchase.PurchaseBillNo, PurchaseCommodity.Quantity/100, PurchaseCommodity.Value, PurchaseCommodity.ActualMarketFee
                        FROM Purchase  with(nolock) INNER JOIN PurchaseCommodity with(nolock) ON Purchase.PurchaseID = PurchaseCommodity.PurchaseID where
                        TraderID=@traderID and EntryDate>=@Fromdate and EntryDate<=@ToDate and OriginTypeID=1 and purchase.Isdeleted=0)
    Select * from @temptb order by EntDate,BillNo
    and field 'BillNo' is my problem...in sp BillNo showing full data but in report it is  displaying only 10 characters ..
    in sp-->BillNo is 00010050027293
    in report-->0001005002
    Edited by: kiran86 on Feb 3, 2011 11:29 AM
    Edited by: kiran86 on Feb 3, 2011 11:29 AM

  • How to set column size in sqlplus.exe ?

    SQL> select * from dba_cons_columns where user='USER1' and table_name='PARENT1';
    OWNER                          CONSTRAINT_NAME
    TABLE_NAME
    COLUMN_NAME
      POSITION
    USER1                          PARENT1_PK
    PARENT1
    COL2
             2
    OWNER                          CONSTRAINT_NAME
    TABLE_NAME
    COLUMN_NAME
      POSITION
    USER1                          PARENT1_PK
    PARENT1
    COL1
             1doesn't it seems bit ugly to see these data.Why length of columns is so long ?please tell how to set the length of columns and other parameters so that data that is displayed should come out in screen in a well managed and beautiful way.
    Like this:
    OWNER     CONSTRAINT_NAME     TABLE_NAME       COLUMN_NAME   POSITION
    USER1        PARENT1_PK              PARENT1             COL2                  2
    USER1        PARENT1_PK              PARENT1             COL1                  1I have written this by hand. How to get display in sqlplus.exe ?

    This command sets column size for all forthcoming commands. Suppose there is select command for different columns, and i want to set different size for different columns. e.g.,select name,address,zone from table1;
    How can i set column size for name to (say) 20 char, address to 30 char and zone to 3 char ?
    You need to do it in some sort of sql script which would set the column formatting before the query would start and then would clear the formatting after the query gets finished. See an example below,
    SQL> column ename format a20 heading emp_name
    SQL> select ename from emp
      2  ;
    emp_name
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    emp_name
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> column ename clear
    SQL> select ename from emp;
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    ENAME
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL>So likehtis you have to format all the columns on individual lines and then clear the fomattings of each once th query isdone.
    HTH
    Aman....

  • How to set min-password length on ASR1002?

    How to set min-password length on ASR1002?

    Try:
    security passwords min-length
    I'm not positive if it's supported in your version of IOS-XE but it is in some.

  • How to set a JButton,JTextfield, JLabel in a given location

    Hi am designing a login screen and i dont know how to set my JLabels and JButtons on the screen. Can some one pls help
    Thanx
    Edited by: nadeesha on Oct 2, 2007 2:21 AM

    nadeesha
    If you want to really learn, go to the javaTutorial.
    http://java.sun.com/docs/books/tutorial/uiswing/TOC.html
    If you don't want to learn but finish quick, here is :
    For login, you need JDialog, JLabel, JTextField, JButton,
    given location? --> You must know layout. --> if you want to learn go to the link above; learn The best is GridBagLayout.
    if you don't want to learn but finish quick, here is :
    // x, y, width, height  ==> you must put int value 
    class MyDialog extends JDialog {
      this.setLayout(null);
      JLabel myLabel = new JLabel("Login");
      myLabel.setBounds(x, y, width, height);
      myLabel.setBorder(new EtchedBorder()); ---> to see the actual bound of the component.
      JLabel myLabel2 = new JLabel("Password");
      myLabel2 .setBounds(x, y, width, height);
      myLabel2 .setBorder(new EtchedBorder()); ---> to see the actual bound of the component.
      JTextField myLoginTextField1 = new JTextField();  
      myLoginTextField1.setBounds(x, y, width, height);
      JTextField myPasswordTextField2 = new JTextField();
      myPasswordTextField2 .setBounds(x, y, width, height);
      JButton myOKButton = new JButton("OK");
      myOKButton.setBounds(x, y, width, height);
      JButton myCancelButton = new JButton("Cancel");
      myCancelButton.setBounds(x, y, width, height);
    {code}____________________________________________________
    This will do.  Etched border will help you to have proper size. of width and height.
    Play around, you will find fun -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How do I set the length of a podcast?

    How do I set the length of a podcast? I am using Garageband 3.0.2

    Drag the little purple left facing triangle at the top of the timeline to where you want the export to end.
    (Note, GB does impose a minimum length, but I dont' recall what that is at the moment)

Maybe you are looking for

  • A/R and A/P Invoice Draft - Post - Status Tracking

    We post an A/R or A/P Invoice as an Draft Document using DI API, we do this for the convinience of the User to change the Tax components accordingly. Once this is done the draft document is posted as an Invoice and the draft document to be deleted. C

  • Quick question about Time Machineive

    I can't seem to find the answer to this question: can I set up Time Machine to back up an additional external drive in addition to backing up my computer? We keep our media on a separate external drive. I'm looking into buying Leopard in part because

  • Impossible to create process order by MD04

    Hi friends My scenario is that I have a material that can be produced in-house and some times procured externally by subcontracting in material master: Procurement Type = 'X' and Special procurement = '30' The problem is that in transaction MD04 the

  • Need help Linking Images

    I copied and pasted pictures from online into my indesign document. By doing that my document size is over 100mb. I need to reduce the file size. I am trying to reduce the file size because I am working on a project for college and need to submit it.

  • Google / Gchat SMS - Data Plan or Text Message

    I am going to be forced to be on a 250 texts per month plan for work soon. I'm looking for ways around this (since I'll definitely use more than that). One possible option I've found is to use Gchat, and their SMS/texting feature. You can send a mess