JTable - Disable some columns

How should I disable some columns in a JTable so that they cannot be edited at all? The methods provided do this but double clicking the column enables it.

Hi
i dont know whether u r using TableModel or not.
if ur using a customTableModel for ur entries ..
u can implement the following method of
Table Model Interface.
public boolean isCellEditable(int rowIndex,
                              int columnIndex)then implement in such a way that ..
compare always with ur column number and return false.
as follows.public boolean isCellEditable(int rowIndex,
                              int columnIndex){
if (columnIndex ==4 )
return false;
else
return true;
}above code makes all cells in the col=4 uneditable.
even u rearrange the cols in table it works as per documentation.
test this .. and let me know whether u succeeded r not.
note: i think The implementation of this method in AbstractTableModel or defaultTableModel
returns true always.
thanks

Similar Messages

  • Disable some columns in table control?

    Hi
    How to disable some columns in table control.
    For Ex: Table contains 8 columns.
    In first row i want to disable first 4 columns.
    in second row i want to disable last 4 columns.
    In third row i want to disable first 2 and last 2 columns.  How can we achieve this?
    Cheers,
    Venkys.

    HI
    Create three attribute in the node which is bound to the table as data source.
    say pro1, pro2, and pro3 of type wdy_boolean.
    now bind the enabled property of first four column editors to pro1, last 4 to pro2, and pro3 to first 2 and last 2.
    then go to the eventhandler of the dropdown 's on select event and write the code to update the values of these attribute
    according to the selected value.
    here is the sample code.
    DATA lo_nd TYPE REF TO if_wd_context_node.
        DATA lo_el TYPE REF TO if_wd_context_element.
            DATA lv_VAL LIKE ls_dealer1-name.
        lo_nd = wd_context->get_child_node( name = 'DEALER1').
      lo_el = lo_nd->get_element(  ).
        lo_el->get_attribute(
          EXPORTING
            name =  `NAME`
          IMPORTING
            value = lv_VAL ).
         DATA PR1 TYPE WDY_BOOLEAN.
         DATA PR2 TYPE WDY_BOOLEAN.
         DATA PR3 TYPE WDY_BOOLEAN.
      PR1 = ABAP_TRUE.
    PR2 = ABAP_TRUE.
    PR3 = ABAP_TRUE.
    IF LV_VAL EQ 'A'.
    PR1 = ABAP_FALSE.
    PR2 = ABAP_TRUE.
    PR3 = ABAP_TRUE.
       ELSEIF LV_VAL EQ 'B'.
    PR1 = ABAP_TRUE.
    PR2 = ABAP_FALSE.
    PR3 = ABAP_TRUE.
    ELSEIF LV_VAL EQ 'C'.
      PR1 = ABAP_TRUE.
    PR2 = ABAP_TRUE.
    PR3 = ABAP_FALSE.
      ENDIF.
       LO_EL->SET_ATTRIBUTE(
       NAME = 'PRO1'
       VALUE = PR1
       LO_EL->SET_ATTRIBUTE(
       NAME = 'PRO2'
       VALUE = PR2
       LO_EL->SET_ATTRIBUTE(
       NAME = 'PRO3'
       VALUE = PR3
    thanks
    sarbjeet singh

  • How to disable some "columns to display"?

    Hello!
    I have one management pack (it's monitor some our network devices), which was written by contractors for our company. This mp have many unnecessary columns in it's view. I deleted some of these <ColumnInfo> 
    from mp (.xml file). Then I import mp but these columns
    have not disappeared.
    Can anybody help me? What should I do to remove these columns?
    P.S. I know that I can disable them with "Personalize view", but I want to do it
    centralized (all of the console users must see these changes).

    Hi,
    Since the MP was written by contractors, it is better to contact them edit the column.
    Meanwhile, after importing the management pack, please re-create monitor for
    a test.
    Niki Han
    TechNet Community Support

  • Disable first Column in jTable

    Hello people my problem is I use jTable and in the table I need to disable first column so that the user is not able to change edit the values that are listed in this column. Please help me with some code samples if possible. Thanks in advance.

    A custom table model makes this simple. You just override the isCellEditable method and return false when the column index is 0.

  • How could I display some columns in a JTable?

    Help, please:
    I got a Table data(using AbstractedTableModel), and I can display all rows and columns. How can I just display several columns and all rows? Should I delete some columns from table and fireChanges or what? but I need these columns later. Make sense? any ideas?
    Thanks for any helps.
    Royan

    this worked for me,
    import java.util.*;
    import java.io.*;
    import java.net.URL;
    import java.sql.*;
    import javax.swing.table.*;
    import javax.swing.*;
    public class HideTableColumns
          public HideTableColumns()
          private void initialize()
          DefaultTableModel m = new DefaultTableModel();
          try {
             java.util.Vector data = new java.util.Vector();
             java.util.Vector headers = new java.util.Vector();
             String s = "";
             headers.addElement( "OrderID" );
             headers.addElement( "CustomerID" );
             java.util.Vector datum = null;
             datum = new java.util.Vector();
             s = "OrderID";
             datum.addElement( s );
             s = "CustomerID";
             datum.addElement( s );
             data.addElement( datum );
             m.setDataVector( data, headers );
             for( int r = 0; r < m.getRowCount(); r++ )
                for( int c = 0; c < m.getColumnCount(); c++ )
                s = ( m.getValueAt( r, c ) ).toString();
                System.out.println( s );
          } catch( Exception e ) {
             System.out.println(e.getMessage());
             e.printStackTrace();
          JFrame f = new JFrame();
          JPanel p = (JPanel) f.getContentPane();
          JTable tb = new JTable( m );
          TableColumn col = tb.getColumnModel().getColumn(1);
          col.setPreferredWidth(0);
          col.setMinWidth(0);
          col.setMaxWidth(0);
          p.add( tb );
          f.pack();
          f.show();
          public static void main( String[] args )
          HideTableColumns d1 = new HideTableColumns();
          d1.initialize();
    }

  • How to disable sorting for some columns in a ALV GRID?

    Hi i have requirement where I have to disable sorting for some columns in a ALV GRID. i am using REUSE_ALV_GRID_DISPLAY function module.
    Can anybody help me. how to acieve this? Any code snippets will really be appreciated.

    Hi,
    I have tried this but not completely successful. I think this can be done using the OOPS method.
      DATA: it_event_exit TYPE  slis_t_event_exit.
      DATA: w_exit TYPE slis_event_exit.
      w_exit-ucomm = '&ODN'.
      w_exit-before = 'X'.
      CLEAR w_exit-after.
      APPEND w_exit TO it_event_exit.
      w_exit-ucomm = '&OUP'.
      w_exit-before = 'X'.
      CLEAR w_exit-after.
      APPEND w_exit TO it_event_exit.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program          = w_repid
          i_callback_top_of_page      = 'ALV_TOP_OF_PAGE'
          i_callback_html_top_of_page = 'ALV_HTML_TOP_OF_PAGE'
          i_callback_user_command     = 'USER_COMMAND'  <- User command form
          is_layout                   = wm_layout
          it_fieldcat                 = wt_fieldcat
          it_events                   = i_events
          it_event_exit               = it_event_exit    <- Need to fill
          it_sort                     = wt_sort
          i_default                   = 'X'
    Now you can capture this events in the user command
    FORM user_command  USING r_ucomm LIKE sy-ucomm
                             rs_selfield TYPE slis_selfield.
      IF r_ucomm = '&OUP' and rs_selfield-SEL_TAB_FIELD = 'Your field name'.
      ENDIF.
    ENDFORM.                    "user_command
    In this form you will get the function code in 'r_ucomm' and the field selected for sorting in 'rs_selfield-SEL_TAB_FIELD'. But reseting 'r_ucomm' will not work.
    May be somebody else can give some help on this.
    But this will work if you follow the oop method.
    Please see this document for more info.
    http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/an easy reference for alv grid control.pdf
    Thanks
    Vinod

  • Making some columns non-resizable in JTable

    Hi,
    In my Application i need to make some columns non-resizable and some columns needs resizability.
    If anybody done this,please help me.
    Thanks in advance.
    Vattikuti

    Look at some of these
    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=forum%3A57&qt=%2Bjtable+%2Bcolumns+%2Bresizable

  • Disable Aggregation on some columns in Crosstab

    Hello everyone,
    Can somebody let me know how I can control dates being aggretated on a crosstab report? I have a list of items in hierarchy on left axis and I need to get count for those in data point column so users can know how many children each parent has. But they also need the Enabled date and Disabled date columns so they can know if each item is active or not. Since the datapoints will be aggregated in a crosstab report, report displays wrong dates all across. Please suggest.
    Thanks.

    Hi Rod,
    I am sorry for not giving enough details. We have hierarchy in GL Account segment. User wants to maintain a report that gives shows hierarchy changes. I created a report with all 5 levels of accounts on left axis of a crosstab report and added a count column with SUM aggregation so we can see how many children each parent has got.
    Ex:
    100001 - Cash                36
         101000 - Cash equi          20
              101001 - Cash Operating 1
              101002 - Reserved for TL 1
              101003 - Cash Op Trust      1
    Now, I also need to add each account Enabled Date and Disabled Date columns so the report should look like
    100001 - Cash                36 01-Apr-2008 N/A
         101000 - Cash equi          20 01-Apr-2008 N/A
              101001 - Cash Operating 1 01-Apr-2008 N/A
              101002 - Reserved for TL 1 01-Apr-2008 04-Apr-2008
              101003 - Cash Op Trust      1 01-Apr-2008 N/A
    But since I have aggregation on Count, it is also trying to aggregate dates and copy dates from children records to parent records if there is only one date for all its parents or leave it NULL if there are more than one dates in all its child records (this is because of the setting in Discoverer to use NULL if it cannot aggregate the values). So my report is looking like this
    100001 - Cash                36 01-Apr-2008 04-Apr-2008
         101000 - Cash equi          20 01-Apr-2008 04-Apr-2008
              101001 - Cash Operating 1 01-Apr-2008 N/A
              101002 - Reserved for TL 1 01-Apr-2008 04-Apr-2008
              101003 - Cash Op Trust      1 01-Apr-2008 N/A
    How can I change this to show correct dates having counts do the aggregation?
    Thanks for your help in advance.

  • How to disable certain columns of a Table?

    hi all,
    I wish to fill a pattern of 8 digital signals (only 1's & 0's) in a Table.
    Is there any way to restrict the user from typing char or num other than a 1 or a 0?
    Since the table is a string, I'm having confusion how to do this.
    Secondly, the table would have by default 12 columns visible on the Front Panel, excluding both the headers.
    But the No. of Columns is based on a parameter called Duration that ranges between 4 & 256.
    What I want the user to do is to key in 1's & 0's for the Duration chosen.
    Since it'll be tedious to key in for large values of Duration, I've given the option of Set Row(s) & Reset Row(s),
    that will fill with either 1 or 0 respectively for the chosen Row Value.
    Is there any way to disable the remaining columns of the Table, ie, those unfilled columns,
    when the user scrolls horizontally? I don't know how to achieve this.
    I went thro' the Properties of the Table, I don't understand some of their functionalities,
    like SelStart, SelSize etc.
    I wonder why a Property like Disable Array Elements for Arrays is not provided for a Table
    to Disable the columns we want to do so, or is it my gross ignorance, I don't know.
    Experts pls clarify me & help me out.
    Regards,
    Partha.
    - Partha
    LabVIEW - Wires that catch bugs!
    Attachments:
    Set Eventframe1.vi ‏409 KB

    Another option is to do this:
    Slightly more elegant, but also more potential for bugs (e.g. the users can tab into the column).
    craigdobis wrote:
    You can lower your overhead by using these "professional" looking indicators and controls. They are limited in functions and properties, thereby causing a smaller VI in file size.
    Nice. I didn't think about that. Looks like a VI with a single system boolean takes ~20% less space than one with a standard boolean.
    P.S. In general, I would say there are considerably better arguments for using system controls than memory issues.
    Try to take over the world!
    Attachments:
    Disabled Column.png ‏5 KB

  • How to hide some column filter operators in Interactive Report

    Hi,
    I have an APEX 4.2 application what includes Interactive Report page.
    Is there possibilty to hide or disable some filter operators in column filter?
    But I don't want to disable all filter functionality for end users.
    For example how to hide/disable operator "matches regular expression".
    Some filter operators are too complicated for end users.
    I have searhced but not found solution.
    regards,
    Erkki

    erkkik wrote:
    I have an APEX 4.2 application what includes Interactive Report page.
    Is there possibilty to hide or disable some filter operators in column filter?
    But I don't want to disable all filter functionality for end users.
    For example how to hide/disable operator "matches regular expression".
    Some filter operators are too complicated for end users.
    I wouldn't really recommend this. Users will quickly recognise what works for them and avoid options that they do not currently understand. However, over time—through training or advice from more experienced users—they may come to understand and use all of the available features. Blocking access (especially in a non-standard way) to options that users may eventually need is likely to result in unnecessary development work now and at some (possibly inconvenient) time in the future.
    That said, this really isn't difficult to implement using CSS. Use your browser web inspector to identify which filter types are to be blocked, using the value attribute of the filter Operator select list in the generated IR HTML. For example, in APEX 5.0 a filter operator select list looks like:
    <select id="R70597672218719366505_STRING_OPT" class="a-IRR-operator" data-column-type="STRING" title="Operator" name="p_ignore_10" size="1">
      <option value="=">=</option>
      <option value="!=">!=</option>
      <option value="is null">is null</option>
      <option value="is not null">is not null</option>
      <option value="like">like</option>
      <option value="not like">not like</option>
      <option value="in">in</option>
      <option value="not in">not in</option>
      <option value="contains">contains</option>
      <option value="does not contain">does not contain</option>
      <option value="regexp_like">matches regular expression</option>
    </select>
    The "matches regular expression" option has the value regexp_like, so the required CSS rule using the IR operator select list class and an attribute selector on the option value is:
    .a-IRR-operator option[value="regexp_like"] {
      display: none;
    Additional selectors for other filter types can be added to this rule as required, for example:
    .a-IRR-operator option[value="regexp_like"],
    .a-IRR-operator option[value="is not null"] {
      display: none;
    to eliminate the "is not null" filter.
    To implement this for all IRs in your application, create a custom CSS style sheet containing the rule, upload it to your workspace, and reference it in all of the page templates used for IR pages.
    This is not a 100% foolproof solution. CSS is not an appropriate way to implement security restrictions. A web-savvy user could use their web inspector to disable the CSS rule and access the blocked filter(s). However there is little risk here as (1) it appears that your users will lack the required expertise; and (2) doing so will only allow them to further filter data they already have access to.

  • JTable: Easy groupable column headers with hideable columns

    Hi All,
    I have a requirement to make a JTable which displays
    columns with 2 values - a current value and an old one.
    The old value can be hidden or shown by user preference.
    The values are not editable. The 2 values have a single
    heading.
    I've been mucking about with GroupableTableHeader and
    HideableTableColumnModel and all that. This way of
    solving the problem requires siginificant coding.
    Then I had an idea - just use the TableCellRenderer to
    make it look like 2 columns ! This fits my requirements
    and is much simpler.
    So for anyone who has the same requirement, here is
    some sample code. I think you'll all agree that in my
    specific case it is a very good way of providing the needed
    functionality.
    Here is the sample code:
    import javax.swing.*;
    import javax.swing.border.AbstractBorder;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.DefaultTableCellRenderer;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    public class DoubleColumnTable extends JTable {
        private boolean secondValueVisible = true;
        public DoubleColumnTable() {
            super();
            setModel(new AbstractTableModel() {
                public String getColumnName(int column) {
                    return column + "";
                public int getColumnCount() {
                    return 5;
                public int getRowCount() {
                    return 5;
                public Object getValueAt(int rowIndex, int columnIndex) {
                    return new Integer[]{new Integer(rowIndex), new Integer(columnIndex + 10)};
            setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    Integer[] twoValues = (Integer[])value;
                    JPanel panel = new JPanel();
                    if (secondValueVisible) {
                        panel.setLayout(new GridLayout(0, 2));
                        JLabel firstLabel = new JLabel(twoValues[0].toString(), JLabel.CENTER);
                        JLabel secondLabel = new JLabel(twoValues[1].toString(), JLabel.CENTER);
                        secondLabel.setBackground(Color.lightGray);
                        secondLabel.setOpaque(true);
                        secondLabel.setBorder(new LeftBorder());
                        panel.add(firstLabel);
                        panel.add(secondLabel);
                    } else {
                        panel.setLayout(new GridLayout(0, 1));
                        JLabel firstLabel = new JLabel(twoValues[0].toString(), JLabel.CENTER);
                        panel.add(firstLabel);
                    return panel;
        private void toggle() {
            secondValueVisible = !secondValueVisible;
            repaint();
        class LeftBorder extends AbstractBorder {
            public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
                g.setColor(Color.gray);
                g.drawLine(x, y, x, height);
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            frame.setSize(300, 300);
            frame.setLocation(300, 200);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Container contentPane = frame.getContentPane();
            final DoubleColumnTable table = new DoubleColumnTable();
            contentPane.add("North", new JButton(new AbstractAction("Toggle") {
                public void actionPerformed(ActionEvent e) {
                    table.toggle();
            contentPane.add("Center", new JScrollPane(table));
            frame.setVisible(true);
    }Message was edited by:
    NY_Consultant
    Message was edited by:
    NY_Consultant
    Message was edited by:
    NY_Consultant

    This should read
    "I have a table with column headers and a row headers using a single column from a second table."

  • Sort jTable rows by column as Integer value

    Hi all,
    I have problem with sort jTable rows. I have some columns and in first are integer data. jTable sort that as String value..1,10,11,12....2,21, ...
    How can I do that?
    Thanks

    In the future, please post Swing questions to the Swing forum: http://forum.java.sun.com/forum.jspa?forumID=57
    What does the TableModel's getColumnClass method return for that column?

  • How to disable a Column for a particular row in Advanced Tables

    Hi All,
    We are using an Advanced Table for search criteria. Our requirement demands to disable a column (we are using messagechoice item in that column) for only first row. We use standard Add Another Row functionality to add the rows.For the remaining rows it (message choice) should be enabled. Can anyone help me to solve.
    Regards,
    Sundeep

    You can either use a Switcher or OADataBoundVariables for this.
    Please see the section OADataBoundVariable in the dev guide. Based on certain View Attribute value, you can set the specific column in the table as Read Only.
    Switcher can be very similar too. Decide an Attribute for the Switcher and make sure the first row (which you want to disable) has some specific value. All other rows should have some other value. Decode can help you here. Then you would need to create two cases. Under the specific to first row, have a read only item. For the other case, have an enterable item. A little read through of the Switcher chapter in the Dev guide would clarify the doubts if any.
    Regards
    Sumit

  • How do I create a JTable with some empty cells in it?

    I have a three column JTable. The first column is a String showing description. The second column contains numbers (double) and the third column also contains numbers. In some cases not all cells in a row should contain data. So for instance, I could have row one showing only description (a String in the first column), and then row two showing description (a String in the first column) and a number (a double in the second column) in columns one and two respectively. My problem is that, the data gets copied from the cells with data to the cells which are supposed to be empty. So, how do I create a JTable with some empty cells in it.

    I have tried empty strings for those values, but it did not work. My table puts objects in an arraylist called reconciliation. The arraylist takes different objects with the same super class. The code below explains. Are you suggesting I pass null to my constructor?
    JTable table = new JTable(new ReconTableModel());The method below is from the table model
    protected  List<Reconciliation> reconciliation = new ArrayList<Reconciliation>();
    protected void fillModel(){
          reconciliation.add(new CashBook("Cash Book Report"," "," "));
          reconciliation.add(new CheckingBankAccount("Checking Bank Account"," "," "));
          reconciliation.add(new BankBalance("Bank Balance As Per Bank Statement",500," "));
          reconciliation.add(new PaymentVouchers("Payment Voucher Receipt",300," "));
          reconciliation.add(new DepositVoucher("Deposit Voucher Receipt",1000," "));
          reconciliation.add(new ReconciledBalance("Reconcilied Bank Balance",1200," "));
          reconciliation.add(new BalanceAt("Bank Balance At",800," "));
          reconciliation.add(new Difference("Difference",400," "));
          Collections.sort( reconciliation, new Comparator<Reconciliation>(){
          public int compare( Reconciliation a, Reconciliation b) {
            return a.getTransactionName().compareTo( b.getTransactionName());
      }

  • Change the colour of some column headers

    Hello All,
    I have a table with a few columns. I want to colour some of the column headers. I want to do this as these columns represent a KEY.
    Regards,
    Aayush

    Hi Aayush,
    As such there doesn't exist any way to colour only some column <b>headers</b>. The two existing options are :
    1) Show the data of some columns in a different colour. For this use text views (default one) as the column elements, and select one among the few built-in colours for the property 'semanticColor' of the text view.
    2) Attach a small image to the primary column's header, using the 'imageSource' property of the table header.
    Hope this helps,
    Best Regards,
    Nibu.

Maybe you are looking for

  • How to monitor available disk space in archive directory

    I need to monitor the available disk space of the archive directory during a long running PL/SQL program which does a lot of inserts and updates. This program is running in a background session and should regularly check for the available space. If t

  • Best method to load XML data into Oracle

    Hi, I have to load XML data into Oracle tables. I tried using different options and have run into a dead end in each of those. I do not have knowledge of java and hence have restricted myself to PL/SQL solutions. I tried the following options. 1. Usi

  • HT1766 my daughter forgot her passcode for I pod won't connect to itunes

    my daughter forgot her passcode on ipod it won't connect to itunes to backup without passcode

  • FTP Client via iWeb

    Can I use my iWeb site for a FTP Client? I just downloaded Classic FTP for Mac and it's requesting that I designate a 'site'. I'm inexperienced in this area so not sure what I'm supposed to do. Any guidance would be extremely appreciated. Barry

  • Cant get afterburner screen recorder to work

    Hi I can't get the after burner screen video recorder to work. I follow all the steps to creating hotkeys, but my hotkeys stay dead no matter what I do. Can someone trouble shoot me this prob? Been stuck for days with it now. thx