SWT Table hat keine Scrollbar

Status
Nicht offen für weitere Antworten.

Aldimann

Bekanntes Mitglied
Hi zusammen,

ich hab keinen Table, der mehr Informationen enthält, als er aufeinmal anzeigen kann. Somit sollte eigentlich eine Scrollbar erschreinen, was allerdings nicht passiert 🙁.

Ich hatte auf der darüberliegenden Komponente sowohl Grid- als auch ein Filllayout probiert, bei beidem blieb der gewünschte Erfolg aus.

Hat jemand ne Idee woran das liegen kann?

Gruß
 
Die korrekten Styles (SWT.H_SCROLL | SWT.V_SCROLL) sind gesetzt? Und die darueberliegende Komponente selbst waechst nicht selbst?

[Edit: oder du verwendest nicht SWT, das koennte auch sein....]
 
Zuletzt bearbeitet von einem Moderator:
Die korrekten Styles (SWT.H_SCROLL | SWT.V_SCROLL) sind gesetzt? Und die darueberliegende Komponente selbst waechst nicht selbst?

[Edit: oder du verwendest nicht SWT, das koennte auch sein....]

SWT.H_SCROLL und SWT.V_SCROLL waren nicht gesetz, sind es aber jetzt und es Funktioniert nicht :/.
Die Komponente liegt mit zwischenebenen auf einem PluginFenster für Eclipse und kann somit nur begrenzt wachsen, bei SWT.FILL scheint er da den kompletten Platz zu nutzen.

Zugrunde liegt dem ganzen folgendes Beispiel:
KLICK

Das Beispiel funktioniert so bei mir (Scrollbar wird angezeigt).

Code zum erstellen des Tables:

Java:
import org.eclipse.swt.widgets.Table;

Table table = new Table(comp, SWT.H_SCROLL | SWT.V_SCROLL);

Sollte also auch passen?!


Hast du die Tabelle in eine JScrollPane eingebettet?

Verstehe nicht, was ein JScrollPanel bei einer SWT Komponente soll? Ist das nicht eine SWING Komponente?
 
hmm ich würde die Tabele

in ein extra ScrolledComposite rein basteln mit irgend welchen srollbar hinzu fügen usw habe ich nur Problem gehabt

so sollte das denn irgendwie aussehen
Code:
sc = new ScrolledComposite(compeditor, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

Table table = new Table(sc,SWT.NONE);
 
hmm ich würde die Tabele

in ein extra ScrolledComposite rein basteln mit irgend welchen srollbar hinzu fügen usw habe ich nur Problem gehabt

so sollte das denn irgendwie aussehen
Code:
sc = new ScrolledComposite(compeditor, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

Table table = new Table(sc,SWT.NONE);

Würde ich nicht machen


Klappt doch wunderbar

Java:
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class SWTTest {

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    GridLayout gridLayout = new GridLayout();
    Composite composite = new Composite(shell, SWT.FULL_SELECTION);
    composite.setLayout(gridLayout);
    Table table = new Table(composite,  SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL,true,true));
    String[] titles = { " ", "C", "!", "Description", "Resource",
        "In Folder", "Location" };
    for (int i = 0; i < titles.length; i++) {
      TableColumn column = new TableColumn(table, SWT.NONE);
      column.setText(titles[i]);
      column.pack();
    }
    int count = 40;
    for (int i = 0; i < count; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(0, "x");
      item.setText(1, "y");
      item.setText(2, "!");
      item.setText(3, "this stuff behaves the way I expect");
      item.setText(4, "almost everywhere");
      item.setText(5, "some.folder");
      item.setText(6, "line " + i + " in nowhere");
    }
   
    composite.pack();
    shell.setSize(new Point(200,200));
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}
 
Bei anderen Quelltexten gehts ja auch, nur bei meinem nicht😀.

Hab jetzt mal den meiner Meinung nach entscheidenen Teil zusammen kopiert:

Java:
		Set<String> buttonTexts = new TreeSet<String>(new Comparator<String>(){

			public int compare(String o1, String o2) {
				return o1.compareTo(o2);
			}
			
		});

	buttonTexts.addAll(fileMap.keySet());
	
	Table table = new Table(comp, SWT.H_SCROLL | SWT.V_SCROLL);
	table.setHeaderVisible(false);
	table.setLinesVisible(true);
	
	for(int i =0;i<4;i++){
		TableColumn col = new TableColumn(table, SWT.NONE);
		
		for (String text : buttonTexts) {
			
			
			TableItem item = new TableItem(table, SWT.NONE);
			
			TableEditor tableeditor = new TableEditor(table);
			
			Button button = new Button(table, SWT.CHECK);
			button.setText(text);
			button.pack();
			
			tableeditor.minimumWidth = button.getSize().x;
			tableeditor.horizontalAlignment= SWT.LEFT;
			tableeditor.setEditor(button, item, i);
			
			button.setBackground(table.getBackground());
			
			col.setWidth(button.getSize().x);
			table.pack();
			
			buttons.add(button);
			
		}
		}
    
	}

