Set the column length in an sql query

Hi,
Is there a way to set the column length in a query without using sqlplus commands like row size and format column.
I'd like to do it just from the sql query itself.
select 'this is a test' from dual; Can I define the width of this column in the select statement
Cheers.

Use RPAD,
SQL> WITH T
  2       AS (SELECT 'this is test' str FROM DUAL
  3           UNION ALL
  4           SELECT 'this is a long test' FROM DUAL
  5           UNION ALL
  6           SELECT 'this is a long long long long test' FROM DUAL)
  7  SELECT RPAD ( str, 20) str,LENGTH( RPAD ( str, 20)) len
  8    FROM T;
STR                         LEN
this is test                 20
this is a long test          20
this is a long long          20
SQL> G.

Similar Messages

  • Resolve column names in a sql Query

    Hi Folks,
         I’m upgrading an application and there are database columns that have major changes that could affect production reports. I would like to survey v$SQL for a few days to see if these columns are affected. Here’s the problem.
    Looking at a SQL query to determine which columns are used is not nearly as easy as it sounds. Are there any oracle functions or 3rd party tools that can be used to list the columns used by a sql query? (this gets extremely tricky when subqueries become involved)
    For instance.
    select
    name, b.dep_id, employee_id
    From emp a
    Inner join v_department b on a.dep_id=b.dep_id
    Columns used:+
    Emp.name+
    Departments.dep_id (under the view)+
    Emp.employee_id+
    Emp.dep_id (from the join)+

    If you're on > 10g, you can use dbms_xplan with "all" option.
    It shows "column projection information" which is exactly what you want.
    UKJA@ukja102> set serveroutput on
    UKJA@ukja102>
    UKJA@ukja102> drop table t1 purge;
    Table dropped.
    Elapsed: 00:00:00.03
    UKJA@ukja102> create table t1(c1 int, c2 int);
    Table created.
    Elapsed: 00:00:00.03
    UKJA@ukja102>
    UKJA@ukja102> explain plan for
      2  select
      3    t1.c1, t1.c2, v.cnt
      4  from t1,
      5    (select /*+ no_merge */ c1, count(*) as cnt
      6        from t1
      7        group by c1) v
      8  where
      9    t1.c1 = v.c1
    10  ;
    Explained.
    Elapsed: 00:00:00.01
    UKJA@ukja102>
    UKJA@ukja102> @plan_all
    UKJA@ukja102> select * from table(dbms_xplan.display(null,null,'all'))
      2  /
    PLAN_TABLE_OUTPUT                                                              
    Plan hash value: 536125944                                                     
    | Id  | Operation            | Name | Rows  | Bytes | Cost (%CPU)| Time     |  
    |   0 | SELECT STATEMENT     |      |     1 |    52 |     6  (34)| 00:00:01 |  
    |*  1 |  HASH JOIN           |      |     1 |    52 |     6  (34)| 00:00:01 |  
    |   2 |   TABLE ACCESS FULL  | T1   |     1 |    26 |     2   (0)| 00:00:01 |  
    |   3 |   VIEW               |      |     1 |    26 |     3  (34)| 00:00:01 |  
    |   4 |    HASH GROUP BY     |      |     1 |    13 |     3  (34)| 00:00:01 |  
    |   5 |     TABLE ACCESS FULL| T1   |     1 |    13 |     2   (0)| 00:00:01 |  
    Query Block Name / Object Alias (identified by operation id):                  
       1 - SEL$1                                                                   
       2 - SEL$1 / T1@SEL$1                                                        
       3 - SEL$2 / V@SEL$1                                                         
       4 - SEL$2                                                                   
       5 - SEL$2 / T1@SEL$2                                                        
    Predicate Information (identified by operation id):                            
       1 - access("T1"."C1"="V"."C1")                                              
    Column Projection Information (identified by operation id):                    
       1 - (#keys=1) "T1"."C1"[NUMBER,22], "T1"."C2"[NUMBER,22],                   
           "V"."CNT"[NUMBER,22]                                                    
       2 - "T1"."C1"[NUMBER,22], "T1"."C2"[NUMBER,22]                              
       3 - "V"."C1"[NUMBER,22], "V"."CNT"[NUMBER,22]                               
       4 - (#keys=1) "C1"[NUMBER,22], COUNT(*)[22]                                 
       5 - "C1"[NUMBER,22]                                                         
    Note                                                                           
       - dynamic sampling used for this statement                                  
    40 rows selected.
    Elapsed: 00:00:00.01
    UKJA@ukja102>
    UKJA@ukja102>
    UKJA@ukja102> @end
    UKJA@ukja102> set echo offDion Cho

  • Increase the column lengths of excel sheet through abap

    I developed a abap program and it was displayed the output.
      So i need to display this out put in excel sheet.
      for that I read the out put and placed in the excel,
    the only problem is the column lengths are small
    after download  i am dragging the each column,
    But i need to increase the each column by the program
       How can I ?
    I am using the following code
          lastline = new_line_c + 13.
          DO .
            READ LINE sy-index LINE VALUE INTO it_read-excel.
            APPEND it_read.
            IF sy-index > lastline.
              EXIT.
            ENDIF.
          ENDDO.
          lastline = new_line_c - 38.
          colm = ( length - 37 ) / 18.
          colm = colm + 4.
          FOR THE EXCEL CONVERTION
          INCLUDE ole2incl.
          DATA: w_cell1 TYPE ole2_object,
          w_cell2 TYPE ole2_object.
    *--- Ole data Declarations
          DATA: h_excel TYPE ole2_object, " Excel object
          h_mapl TYPE ole2_object, " list of workbooks
          h_map TYPE ole2_object, " workbook
          h_zl TYPE ole2_object, " cell
          h_f TYPE ole2_object, " font
          gs_interior TYPE ole2_object, " Pattern
          worksheet TYPE ole2_object,
          h_cell TYPE ole2_object,
          h_merge TYPE ole2_object,
          h_cell1 TYPE ole2_object,
          range TYPE ole2_object,
          h_sheet2 TYPE ole2_object,
          h_sheet3 TYPE ole2_object,
          gs_font TYPE ole2_object,
          flg_stop(1) TYPE c.
    *DATA: t_excel_bckord LIKE t_excel OCCURS 0 WITH HEADER LINE,
    *t_excel_bcklog LIKE t_excel OCCURS 0 WITH HEADER LINE,
    *t_excel_blkord LIKE t_excel OCCURS 0 WITH HEADER LINE.
          TYPES: data1(1500) TYPE c,
          ty TYPE TABLE OF data1.
          DATA: it TYPE ty WITH HEADER LINE,
          it_2 TYPE ty WITH HEADER LINE,
          it_3 TYPE ty WITH HEADER LINE,
          rec TYPE sy-tfill,
          deli(1) TYPE c,
          l_amt(18) TYPE c.
          DATA: BEGIN OF hex,
          tab TYPE x,
          END OF hex.
          FIELD-SYMBOLS: <fs> .
          CONSTANTS cns_09(2) TYPE n VALUE 09.
          ASSIGN deli TO <fs> TYPE 'X'.
          hex-tab = cns_09.
          <fs> = hex-tab.
          DATA gv_sheet_name(20) TYPE c .
    M A C R O Declaration
          DEFINE ole_check_error.
            if &1 ne 0.
              message e001(zz) with &1.
              exit.
            endif.
          END-OF-DEFINITION.
          DATA: xy TYPE i,
                xz TYPE i,
                yz TYPE i,
                ab TYPE i,
                pterm TYPE i.
          IF h_excel-header = space OR h_excel-handle = -1.
    start Excel
            CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
          ENDIF.
    PERFORM err_hdl.
    *--- get list of workbooks, initially empty
          CALL METHOD OF h_excel 'Workbooks' = h_mapl.
    PERFORM err_hdl.
          SET PROPERTY OF h_excel 'Visible' = 1.
    add a new workbook
          CALL METHOD OF h_mapl 'Add' = h_map.
    PERFORM err_hdl.
    *GV_SHEET_NAME = '1st SHEET'.
          gv_sheet_name = 'Price Comparison List'.
          GET PROPERTY OF h_excel 'ACTIVESHEET' = worksheet.
          SET PROPERTY OF worksheet 'Name' = gv_sheet_name .
          index1 = 3.
          LOOP AT it_read.
           heading
            IF sy-tabix < 4.
              it_item = it_read.
              IF  it_item CS '-----'.
                CLEAR it_item.
                APPEND it_item.
              ELSE.
                IF sy-tabix = 1.
                  it_item+0(1) = deli.
                ENDIF.
                APPEND it_item.
              ENDIF.
            ENDIF.
           headear data and item
            IF sy-tabix > 4 AND sy-tabix < descline1.
              it_item = it_read.
              IF it_item CS '----'.
              ELSE.
                REPLACE ALL OCCURRENCES OF sy-vline IN it_item WITH deli.
                APPEND it_item.
              ENDIF.
            ENDIF.
            xy = 2.
            xz = 38.
           discount etc
            IF sy-tabix >= descline1 AND sy-tabix < descline.
              it_item = it_read.
              it_item+12(1) = deli.
              it_item+22(1) = deli.
              it_item+43(1) = deli.
              WHILE xy < colm.
                xz = xz + 18.
                it_item+xz(1) = deli.
                xy = xy + 1.
              ENDWHILE.
              APPEND it_item.
            ENDIF.
          payment terms
            xy = 2.
            xz = 37.
            pterm = descline + 6.
            IF sy-tabix > descline AND sy-tabix < pterm.
              it_item = it_read.
              IF it_item CS '-----'.
                CLEAR it_item.
                APPEND it_item.
              ELSE.
                it_item+12(1) = deli.
                it_item+15(1) = deli.
                it_item+36(1) = deli.
                WHILE xy < colm.
                  xz = xz + 17.
                  it_item+xz(1) = deli.
                  xy = xy + 1.
                ENDWHILE.
                APPEND it_item.
              ENDIF.
            ENDIF.
         prepared by
            lastline = pterm + 3.
            IF sy-tabix >= pterm AND sy-tabix <= lastline.
              it_item = it_read.
              IF it_item CS '-----'.
              ELSE.
                it_item+0(1) = deli.
                it_item+54(1) = ' '.
                it_item+16(1) = deli.
                APPEND it_item.
              ENDIF.
            ENDIF.
           remaarks
            yz = lastline + 10.
            IF sy-tabix > lastline AND sy-tabix <= yz.
              it_item = it_read.
              it_item+0(1) = deli.
              it_item+54(1) = ' '.
              APPEND it_item.
            ENDIF.
      approved by
            ab = yz + 5.
            IF sy-tabix > yz AND sy-tabix < ab.
              it_item = it_read.
              IF it_item CS '-----'.
              ELSE.
                it_item+0(1) = deli.
                it_item+54(1) = ' '.
                it_item+14(1) = deli.
                APPEND it_item.
              ENDIF.
            ENDIF.
          ENDLOOP.
    *--Formatting the area of additional data 1 and doing the BOLD
          CALL METHOD OF h_excel 'Cells' = w_cell1
            EXPORTING
            #1 = 1
            #2 = 1.
          CALL METHOD OF h_excel 'Cells' = w_cell2
            EXPORTING
            #1 = 1
            #2 = colm.
          CALL METHOD OF h_excel 'Range' = h_cell
            EXPORTING
            #1 = w_cell1
            #2 = w_cell2.
    *CALL METHOD OF gs_cells 'Select' .
          GET PROPERTY OF h_cell 'Font' = gs_font .
          SET PROPERTY OF gs_font 'Bold' = 1 .
    *Bold for the second row
          CALL METHOD OF h_excel 'Cells' = w_cell1
            EXPORTING
            #1 = 2
            #2 = 1.
          CALL METHOD OF h_excel 'Cells' = w_cell2
            EXPORTING
            #1 = 1
            #2 = colm.
          CALL METHOD OF h_excel 'Range' = h_cell
            EXPORTING
            #1 = w_cell1
            #2 = w_cell2.
    *CALL METHOD OF gs_cells 'Select' .
          GET PROPERTY OF h_cell 'Font' = gs_font .
          SET PROPERTY OF gs_font 'Bold' = 1 .
    *Bold for the fourth row
          CALL METHOD OF h_excel 'Cells' = w_cell1
            EXPORTING
            #1 = 4
            #2 = 1.
          CALL METHOD OF h_excel 'Cells' = w_cell2
            EXPORTING
            #1 = 1
            #2 = colm.
          CALL METHOD OF h_excel 'Range' = h_cell
            EXPORTING
            #1 = w_cell1
            #2 = w_cell2.
    *CALL METHOD OF gs_cells 'Select' .
          GET PROPERTY OF h_cell 'Font' = gs_font .
          SET PROPERTY OF gs_font 'Bold' = 1 .
    *Bold for the fifth row
          CALL METHOD OF h_excel 'Cells' = w_cell1
            EXPORTING
            #1 = 5
            #2 = 1.
          CALL METHOD OF h_excel 'Cells' = w_cell2
            EXPORTING
            #1 = 1
            #2 = colm.
          CALL METHOD OF h_excel 'Range' = h_cell
            EXPORTING
            #1 = w_cell1
            #2 = w_cell2.
    *CALL METHOD OF gs_cells 'Select' .
          GET PROPERTY OF h_cell 'Font' = gs_font .
          SET PROPERTY OF gs_font 'Bold' = 1 .
    *Bold for the sixth row
          CALL METHOD OF h_excel 'Cells' = w_cell1
            EXPORTING
            #1 = 6
            #2 = 1.
          CALL METHOD OF h_excel 'Cells' = w_cell2
            EXPORTING
            #1 = 1
            #2 = colm.
          CALL METHOD OF h_excel 'Range' = h_cell
            EXPORTING
            #1 = w_cell1
            #2 = w_cell2.
    *CALL METHOD OF gs_cells 'Select' .
          GET PROPERTY OF h_cell 'Font' = gs_font .
          SET PROPERTY OF gs_font 'Bold' = 1 .
          DATA l_rc TYPE i.
          CALL METHOD cl_gui_frontend_services=>clipboard_export
            IMPORTING
              data                 = it_item[]
            CHANGING
              rc                   = l_rc
            EXCEPTIONS
              cntl_error           = 1
              error_no_gui         = 2
              not_supported_by_gui = 3
              OTHERS               = 4.
          CALL METHOD OF h_excel 'Cells' = w_cell1
            EXPORTING
            #1 = 1
            #2 = 1.
          CALL METHOD OF h_excel 'Cells' = w_cell2
            EXPORTING
            #1 = 1
            #2 = 1.
    PERFORM err_hdl.
          CALL METHOD OF h_excel 'Range' = range
            EXPORTING
            #1 = w_cell1
            #2 = w_cell2.
          CALL METHOD OF range 'Select'.
    PERFORM err_hdl.
          CALL METHOD OF worksheet 'Paste'.
    PERFORM err_hdl.
    CALL METHOD OF h_excel 'QUIT'.
          FREE OBJECT h_zl.
          FREE OBJECT h_mapl.
          FREE OBJECT h_map.
          FREE OBJECT h_excel.

    Hello Ravi,
    Thank you very much for your suggestions.. but still have some more doubts:
    What i want to do is :
    -->call report in background job with a selection criteria.
    -->the output of the report should be trasnsfered to excel sheet
    -->then the excel sheet should be sent to XI..
    My doubts are:
    -> is it possible with every report or we need some extra code to achieve this
    -> If yes, then how exactly it should be done. can you please explain in more detail.
    Thank you very much for your help.
    Best Regards,
    Jasmeet

  • How to set the bit length of the RSA key in ILOM?

    It is possible to generate new SSH keys for the ILOM.
    set /SP/services/ssh generate_new_key_type=rsa
    set /SP/services/ssh generate_new_key_action=true
    I noticed that the default length is 1024 bit. How to define a key with 2048 bits?

    Hi,
    According to your post, my understanding is that you want to set the column order of a sealed column in a custom Content Type for the new item form NewDocSet.aspx.
    Per my knowledge, if you have Content Type management enabled for the list or library (if you see a list of content type with the option to add more), the display order of columns is set for each content type.
    Drill down into one of them and you'll see the option under the list of columns for that content type.
    To apply the column order in the NewDocSet.aspx page, you need to:
    Select Site Settings, under Site Collection Administration, click Content type publishing. In the Refresh All Published
    Content Types section, choose Refresh all published content types on next
    update.
    Run two timer jobs(Content Type Hub, Content Type Subscriber) in central admin(Central Administration--> Monitoring--> Review timer jobs).
    More information:
    http://sharepoint.stackexchange.com/questions/95028/content-types-not-refreshing-on-sp-online
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Set the column name of a table in a list box

    is there any code to set the column name of a table in a list box at oracle devloper 6i?
    pls help.

    I dont want to go for pl/sql . It should work any table.You want Dynamic SQL without using PL/SQL? Tricky. I'm sure there's a possible way using some very complex and convoluted XML functionality of SQL but in reality you are asking for something that isn't natural to SQL queries, especially if you are expecting a dynamic number of columns to be produced for each row of data. SQL expects a table structure, including output formats, to be a defined number of columns with any number of rows, not a defined number of rows with any number of columns.
    Perhaps if you explain why you need this sort of functionality then we may be able to offer a better solution.
    ;)

  • How to set the maximum length that a user can enter in Msgstyledtextinput

    Hi Everyone,
    I'm currently using EBS 11.5.1 and 10.2g DB
    Is there a way that I can set the maximum length that a user can input?
    I changed the Maximum Length to lower number (from 150 to 100) but I get the following error.
    Developer Mode Exception encountered in item SaveLocation
    Error: The item SaveLocation has a maximum length (100)
             which is not equal to that of the corresponding VO attribute
           , SaveLocation length (150).
    Action: Make sure they are equal in size. There must be other way to set that value
    Thanks,
    Elmer

    You have to set the maximum length of column to 150 to avoid this error.
    You can set the same in Jdev.
    Thanks
    --Anil                                                                                                                                                                                                                                                       

  • How to set the column order of a sealed column in a custom Content Type for the new item form NewDocSet.aspx?

    Dear SharePoint Developers,
    Please help.
    I need to know How to set the column order of a sealed column in a custom Content Type for the new item form NewDocSet.aspx?
    I think this is a "sealed column", whatever that is, which is  shown in SPD 2013 as a column of content type "document, folder, MyCustomContentType".
    I know when I set the column order in my custom Content Type settings page, it is correct.
    But, when I load the NewDocSet.aspx page, the column order that I set in the settings page is NOT used for this "sealed column" which is bad.
    Can you help?
    Please advise.
    Thanks.
    Mark Kamoski
    -- Mark Kamoski

    Hi,
    According to your post, my understanding is that you want to set the column order of a sealed column in a custom Content Type for the new item form NewDocSet.aspx.
    Per my knowledge, if you have Content Type management enabled for the list or library (if you see a list of content type with the option to add more), the display order of columns is set for each content type.
    Drill down into one of them and you'll see the option under the list of columns for that content type.
    To apply the column order in the NewDocSet.aspx page, you need to:
    Select Site Settings, under Site Collection Administration, click Content type publishing. In the Refresh All Published
    Content Types section, choose Refresh all published content types on next
    update.
    Run two timer jobs(Content Type Hub, Content Type Subscriber) in central admin(Central Administration--> Monitoring--> Review timer jobs).
    More information:
    http://sharepoint.stackexchange.com/questions/95028/content-types-not-refreshing-on-sp-online
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Set the maximum length of textedit element in webdynpro

    Hi All,
      How to set the maximum length of texedit element to a some constant characters.setting col and row property to 10 and 2 didnot set max length to 40.setting width and height also didnt helped to limit the characters user can enter to 20.
    Thanks,
    pkv

    >
    pkv wrote:
    > Hi All,
    >
    >   How to set the maximum length of texedit element to a some constant characters.setting col and row property to 10 and 2 didnot set max length to 40.setting width and height also didnt helped to limit the characters user can enter to 20.
    >
    > Thanks,
    > pkv
    Hi,
    Setting row and height is for layout purposes and not for the limiting of text in a TextEdit UI Element.
    To ensure that the Text Exit has only 40 characters in 04s - you can do as Alka has suggested.
    For doing the same in CE 7.1 - you can use the onChange Action and write code inside that method to limit the number of characters.
    I would suggest that you use IWDMessageManager to show a message in the MessageTray whenever the user goes over the limit of 40 characters - rather than accept the whole text and then show some sort of popup.
    Thanks.
    p256960

  • How do I set the column content to automatic break lines

    Hello Guys,
    I have a problem with the column width and the column content of a standard report. Within the report are hugh entries which aren't interrupted by an space character. I set my column width to a special value by usingen "css style: display block; width: 300px;". Now the problem is that some of the column entries have a longer width than the column width is setted. So they overlock the entries of the column next to them.
    My question is: How do I set the column content to automatic break lines after a certain count of characters?
    After researching a couple of websites and discussion thread I found maybe a reference to the solution. I hope it help you to give me an answer.
    COLUMN LAST_NAME FORMAT A4
    regards
    wderr

    Wderr,
    PDFs are another animal entirely. Try adjusting the width of the column under the Print Attributes tab of the report.
    If that doesn't work you'll probably need to create custom XSL-FO layouts which, depending on the tools you have at your disposal, could take some time.
    Regards,
    Dan
    Blog: http://DanielMcGhan.us/
    Work: http://SkillBuilders.com/

  • How to decrease the column length in working time (CATS) table

    Hi all,
    Can you please tell me how we can decrease the column length in CATS table in the portal. Is it something we can do in webdynpro or in the back end.
    Thanks in advance.
    RK Reddy

    I was looking for something similar and ran across OSS Note 989453. I would recommend checking out this note to see if it helps. Apparently, there is a JAVA program error that makes the columns wider than they need to be.
    We have not yet tried this so if you happen to use it, let me know how it works for you.
    Mark Musser
    County of Sacramento

  • New to portal: Setting the column width in portal QBE report

    I'm trying to set different widths to different columns in the QBE report. One of the columns in the report contains long descriptive text. With the default column width the reports runs into many pages and user has to scroll a lot. I would like to set the column width for this column so that it does not wrap for every 2/3 words. In the customization tab, I'm setting the width type to "Char" and selecting the number of characters to be displayed in that coulmn. Percent/pixel width type also didn't help. Should I set the Header width also?. I'm not sure where to set this header column width.QBE report just ignores these customization parameters and displays the report in default format. Please let me know if you have any idea/solution to this problem.
    Thanks
    Surya

    Hi,
    This is a bug and has been fixed 30984.
    Thanks,
    Sharmila

  • How to set the column table so it can not be moved !

    how to set the column table so it can not be moved !

    m_table.getTableHeader().setReorderingAllowed(false);
    m_table.getTableHeader().setResizingAllowed(false);

  • Set the column order in document library using power shell

    hi all,
     am looking for a power shell script which set the column order in the document  library, when i try to upload a  document.
     ie; i am  uploading a  doc to the doc lib. which has the below columns:
     columnA -   [choice field  - mandatory ]
     columnB -   [lookup field  - mandatory ]
     columnC -   [single line of text  - optional ]
     columnD -   [choice field  - optional ]
     columnE -   [choice field  - mandatory ]
    now when  the end user uploads a   document in my doc lib, i would like to see the mandatory columns takes up the top order and then optional fields.
     columnA
     columnB
     columnE
     columnC
     columnD
    so, is there any script, through which i can set the mandatory columns which will be coming in top and the optional fields as next order

    This is sample PowerShell code to reorder fields in a content type of a list.
    $web = Get-SPWeb http://aissp2013/sites/TestSite
    $list = $web.Lists["MyList"]
    $contentType = $list.ContentTypes | where {$_.Name –eq "MyTestCT"}
    $ctArray = "Title","ColumnA","ColumnB","ColumnD","ColumnC"
    $contentType.FieldLinks.Reorder($ctArray)
    $contentType.Update()
    Blog | SharePoint Learnings CodePlex Tools |
    Export Version History To Excel |
    Autocomplete Lookup Field

  • Is there a way to set the default length of appointments/events to 1 hour?

    Is there a way to set the default length of appointments/events to 1 hour?

    No, there's not a way to do that, but it's a good feature request. You can submit feature requests here:
    http://www.adobe.com/go/wish

  • JTextField - Setting the column size doesn't work. Help, please.

    Hi,
    I want to set the column size of a text field from another text field by the input from the user. However, it just doesn't work. The following is my code. Just check out the last anonymous inner class action listener. Somehow i can get the user text, but it just doesn't work.
    Thanks for any helpful inputs.
    * Introduction to Java Programming: Comprehensive, 6th Ed.
    * Excercise 15.11 - Demonstrating JTextField properties, dynamically.
    * @Kaka Kaka
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.Border;
    import javax.swing.border.LineBorder;
    import javax.swing.border.TitledBorder;
    public class Ex15_11 extends JFrame{
        // Create two text fields and three radio buttons
        private JTextField jtfUserText = new JTextField(10);
        private JTextField jtfColumnSize = new JTextField(new Integer(10));
        private JRadioButton jrbLeft = new JRadioButton("Left");
        private JRadioButton jrbCenter = new JRadioButton("Center");
        private JRadioButton jrbRight = new JRadioButton("Right");
        public static void main(String[] args){
            Ex15_11 frame = new Ex15_11();
            frame.pack();
            frame.setTitle("Excercise 15.11 - Text Field Property");
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        // Start of Constructor
        public Ex15_11(){
            // Set the the frame layout
            setLayout(new BorderLayout(5, 5));
            // Create three panels and two labels
            JPanel jpText = new JPanel();
            JPanel jpHorizontalAlignment = new JPanel();
            JPanel jpColumn = new JPanel();
            JLabel jlblTextField = new JLabel("Text Field");
            JLabel jlblColumn = new JLabel("Column Size");
            // Create a button group for the radio buttons to be grouped
            ButtonGroup group = new ButtonGroup();
            // Group the radio buttons
            group.add(jrbLeft);
            group.add(jrbCenter);
            group.add(jrbRight);
            // set a titled border for a panel
            jpHorizontalAlignment.setBorder(new TitledBorder("Horizontal Alignment"));
            // Create a line border
            Border lineBorder = new LineBorder(Color.BLACK, 1);
            // the all the components to their corresponding panels
            jpText.add(jlblTextField);
            jpText.add(jtfUserText);
            jpHorizontalAlignment.add(jrbLeft);
            jpHorizontalAlignment.add(jrbCenter);
            jpHorizontalAlignment.add(jrbRight);
            jpColumn.setBorder(lineBorder);
            jpColumn.add(jlblColumn);
            jpColumn.add(jtfColumnSize);
            // add the panels to the frame
            add(jpText, BorderLayout.NORTH);
            add(jpHorizontalAlignment, BorderLayout.WEST);
            add(jpColumn, BorderLayout.EAST);
            jrbLeft.addActionListener(new ActionListener(){
                // Handle event
                public void actionPerformed(ActionEvent e) {
                    jtfUserText.setHorizontalAlignment(SwingConstants.LEFT);
            jrbCenter.addActionListener(new ActionListener(){
                // Handle event
                public void actionPerformed(ActionEvent e) {
                    jtfUserText.setHorizontalAlignment(SwingConstants.CENTER);
            jrbRight.addActionListener(new ActionListener(){
                // Handle event
                public void actionPerformed(ActionEvent e) {
                    jtfUserText.setHorizontalAlignment(SwingConstants.RIGHT);
            // Register the listener for the coloum size
            jtfColumnSize.addActionListener(new ActionListener(){
                // Handle event
                public void actionPerformed(ActionEvent e) {
                    System.out.println(Integer.parseInt(jtfColumnSize.getText()));
                    jtfUserText.setColumns(Integer.parseInt(jtfColumnSize.getText()));
    }Edited by: ChangBroot on Dec 16, 2008 6:13 PM

    don't forget to revalidate the JPanel after changing the components it holds:
        jtfColumnSize.addActionListener(new ActionListener()
          // Handle event
          public void actionPerformed(ActionEvent e)
            System.out.println(Integer.parseInt(jtfColumnSize.getText()));
            jtfUserText.setColumns(Integer.parseInt(jtfColumnSize.getText()));
            jpText.revalidate();
        });This will tell the jpText JPanel's layout manager to relayout the components that this JPanel holds. It should resize your JTextField. Note that in order to call this from within the anonymous inner ActionListener jpText will need to be declared "final". Either that or declared as a class field.

Maybe you are looking for

  • CSS Layout in DW CS 3

    I'm kinda wondering why the id's are preceded with a class if you open any of the premade CSS layouts in DW CS3. example: Two Columns, all widths in percent, with right sidebar header and footer. CSS: body { font: 100% Verdana, Arial, Helvetica, sans

  • Can't update my IPod Touch because I have to enter in a passcode but it wont let me on my Ipod

    Okay so I turn on my IPod Touch today and their is a message saying I need to plug it into ITunes. I plug it in but ITunes says that I need to enter in a passcode to my IPod because it is locked. I can't do this because the screen is still up on my I

  • EAS stopped communication with Shared Services

    All of a sudden my EAS seemed to have stoppped communicating with Shared Services. I can log into the EAS console, but cannot do the following: 1. I cannot open calculation scripts to edit them. 2. After I try to open one, it then logs me out complet

  • Bug or feature : ref to decorations?

    Hi, The LV manual is mentions, under 'Selection List (Panel)' : Decorations Readonly Array of references to the decorations in the panel. All Objects Read only Array of references to all the objects (controls and decorations) in the pane. Selection L

  • FAQ:  HR-OCI 4.6 (Human Resources, Organizational Charting Interface )

    Welcome to HR-OCI 4.6 (Human Resources, Organizational Charting Interface ) forum! This forum is actively monitored and moderated by SAP Integration and Certification Center (ICC). Frequently Asked Questions: ====================================== Q1