How to disable horizontal scroll bars in the swt table?
Asked Answered
K

6

6

To disable vertical scroll bar i used the following syntax

table.getHorizontalBar().setEnabled(false);

But it is not working. It is ruining my application ui. How can i disable it?

Kieserite answered 2/4, 2012 at 13:26 Comment(3)
What is the problem exactly? There is an almost useless scrollbar (almost nothing to "scroll"), or you have problems with the width of the columns?Garnishment
snippet may be useful, but please consider platform dependent issuesGarnishment
How to control the scrollbars of a Table in SWT.Arillode
M
6

You can't prevent the Table from showing its scrollbars if it wants to. However, if you give the table the space it requires, it should not have to display any scrollbars.

Note: You can simply use SWT.NO_SCROLL in the constructor but if you want to update it later it won't be possible.

Mistranslate answered 2/4, 2012 at 15:56 Comment(0)
G
15

Use option SWT.NO_SCROLL and SWT.V_SCROLL while constructing the table as following:

new Table (shell, SWT.NO_SCROLL | SWT.V_SCROLL);
Greeneyed answered 7/12, 2013 at 6:6 Comment(0)
M
6

You can't prevent the Table from showing its scrollbars if it wants to. However, if you give the table the space it requires, it should not have to display any scrollbars.

Note: You can simply use SWT.NO_SCROLL in the constructor but if you want to update it later it won't be possible.

Mistranslate answered 2/4, 2012 at 15:56 Comment(0)
A
1

ScrollBar / Table position synchronization in Java SWT turorial

Probably, if you you want to disable a scrollbar, it means you want to synchronize the content with something else. Here is example how to do it with two tables, where content of main table called tableExcel is mirrored in extra table called tableRow (please, be aware the code may not be perfect, because I am beginner):

*Note: the code is not complete & shows only key things (beginners, please use Window Builder and then edit/add code):

1) As ankur.trapasiya mentioned, do this:

tableRow = new Table(sashFormExcel, SWT.BORDER | SWT.VIRTUAL | SWT.NO_SCROLL);

2) And (SWT.VIRTUAL will be required to do the workaround, and to load tables fast, it will load what you see & where you scroll)

tableExcel = new Table(sashFormExcel, SWT.BORDER | SWT.VIRTUAL);

3) Because I used sash-form for better navigation, insert this above point 1:

SashForm sashFormExcel = new SashForm(sashForm_Main, SWT.NONE);

4) Then implement this (after point 3):

synchronizer synchronize = new synchronizer(tableRow, tableExcel); tableExcel.getVerticalBar().addSelectionListener(synchronize);

5) Add this class (will synchronize the tables content position):

class synchronizer implements SelectionListener
{
Table t1, t2;

public synchronizer(Table tableRow, Table tableMain)  
{  
    t1 = tableRow;
    t2 = tableMain;  
}  

@Override
public void widgetSelected(SelectionEvent e) {
    t1.setTopIndex(t2.getTopIndex());
}

@Override
public void widgetDefaultSelected(SelectionEvent e) {
    // TODO Auto-generated method stub
}  

}

6) And after point 2, add this (it will make to load main table fast, and will also synchronize your table where scroll bar is disabled):

        tableExcel.addListener( SWT.SetData, new Listener() {
        public void handleEvent( Event event ) {
            TableItem item = (TableItem) event.item;
            int index = event.index;
            int page = index / PAGE_SIZE;
            int start = page * PAGE_SIZE;
            int end = start + PAGE_SIZE;
            end = Math.min (end, virtTableExcel.size());
            for (int i = start; i < end; i++) {
                item = tableExcel.getItem (i);
                item.setText (virtTableExcel.get(i));
                tableRow.getItem(i).setText(Integer.toString(i));
            }
        }
    });
  1. And on top of code, add this: private static Table tableExcel; ArrayList<String[]> virtTableExcel = new ArrayList<String[]>(); final int PAGE_SIZE = 64; private Table tableRow;

  2. As it is mentioned in point 7, you take data from array list virtTableExcel, but to trigger point 6, use this (somewhere in code, after you generated virtTableExcel with data), where rowMax is integer which is equal to virtTableExcel.size(); :tableExcel.setItemCount(rowMax); tableRow.setItemCount(rowMax);

Please, don't blame me for code, I used it from my application. But, all these bits might be useful for other beginners.

Ahmad answered 2/7, 2012 at 2:25 Comment(0)
L
1

What work for me:

When declaring the TableViewer I do this:

this.viewer.getTable().getHorizontalBar().setVisible(false);
this.viewer.getTable().pack();
this.viewer.getTable().getParent().layout();
this.viewer.getTable().getParent().getParent().layout();

and when i am changing the viewer input i also call the three last lines. I got this solution from: https://bugs.eclipse.org/bugs/show_bug.cgi?id=304128

Lentz answered 19/11, 2012 at 11:9 Comment(0)
C
0

Try

table.getHorizontalBar().setVisible(false);
Citrin answered 2/4, 2012 at 13:30 Comment(3)
in SWT you can use CSS than try this overflow: hiddenCitrin
Well, i tried your option and searched on that but still i am not able to figure out where to give style. Can you please tell which method is used for giving this specific style.Kieserite
i have another solution you must declare your table like this Table table = new Table (shell, SWT.BORDER | SWT.NO_SCROLL); the SWT.NO_SCROLL forces the table to not have the scroll bars hope this helps youCitrin
C
0

Is't simple:

leftTable.getVerticalBar().addListener(SWT.Selection, event -> { rightTableViewer.getTable().setTopIndex(leftTableViewer.getTable().getTopIndex());

});

and vice versa.

Crenulation answered 6/5, 2016 at 18:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.