How to delete columns in a JTable

hi,
this is the code i tried..
columnModel1.removeColumn(columnModel1.getColumn(i));
but its adding the columns

let's see more of your model code. Please when posting your code, please use code tags so that your code will be well-formatted and readable. To do this, place the tag [code] at the top of your block of code and the tag [/code] at the bottom, like so:
[code]
// your code block goes here.
[/code]

Similar Messages

  • How to delete columns in table control

    hi
    1) I have creted a table control with five columns
    now i want to delted the tow of the five coluent pls let me know how to delete it
    1) also i am useing a module pool programming (code if needed i will paste)
    in that the requirment is to select data from a ztable and aloow user to enter new ship to data only whne the corresponding records exists in kna1 table
    and to populate the name1 value automatically from table kna1 whne user enters ship to number
    pls suggest
    regards
    Arora

    Hello,
    Requirement 1
    i believe you need to delete a row from the control table based on the user input...
    if thats the case then definitely in the control table the multiple line selection will be activated .
    in PAI of the control table screen...
    if user has clicked delete.
    loop at control table records..
    if the selection code for the line is 'X'.
    Delete from the internal table.
    endif.
    endloop.
    endif.
    Requirement 2..
    i will give an outline on the checks
    a)first let the user enter the data...in the PAI of the screen...write the code to do the checking....if your requirement is not satisfied provide a warning/error  message or delete the record and give a message stating the reason for deletion...
    in PAI.
    for a control table...
    loop at the table records
    select from table and check if user record is O.K
    if not delete the record and give message
    endif.
    endloop.
    b)similarly inside the PBO write code to fetch the name1 from Kna1 table for the ship to number if that ship to number is not empty
    in PBO of that screen
    if  ship_to is not initial.
    select text for ship_to number to the display field
    else.
    clear the display field
    endif.
    reward if the suggestions were useful
    Regards
    Byju

  • How To Delete Columns In JTable?

    Hi,
    I created a JTable and added values through DefaultTableModel. I Have JButton to add columns if need. I have another JButton to remove columns by entering the columns header.. eg: If there are three columns like A,B,C, If i need to remove column "C" means. I just click the remove button and enter the column header in the dilaog box eg: "C". and the columns will deleted. It is working properly. but if i add a new column means the removed columns also getting added and the datas are also in that same column. how delete a column and it's data in a single shot.
    How to add network drivers in a save as dialog box. I have using my code in Windows and also in mac os.
    Thanks in Advance
    by,
    Mohan

    One possibility would be to use a DefaultTableModel to store the data but have JTable access it through your own table model which mapped the columns and altered the column count etc..Why go to all that trouble. If you just want to hide a column, then remove the TableColumn from the TableColumnManager.
    The requirement was to remove the data as well.
    Implementing AbstractTableModel is really less hassle than it looks. Generally you only have to override getColumnName, getValueAt, getRowCount, getColumnCount and (usually) getColumnClass.Nobody said it was difficult, by why reimplement everything from scratch? Just extend DTM to add your new functionality.

  • How to delete columns from process form table

    hi,
    I have a process form UD_FN_USR. I created one column userid with type long and later the requirement got changed and I need to change the type to string.I am able to delete the column from design console but in the table the column exits so that I coulnt create the column with same name as type string , its tellling same column name exits with different datatype in current version or previous versions.can anybody please tell me how to solve this issue

    Sorry for late response. Got stuck in work.
    This time it will answered ;-)
    ALTER TABLE UD_ABCD DROP COLUMN UD_ABCD_UID
    DELETE FROM SDC WHERE  SDC_NAME='UD_ABCD_UID';
    COMMIT;
    Thanks
    Rajiv Dewan

  • How to delete columns in table control (tab Services) for transaction ME51

    Hi, gurus!
    We're facing this problem in our upgrade: we have a batch input (ME51) in order to create purchase requisitions, but we get an error with the dynpro data (program: SAPMM06B, dynpro: 0102).
    We are sure we populate all the required fields in that screen.
    The only possible reason we find for that error is the fact  that we have two new entries in table control (in tab services=> Current settings there are 67 fixed columns)
    We had to add in table T162V (which previously had only 65 columns for each variant): ESLL-SRVMAPKEY y ESLL-EXTERNALID, as described on note 1382685, so table control and table T162V could have same number of fields.
    We guess we could solve the batch input error deleting those fields in both table control and T162V, but don't know how.
    We really would appreciate any clue.
    Thanks in advance.
    Best regards,
    J. Madariaga

    It's an own batch input.
    The error is: "Batch input information for dynpro SAPMM06B 0102 does not exist", but the fields in that screen are alright.
    And that batch input works fine in another client with same patch level, but without fields ESLL-SRVMAPKEY and ESLL-EXTERNALID in table T162V, so I guess that could be the problem (not sure about it, of course).
    Regards,
    J Madariaga

  • How to set column alignment in JTable

    I make a table with JTable(Vector a, Vector b).
    I don't know how to set the alignment to right while the column type is Integer or Long.
    Do i have to use JTable(Object[][] a, Object[] b) ?

    Well , you can configure the alignment when you are creating the column, like
    for (int i=0; i<7; i++){
    //Size of cell
    int colunaTam = 50;
    //Define Allingment
    int cellAlinhamento = 4; //Right Aligment
    //Column
    javax.swing.table.TableColumn coluna;
    BusinessObjects.CellColorRenderer renderer = new BusinessObjects.CellColorRenderer();
    //Define alingment in cell render
    renderer.setHorizontalAlignment(cellAlinhamento);
    coluna = new javax.swing.table.TableColumn(i, colunaTam, renderer, null);
    ivjJTableDespachos.addColumn(coluna);
    Hope i help you...
    Ice

  • How to delete columns from a 2D array

    Hi guys,
    I read a matrix from a text file and I want to delete the first and last columns of the matrix. I've been trying to do it with delete from an array function but it doesn't do it the way I want. Any suggestions?

    Keep in mind that by default, 2-D LabVIEW arrays are row-based. So though you might be thinking that the first indexing input for the 'index array' primitive is for columns, it is actually for rows. You can either select the second input for the 'index array', or, if you are like me and think better in columns, you can transpose the array before you operate on it. I recommend getting used to the order of the inputs for the array tools and forcing yourself into the LabVIEW convention, as it gets complicated if you need to invert an array before you operate on it, and then again after so that the array returns to row-centric order, which is what all the rest of the LV array tools are expecting
    Good luck!
    Wes Ramm, Cyth UK
    CLD, CPLI

  • How to delete columns in TextEdit?

    Well, for a "power" user, veteran word processor, table star, help reader, Google user, and board browser, I've been unable to figure this out!
    I also couldn't figure out where to post this (no TextEdit forum!).
    So, what happened was that I copied and pasted several rows and coiumns from a spreadsheet and want to delete couple of the columns. I figured out that one can highlight columns using the option key, but then delete removes the text not the column!
    It's probably something obvious, but I haven't found it!

    Hi
    Does this help, quoting TextEdit Help:
    Adding a table to your document
    You can create tables in TextEdit documents to organize information.
    Place the cursor where you want to add the table.
    Choose Format > Text > Table.
    In the Table window, type the number of rows and columns you want (or use the arrow buttons to add or subtract rows and columns).
    To adjust the height or width of a row or column, place the pointer over the border of a cell. When the pointer changes to a double arrow, drag the border to change the dimensions of the row or column.
    Steve

  • How to change column names in JTable?

    Hi!
    May be, my question is simple, but I still don't know the answer.
    Please help.

    JTableHeader th = table.getTableHeader();
    TableColumnModel tcm = th.getColumnModel();
    TableColumn tc = tcm.getColumn( int ); // the column to change
    tc.setHeaderValue( "New Value" );
    th.repaint();

  • How do i delete multiple rows in JTable

    hello
    how i delete multiple rows in JTable
    when i selected multiple rows from the jtable and delete its give the error ArrayIndexOutOfBoundException
    e.g.
    int rows[]=jtable.getSelectedRows();
    for(int i=0;i<rows.length;i++)
    DefaultTableModel model=(DefaultTableModel)jtable.getModel();
    model.removeRow(rows);
    like this
    please help me
    meraj

    You are trying to remove the rows an equal times to the amount of rows selected.
    You should remove one row at a time:
    model.removeRow(rows);
    Change your code into this.
    for(int i=0;i<rows.length;i++)
    DefaultTableModel model=(DefaultTableModel)jtable.getModel();
    model.removeRow(rows[i]);

  • Dragging columns in a JTable

    how to drag columns in a JTable ?

    JTable myTable = new JTable(mymodel,myheaders);
    JTableHeader head =myTable.getTableHeader();
    //// this function will solve your problem
    head.setReorderingAllowed(true);

  • Setting column names in JTable

    can n e one tell me how to set column names for JTable..
    i don't wanna use the JTable constructor ... cuz
    my column names change...

    this is how i did it once...hope it helps
    Vector columnNames = new Vector();
    JTable previewTable = new JTable();
    previewTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    previewScrollPane.getViewport().add(previewTable, null);
    int colNo = 2; // i am displaying 2 columns
    columnNames.add("Col One");
    columnNames.add("Col Two");
    String[] tableColumnNames = {"Id Name","Type"};
    DefaultTableModel aModel = (DefaultTableModel) previewTable.getModel();
    aModel.setColumnIdentifiers(tableColumnNames);
    //add data to the table
    .//loop
    aModel.addRow(objects);
    previewTable.revalidate();
    previewTable.setModel(aModel);

  • Reg:How to delete the column in table control also from database table.

    Hi Experts,
    Once again thank u all for giving the responses.
    one more doubt is how to delete the columns of table control and also the record shold delete from ztable.
    With Regards,
    Saroja.P.

    Hi,
    If you want to delete the rows in the table control and simultaneously delete it from the database table, then you can implement a 'DELETE' functionality specific to your table control. Have a MARK field (you will find that in the screen attributes of the table control -> give a name for the MARK field, you will find an additional MARK column at the beginning of your table control). You can check whatever rows you want to delete from the table control, call the delete module.
    "This portion of code inside the LOOP...ENDLOOP.
    IF sy-ucomm eq 'F_DELETE'.
       gt_itab2-check = mark.  " Store the MARK field status into your internal table's correspoding field 'check'
      MODIFY gt_itab INDEX tabcontrol-current_line.
    ENDIF.
    iF sy-ucomm eq 'DELETE1'.
      DELETE gt_itab WHERE check eq 'X'. "Your internal table does not have rows that you want to delete
    ENDIF.
    Now you can modify your database table using the MODIFY statement.
    MODIFY ZDB FROM TABLE gt_itab.

  • How to get all the values in one column of a JTable

    How to get all the values in one column of a JTable as a Collection of String.
    I don;t want to write a for loop to say getValueAt(row, 1) eg for 2nd column.

    I don;t want to write a for loop to say getValueAt(row, 1) eg for 2nd column. You could always write a custom TableModel that stores the data in the format you want it. It would probably be about 50 lines of code. Or you could write a loop in 3 lines of code. I'll let you decide which approach you want to take.

  • How Can I set up a JTable columns?

    Dear All,
    How can I set up my JTable columns to have the amount the user specifies?
    for example when the user types in 50 in JTextField 1 I want the JTables columns to then set to 50.
    How can this be done?
    Thanks
    lol
    import javax.swing.*;
    import javax.swing.table.TableModel;
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class si1 extends javax.swing.JFrame implements ActionListener {
        JTextField name = new JTextField(15);
        JTextField name1 = new JTextField(15);
        public si1() {
            super("DataBase Loader");
            setSize(1025,740);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel pane = new JPanel();
            JPanel pane1 = new JPanel();
            JPanel pane2 = new JPanel();
            JPanel pane3 = new JPanel();
            JPanel pane4 = new JPanel();
            pane.setLayout(new GridLayout(20,1));
            pane1.setLayout(new BorderLayout());
            int j=10;
            String[][] data = new String[j][2];
            for (int k=0; k<j; k++){
               String[] row = {"",""};
               data[k] = row;
            String[] columnNames = {"First Name", "Last Name"};
            JTable perstab = new JTable(data, columnNames);
            perstab.setGridColor(Color.yellow);
            perstab.setPreferredScrollableViewportSize(new Dimension(500,500));
            JScrollPane scrollPane = new JScrollPane(perstab);
            pane1.add(new JPanel(), BorderLayout.EAST);
            JButton btn = new JButton("What are the names?");
            btn.addActionListener(this);
            btn.putClientProperty("DATABASE", perstab);
            pane1.add(new JPanel().add(btn), BorderLayout.SOUTH);
            pane2.add(name);
            pane3.add(name1);
            pane.add(pane2);
            pane.add(pane3);
            pane1.add(pane, BorderLayout.WEST);
            pane4.add(scrollPane);
            pane1.add(pane4, BorderLayout.CENTER);
            setContentPane(pane1);
            show();
        public static void main(String[] args) {
            si1 frame = new si1();
            frame.setVisible(true);
        public void actionPerformed(ActionEvent e) {
            JTable table = (JTable)((JButton)e.getSource()).getClientProperty("DATABASE");
            TableModel model = table.getModel();
            int count = model.getRowCount();
            String[] firstnames = new String[count];
            String[] lastnames = new String[count];
            for (int i=0; i < count; i++) {
               firstnames[i] = (String)model.getValueAt(i, 0);
                System.out.println("first name at row " + i + ": " + firstnames);
    lastnames[i] = (String)model.getValueAt(i, 1);
    System.out.println("lastname name at row " + i + ": " + lastnames[i]);

    As you can see I have tried this, but no success.
    If I am doing something wrong please accept my apology, and address me in the right direction.
    Thanks
    Lol
    import javax.swing.*;
    import javax.swing.table.TableModel;
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class si1 extends javax.swing.JFrame implements ActionListener {
        JTextField name = new JTextField(15);
        JTextField name1 = new JTextField(15);
        public si1() {
            super("DataBase Loader");
            setSize(1025,740);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel pane = new JPanel();
            JPanel pane1 = new JPanel();
            JPanel pane2 = new JPanel();
            JPanel pane3 = new JPanel();
            JPanel pane4 = new JPanel();
            pane.setLayout(new GridLayout(20,1));
            pane1.setLayout(new BorderLayout());
            int j=10;
            String[][] data = new String[j][2];
            for (int k=0; k<j; k++){
               String[] row = {"",""};
               data[k] = row;
            String[] columnNames = {"First Name", "Last Name"};
            JTable perstab = new JTable(data, columnNames);
         ((DefaultTableModel)perstab.getModel()).setColumnCount(Integer.parseInt(name.getText()));
            perstab.setGridColor(Color.yellow);
            perstab.setPreferredScrollableViewportSize(new Dimension(500,500));
            JScrollPane scrollPane = new JScrollPane(perstab);
            pane1.add(new JPanel(), BorderLayout.EAST);
            JButton btn = new JButton("What are the names?");
            btn.addActionListener(this);
            btn.putClientProperty("DATABASE", perstab);
            pane1.add(new JPanel().add(btn), BorderLayout.SOUTH);
            pane2.add(name);
            pane3.add(name1);
            pane.add(pane2);
            pane.add(pane3);
            pane1.add(pane, BorderLayout.WEST);
            pane4.add(scrollPane);
            pane1.add(pane4, BorderLayout.CENTER);
            setContentPane(pane1);
            show();
        public static void main(String[] args) {
            si1 frame = new si1();
            frame.setVisible(true);
        public void actionPerformed(ActionEvent e) {
            JTable table = (JTable)((JButton)e.getSource()).getClientProperty("DATABASE");
            TableModel model = table.getModel();
            int count = model.getRowCount();
            String[] firstnames = new String[count];
            String[] lastnames = new String[count];
            for (int i=0; i < count; i++) {
               firstnames[i] = (String)model.getValueAt(i, 0);
                System.out.println("first name at row " + i + ": " + firstnames);
    lastnames[i] = (String)model.getValueAt(i, 1);
    System.out.println("lastname name at row " + i + ": " + lastnames[i]);

Maybe you are looking for

  • How to open a Google popup window for an APEX 3.2.1 aplication ...

    Hi folks, I am implementing an APEX application that presents a report with a search field with a checkbox (search google ON/OFF). If this checkbox is activated by the user and he clicks on GO button, the application will filter the APEX report. At t

  • Is there something wrong with a Oscar Gomez Fuentes 2Channel oscilloscope

    Is there something wrong with a Oscar Gomez Fuentes 2Channel oscilloscope or are my devices configured wrong. I have DAQCard-6036E and SCC-2345 with SCC-Ft01 and SCC-A10 modules. The problem is that when I am measuring with A10 it effects to FT01's R

  • Pdf forms in windows 8?  cannot fill image field

    pdf forms in windows 8?  cannot fill image field

  • Dreamweaver encounted problem and need to close

    Hi, Since yesterday I can't get my CS4 started, I always got the message Dreamweaver CS4 has encounted an error and needs to close, I tried to view the technical information, but I can't understand it. the following doc has been included in the error

  • XQuery Namespace Problem !

    Hello everyone... I'm trying to generate a Xdiff document using XQuery. First, i have tried to generate a static XDiff document using Xquery. I'm getting a problem with namespace. The XQuery I have written is select xmlroot(XMLQuery(' declare namespa