Change position of Columns in a JTable

Hello together!
I have the follow problem:
I have a JTable and want to change the position of the Columns.
I tryed to remove and add the columns but that doesn't really work, either I have no columns or I have all twice.
If there is any better method to change the position pls let me know, if not pls give me a hint to get it working with deleting and adding.
Thanks a lot.

table.moveColumn(from,to);

Similar Messages

  • How to change width of columns in a JTable component?

    I created JTable1 by dragging from DataControls. I tried to change column width by changing of EntityObject - Width. But it doesn't work. I tried to do it In table binding editor - it doesn't work too.
    Help pls.

    Hello Megadown,
    This is how you can change the width:
    TableColumn column = jTable1.getColumnModel().getColumn(0);
    column.setPreferredWidth(100);
    Regards
    Johan

  • How to Change the position of Column in ALV report

    Hi Follks,
        Is is possible to change the position of column in ALV report?.If yes then how?
        Basically my requirement is, that user want afacility where , he should be able to change the position
        of column aftre he runs the report.
        Eg: After running the report , user felt that column 5 should be at position 2 , in that case he should   
               be able to drag column 5 at position 2 and vice versa.
        Please help me, how to solve this issue.
        Note : I am using NW 7.0 SP 9
        Regards
        PG
    Edited by: PG on Apr 13, 2009 11:10 AM

    HI PG,
    do below whie filling the filed catlog
    wa_fieldcat-fieldname        = 'Field1".
    wa_fieldcat-COL_POS = '1',
    append wa_fieldcat to it_fieldcat.
    wa_fieldcat-fieldname         = 'Field2".
    wa_fieldcat-COL_POS = '2',
    wa_fieldcat-fieldname         = 'Field3".
    wa_fieldcat-COL_POS = '3',
    Thanks!

  • How to change the particular column background  color in jTable?

    I am woking with a project, in which I am using a jTable. Then
    How to change the particular column background color in jTable?

    Use a custom Renderer. This is the JTable tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

  • Change position of a Column in a system matrix

    Hi friends
    i created a user field in table POR1. then in matrix the new fields is displaying in the matrix. can i change position of the matrix column using sdk
    Thanks

    so far as changing of position is concerned, there does not seem to be a way with SDK in runtime. see this thread. David has answered there :):
    How to change the order of the columns in system matrix?
    regards,
    Binita

  • Selective reordering of columns in a Jtable

    Hi
    I have this problem where I need to allow the first 8 columns to be reordered but not the remaining columns in a Jtable.
    I have tried a few approaches by adding listeners to the jtable header and identifying the column which is clicked for reordering and accordingly setting the rearrange policy / feature of the jtable to true/false.
    This works fine in almost all scenarios except for one where the user selects a column which can be reordered and drags it to a position beyond the allowed 8 columns, and now that column is frozen since it is beyond the permissible index of 8.
    I was wondering if there was a 'cleaner'/ better way to go about implementing this.

    Thanks for the link...
    I went through it but seems like a big change for the functionality I want to achieve.
    I am thinking about allowing the user to reorder the column and then if he has chosen an invalid column (one which cannot be rearranged) just undo that action using the moveColumn method.
    I tried overriding the columMoved method to inform me about a column reorder evernt but that method keeps getting fired while the user is rearranging.
    Is there anyway to get a notification once the user is done rearranging the column.
    Thanks

  • Images change position and dimension after client edits on admin console!

    Hi, 
    1. After my client uploaded his images onto the site using the admin console they changed position slightly and did not fit exactually into the image frames i had set when i first made the site.
    2. When i opened the site on muse and merged changes the images positions and dimensions changed even more than what was being diplayed on the live site? (E.g I originally had two columns of square thumbnails for some slideshows and now i have a single column of rectangle images)
    3. I republished to see what would happen it now displays the way it was diplaying in Muse. The site is: www.jacobbuckland.co.uk
    My understanding was that when i create an image frame or gallery in muse that any image uploaded via the admin console should fill that frame no matter what the size or dimensions of that image?
    Any help gratfully received. Thanks

    Our technical team managed to find the immediate cause for the problem, and a solution.
    According to them there was a corruption on a speciffic OLAP file. By deleting it, they allowed it to be recreated on the next application processing. The file in question was found in \Microsoft SQL Server\MSSQL.2\OLAP\Data\UGF.0.db\<APPLICATION>.38.cub.xml
    Where <APPLICATION> is the name of the problematic cube.
    After that everything is working.

  • Setting the Size of a Column in a JTable

    Hi there,
    does anybody knows a way how to set the size of a specified column in a JTable without changinge the size of the other columns?
    thx anyway
    Errraddicator

    You've got to change the JTable's column resizing policy to prevent the other columns resizing:
    JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)Otherwise all the columns will be adjusted to fit into the width of the table - changing one column would have to result in at least one other column changing!
    Hope this helps.

  • Position of columns in a table

    Hello,
    please help me on how to set the position of columns for a table not for a alv-table at a runtime via coding.
    How can we change the positions in ABAP?
    Regards
    Beserithan

    Hi,
    I don't see any partcular method in cl_wd_table_column class for setting column position ( in ALV for class cl_salv_wd_column we have one method for this set_postion ).
    What you can do probably as a workaround is to remove all columns (remove_all_columns of cl_wd_table ) nad then add columns again in code ( new_table_column method of class cl_wd_table_column and then using add_column of cl_wd_table) in whatever order you want.
    Let's see if others can come up with some straightforward solution.
    Regards
    Manas Dua
    Edited by: Manas Dua on Apr 9, 2010 7:24 PM
    Edited by: Manas Dua on Apr 9, 2010 7:53 PM

  • ( im new to java) How do I increase number of columns in a JTable ?

    I am dooing a small calculating program in school and can't figure out how to change the amount of columns in a JTable, my programming skills sofar are extremely basic and therefore we are using the netbeans GUI to create our windows. The code generated by the GUI cannot be edited and I have tried to copy paste the code into Eclipse but it didn't work.
    I have a fair idea of where in the code you can preform the things I want but I need to do it in the grapical interface.
    any suggestions are very much appriciated.

    my programming skills sofar are extremely basic and therefore we are using the netbeans GUI to create our windows.Using and IDE doesn't not make it easier. As you've found out it only makes it harder since you can't edit the code and take full control.
    Read the Swing tutorial, it contains plenty of example for building GUI applications:
    http://java.sun.com/docs/books/tutorial/uiswing/TOC.html
    I don't really understand your question, because if you create the table correctly, then then is no need to increase the number of columns. However, the table does support an addColumn(....) method.

  • Simulating one column using two columns in a JTable

    What I need to do is "join" the two first columns of a JTable...
    What do I mean by saying "join" ?
    I want to make dissapear the right border of the first column, and the same thing for the left border of the second column, also do both things for the column headers of that two columns.
    All that to simulate having one column when there's actually two differents columns.
    How can i do that ? Thanks !

    Make a TableModel that filters your original table model.
    See JTable.setModel.
    public class MergedColumnsTableModel extends javax.swing.table.AbstractTableModel
         javax.swing.TableModel model;
         int[] columnSpans;
          * Assume for simplicity that model does not change (no columns inserted/deleted).
         public MergedColumnsTableModel(javax.swing.TableModel model) {
              this.model = model;
              columnSpans = new int[model.getColumnCount()];
              for (int columnIndex = 0; columnIndex < columnSpans.length; ++columnIndex) {
                   columnSpans[columnIndex] = 1;
         public void merge2(int columnIndex) {
              int leftSpan = columnSpans[columnIndex];
              int rightSpan = columnSpans[columnIndex + leftSpan];
              columnSpans[columnIndex + leftSpan] = 0;
              columnSpans[columnIndex] += rightSpan;
         public int getRowCount() {
              return model.getRowCount();
         public int getColumnCount() {
              int n = 0;
              for (int i = 0; i < columnSpans.length; ++i) {
                   if (columnSpans[i] != 0) {
                        ++n;
              return n;
         public Object getValueAt(int row, int column) {
              int n = 0;
              for (int i = 0; i < columnSpans.length; ++i) {
                   if (columnSpans[i] != 0) {
                        if (n == column) { // We are at the column
                             return model.getValueAt(row, i);
                        ++n;
    }

  • Show hidden columns in a JTable

    Hi,
    I have a requirement for hiding some columns of a JTable and showing them back based on user actions.
    I have gone through some topics about hiding columns. which can be done by table.removeColumn();
    But when I use table.addColumn(); it adds the column at the end of the table.It should add in the same location as the previous column.
    How to show /reveal the hidden column back?.

    * Hide_Columns.java
    * This code contains a table model that allows you to
    * specify the columns to be hidden in a boolean array.
    * To use the model:
    *       model = new MyTableModel(data, columnNames);
    *       table.setModel(model);
    * The most important method in the model is "getNumber()", which converts a column number
    * into the number corresponding to the data to be displayed.
    * Visible columns can be dynamically changed with
    * model.setVisibleColumns(0, column0.isSelected());
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Hide_Columns extends JFrame {
        public Hide_Columns() {
            setTitle("Hide columns");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            model = new MyTableModel(data, columnNames);
            table.setModel(model);
            getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
            for( int i=0; i<4; i++ ){
                final JCheckBox columnX = new JCheckBox("Column "+i);
                columnX.setSelected(true);
                final int col = i;
                columnX.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        model.setVisibleColumns(col, columnX.isSelected());
                toolBar.add(columnX);
            getContentPane().add(toolBar, BorderLayout.NORTH);
            setSize(400,300);
            setLocationRelativeTo(null);
            model.addRow(new Object[]{null,null,null,null});
            model.setValueAt("test0",0,0);
            model.setValueAt("test1",0,1);
            model.setValueAt("test2",0,2);
            model.setValueAt("test3",0,3);
        public static void main(String args[]) { new Hide_Columns().setVisible(true); }
        private JTable table = new JTable();
        private  JToolBar toolBar = new JToolBar();
        private   MyTableModel model;
        /** This is the data of the table*/
        private  Vector<Object> data = new Vector<Object>();
        /** Column names */
        Vector<String> columnNames = new Vector<String>();{
            columnNames.addElement("0");
            columnNames.addElement("1");
            columnNames.addElement("2");
            columnNames.addElement("3");
    class MyTableModel extends DefaultTableModel {
        /** Shows which columns are visible */
        private   boolean[] visibleColumns = new boolean[4];{
            visibleColumns[0] = true;
            visibleColumns[1] = true;
            visibleColumns[2] = true;
            visibleColumns[3] = true;
        public MyTableModel(Vector<Object> data, Vector<String> columnNames){
            super(data, columnNames);
        protected void setVisibleColumns(int col, boolean selection){
            visibleColumns[col] = selection;
            fireTableStructureChanged();
         * This function converts a column number of the table into
         * the right number of the data.
        protected int getNumber(int column) {
            int n = column;    // right number
            int i = 0;
            do {
                if (!(visibleColumns)) n++;
    i++;
    } while (i < n);
    // When we are on an invisible column,
    // we must go on one step
    while (!(visibleColumns[n])) n++;
    return n;
    // *** METHODS OF THE TABLE MODEL ***
    public int getColumnCount() {
    int n = 0;
    for (int i = 0; i < 4; i++)
    if (visibleColumns[i]) n++;
    return n;
    public Object getValueAt(int row, int column) {
    return super.getValueAt(row, getNumber(column));
    public void setValueAt(Object obj, int row, int column) {
    super.setValueAt(obj, row, getNumber(column));
    public String getColumnName(int column) {
    return super.getColumnName(getNumber(column));

  • Position search WebDynpro - position id column blank

    Hello experts,
    On one of my HCM adobe forms, I have a position search button which calls a standard WebDynpro for position search. WebDynpro is using the org view group MSS_POS_SEARCH3 from OADP. When I search for positions using wildcards etc., I am getting the right list but position id column is always blank. When I select a position row, right position id is being passed onto the form. It's just not displaying the position id on the popup even though it has a value. Any thoughts please.

    Hi,
    In CN43N output, press 'Change Layout' button and include Position ID in you layout. Its available in standard report, no development or notes reqd.
    Regards
    Shrikant

  • Is it possible to change nunmber of columns dynamically in table control

    Is it possible to change number of columns dynamically in table control? if so how it could be done?
    Thnaks in advance.
    Sounder

    You can update the table control in your program, the table control is a structure of the type CXTAB_CONTROL of TYPE-POOLS cxtab.
    There you can hide or display column the same way you do for fields in LOOP AT SCREEN. there you will ahve to LOOP AT <control>-COLS.
    TYPE-POOL CXTAB .                                                                               
    TYPES:                                                                               
    BEGIN OF CXTAB_COLUMN,                                                          
             SCREEN      LIKE SCREEN,     "Attributes struktur SCREEN                      
             INDEX       TYPE I,         "Position of a column on the screen               
             SELECTED(1) TYPE C,          "Indicator 'column selected'                     
             VISLENGTH   LIKE ICON-OLENG, "Visualised length of a column                   
             INVISIBLE(1) TYPE C,         "Indicator 'column invisible'                    
           END   OF CXTAB_COLUMN,                                                                               
    BEGIN OF CXTAB_CONTROL,                                                         
             FIXED_COLS    TYPE I, "Number of fixed columns                                
             LINES         TYPE I, "Number of lines to display                             
             TOP_LINE      TYPE I, "Top line during next PBO                               
             CURRENT_LINE  TYPE I, "Current line during LOOP/ENDLOOP                       
             LEFT_COL       TYPE I, "Fist scrollable column after fixed area               
             LINE_SEL_MODE    TYPE I, "Line-selection  : none(0), single(1),               
             COL_SEL_MODE     TYPE I, "Column-selection:        multiple(2)                
             LINE_SELECTOR(1) TYPE C, "Indicator: 'With line-selection col'                
             V_SCROLL(1) TYPE C,            "not used                                      
             H_GRID(1) TYPE C,        "Indicator: 'Horizontal  grid-lines'                 
             V_GRID(1) TYPE C,     "Indicator: 'Vertikal    grid-lines'                    
             COLS      TYPE STANDARD TABLE OF CXTAB_COLUMN                                 
                            WITH NON-UNIQUE DEFAULT KEY,                                   
             INVISIBLE(1) TYPE C,                                                          
           END   OF CXTAB_CONTROL,                                                         
    Regards

  • Problem in updating first column header in JTable

    hi
    I am using JTable in my application. I want to change first column name of JTable every time when a JList is selected. I am using DefaultTableModel for JTable. I added first column in Constructor and another in a method. I have to edit only first column header. How can i do this???
    I used this code but it is not working.
    table.getColumnModel().getColumn(0).setHeaderValue("Name of column");
    table.getTableHeader().resizeAndRepaint();
    Your help will be appreciated.
    Thanks in advance
    Sonal

    table.getColumnModel().getColumn(0).setHeaderValue("Name of column");
    table.getTableHeader().repaint();Works for me so post a SSCCE ( http://www.sscce.org/ ) that shows the problem.

Maybe you are looking for

  • Reset connections in connection pool

    Hi, After DB restart (or connection failure) I try to recover the server. In order to do this, I want to tell to container connection pool to reset (clear) all available connections. Does anybody knows how I can tell to container connection pool to r

  • Clearing out a member values

    I have made a simple form to input percentages in it against entity dimension which has parent-child relationship. All the parents are set to dynamic calc. The issue is that these percentages get added on the parents which gives very bad impression o

  • Photoshop CS3 not working

    Hi, I have CS3, and recently, while working in Photoshop, several functions that would normally be available suddenly didn't work. The most obvious of which was that it did not allow me to set up a new file according to the specifications I would lik

  • Data SIM doesn't work in X1 Carbon 20A7005PMH

    Anyone experience with entering APN and Authentication on Windows 8.1? It prompts me to enter my PIN and then refuses to connect. Then suddenly it says Insert SIM. And then I have to reboot to get the SIM detected again. What I tried: - SIM works in

  • How do I get a playlist of library tracks not in any playlist?

    Howdy, I mostly group my tracks into playlists, but I have so many tracks, it's hard for me to figure out if any tracks are not in at least one playlist. With a smart album, I can do something similar to this in iPhoto, but I can't seem to find a way