Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8574055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:23:22+00:00 2026-06-11T19:23:22+00:00

I am trying to create an arraylist from the data in my table. I

  • 0

I am trying to create an arraylist from the data in my table. I need to get the values from the visible columns, but I also need to get values from columns that are not visible in the table. Using SWT with a Table Viewer, I have no idea on how to not display columns in my table. I also have no idea on how to pull the data from the table by specifying column names.

I have always used Swing, so I have always used a Table Model Class. In swing it is pretty simple to create the columns, hide them and get data from them.

This is how I have done it in previous Swing projects.

In my table model class:

public String getColumnName(int column) {
  String s = null;

  switch (column) {
     case ITEMID_COL: {
        s = "ItemId";
        break;
     }

Then the getValueAt()

 public Object getValueAt(int row, int column) {
  Object o = null;

  try {
     switch (column) {
        case ITEMID_COL: {
           o = rds.get(row).rev.getItem().getStringProperty("item_id");
           break;
        }

so when I needed the data from my table in any other class, all I had to do was

Object item_id = SingletonSelectTable.getInstance().getValueAt(i, SingletonSelectTable.getInstance().ITEMID_COL);

I could also easily hide columns by setting the MAX_COLUMNS.

Questions:

  1. I need to learn how to add columns to the table that are not going to be displayed but still contain values using a table viewer.

  2. I need to learn how to access the values from the table, so I can create a array of visible and non visible data from the columns.

  3. Is this even possible using a Table Viewer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:23:23+00:00Added an answer on June 11, 2026 at 7:23 pm

    Alright:

    To hide a TableColumn, you can basically set its width to 0 and prevent resizing. Unhide it by setting the width to something >= 0 and enable resizing.

    Since you are using a TableViewer with a ModelProvider, it does not matter that the columns are hidden when you want to access the content. Just get the Object from the model and get your information from it.

    Here is an example that can hide/unhide the columns and still print the currently selected Person:

    public static void main(String[] args) {
        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(2, false));
    
        final TableViewer viewer = new TableViewer(shell, SWT.READ_ONLY);
    
        // First column is for the name
        TableViewerColumn col = createTableViewerColumn("Name", 100, 0, viewer);
        col.setLabelProvider(new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
                if(element instanceof Person)
                {
                    System.out.println("1");
                    return ((Person)element).getName();
                }
                return "";
            }
        });
    
        // First column is for the location
        TableViewerColumn col2 = createTableViewerColumn("Location", 100, 1, viewer);
        col2.setLabelProvider(new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
                if(element instanceof Person)
                {
                    System.out.println("2");
                    return ((Person)element).getLocation();
                }
                return "";
            }
        });
    
        final Table table = viewer.getTable();
        table.setHeaderVisible(true);
        table.setLinesVisible(true);
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.horizontalSpan = 2;
        table.setLayoutData(data);
    
        /* This button will hide/unhide the columns */
        Button button1 = new Button(shell, SWT.PUSH);
        button1.setText("Hide / Unhide");
    
        button1.addListener(SWT.Selection, new Listener() {
    
            @Override
            public void handleEvent(Event arg0) {
                for(final TableColumn column : table.getColumns())
                {
                    if(column.getWidth() == 0)
                    {
                        column.setWidth(100);
                        column.setResizable(true);
                    }
                    else
                    {
                        column.setWidth(0);
                        column.setResizable(false);
                    }
                }
            }
        });
    
        /* This button will print the currently selected Person, even if columns are hidden */
        Button button2 = new Button(shell, SWT.PUSH);
        button2.setText("Print");
    
        button2.addListener(SWT.Selection, new Listener() {
    
            @Override
            public void handleEvent(Event arg0) {
                IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                Person person = (Person) selection.getFirstElement();
    
                System.out.println(person);
            }
        });
    
        viewer.setContentProvider(ArrayContentProvider.getInstance());
    
        final Person[] persons = new Person[] { new Person("Baz", "Loc"),
                new Person("BazBaz", "LocLoc"), new Person("BazBazBaz", "LocLocLoc") };
    
        viewer.setInput(persons);
    
        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }
    
    private static TableViewerColumn createTableViewerColumn(String title, int bound, final int colNumber, TableViewer viewer) {
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
        final TableColumn column = viewerColumn.getColumn();
        column.setText(title);
        column.setWidth(bound);
        column.setResizable(true);
        column.setMoveable(false);
    
        return viewerColumn;
    }
    
    public static class Person {
        private String name;
        private String location;
    
        public Person(String name, String location) {
            this.name = name;
            this.location = location;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getLocation() {
            return location;
        }
    
        public void setLocation(String location) {
            this.location = location;
        }
    
        public String toString()
        {
            return name + " " + location;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am trying to create an ASyncTask that will parse data from an
I am trying to get the data from the webservice and create dynamic custom
I'm running into a problem when trying to create an ArrayList in Java, but
Trying to create a new Dedicated Cache Role in Windows Azure but get the
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
I'm trying to select and get values from customer objects. What I want to
I'm was trying a tutorial to get data to android from a MySQL database
i m trying to get data from my database and present them to a
I am trying to create a method that removes duplicates from a 2d array.
I am trying to create a simple appplication that can read from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.