Evtl hilft das ja bei der Fehler Findung :/.

Den ScrolledComposite hatte ich auch ausprobiert, Erfolg blieb leider aus.
 
Vielleicht brauch deine Tabelle noch gar keine Scrollpane die wird erst angezeigt wenn sie benötigt wird...
wenn nicht KSKB...
 
export.jpg

Wie man sieht gehts da noch weiter, aber eben nix zum scrollen da 🙁 ...


Hab jetzt meinen Code mal bissl so gemacht das er Ausführbar ist und die Scrollbars trotzdem nicht angezeigt werden:

Java:
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;


public class test {
public static void main(String[] args) {
	new test();
}

public test() {
	Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	
	ScrolledComposite composite = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
	composite.setLayout(new FillLayout());
	
	table(composite);
	
	   shell.pack();
	    shell.open();
	    while (!shell.isDisposed()) {
	      if (!display.readAndDispatch())
	        display.sleep();
	    }
	    display.dispose();
	  }




private void table(Composite comp){
	List<Button> buttons = new ArrayList<Button>();
	Map<String, String> fileMap = new HashMap<String, String>();
	
	for(int i=0;i <100; i++){
		fileMap.put("ButtonNo"+i, "nix");
	}
	
    Set<String> buttonTexts = new TreeSet<String>(new Comparator<String>(){
    	 
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
        
    });

buttonTexts.addAll(fileMap.keySet());

Table table = new Table(comp, SWT.H_SCROLL | SWT.V_SCROLL);
table.setHeaderVisible(false);
table.setLinesVisible(true);

for(int i =0;i<4;i++){
	
    TableColumn col = new TableColumn(table, SWT.NONE);
    
    for (String text : buttonTexts) {
        
        
        TableItem item = new TableItem(table, SWT.NONE);
        
        TableEditor tableeditor = new TableEditor(table);
        
        Button button = new Button(table, SWT.CHECK);
        button.setText(text);
        button.pack();
        
        tableeditor.minimumWidth = button.getSize().x;
        tableeditor.horizontalAlignment= SWT.LEFT;
        tableeditor.setEditor(button, item, i);
        
        button.setBackground(table.getBackground());
        
        col.setWidth(button.getSize().x);
        table.pack();
        
        buttons.add(button);
        
    }
    }


}
}
 
Zuletzt bearbeitet:
Klassen schreibt man GROß
mach ne normale Composite drauß und schon tuts
Java:
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());

        Composite composite = new Composite(shell, SWT.BORDER);
        composite.setLayout(new FillLayout());

        table(composite);

        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
 
Alles klar gelöst!

Problem war wie schon von SirWayne ein normaler Composite, außerdem hatte ich aber noch ein GridLayout, damit gab es anscheinend Probleme.

Habe jetzt ein FillLayout und es funktioniert.

Ja sorry wegen dem Klassennamen, das war grad nur so auf die schnelle 😛 ...

Vielen dank nochmal...

Btw wie setzte ich noch gleich den Thread auf erledigt?
 
for me the last (colored/bold) line of this code snippet that I found did the magic:


Code:
    // parent code her ...
    {
         final ScrolledComposite scrolledComposite = new ScrolledComposite(shell, SWT.BORDER | SWT.V_SCROLL);
         {
              composite = new Composite(scrolledComposite, SWT.NONE);
              composite.setBounds(0, 0, 300, 200);
              composite.setBackground(ResourceManager.getColor(SWT.COLOR_CYAN));
              scrolledComposite.setContent(composite);
              {
                 final Button button = new Button(composite, SWT.NONE);
                 button.setBounds(150, 115, 60, 35);
                 button.setText("button");
              }
         }
    }
    // and AFTER! everything had been set, we do a:
    composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben