JavaFX Table – Java – Fórum – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

JavaFX Table – Java – Fórum – Programujte.comJavaFX Table – Java – Fórum – Programujte.com

 

Vlákno bylo úspěšně vloženo.
Pokud sám přijdeš na řešení, nezapomeň ho sem přidat!
William
~ Anonymní uživatel
16 příspěvků
15. 3. 2014   #1
-
0
-

   

Připojen obrázek.

Ahoj, neporadí mi někdo jak udělat obdobnou tabulku v JavaFx jako je tato (viz obrázek) udělaná v SWT.

Děkuji

William

Nahlásit jako SPAM
IP: 195.146.119.–
Flowy0
Věrný člen
15. 3. 2014   #2
-
0
-

chces radu alebo riesenie?

Nahlásit jako SPAM
IP: 95.102.43.–
https://github.com/Flowy
William
~ Anonymní uživatel
16 příspěvků
15. 3. 2014   #3
-
0
-

#2 Flowy
nejlepe reseni. Jelikoz reseni pro Swing a SWT bylo docela jednoduche ale pro JavaFx jsem si to jaksi nedal :(

Nahlásit jako SPAM
IP: 195.146.119.–
Flowy0
Věrný člen
16. 3. 2014   #4
-
0
-

http://docs.oracle.com/javafx/2/api/javafx/scene/control/TableView.html

Nahlásit jako SPAM
IP: 95.102.43.–
https://github.com/Flowy
William
~ Anonymní uživatel
16 příspěvků
16. 3. 2014   #5
-
0
-

 to jsem už viděl (ten odkaz co posíláš). To je ale nepřestavitelně zbytečně složité tyto příklady s tou třídou Person. Jde mi o to, že bych potřeboval mít podobně zpracovanou tabulku (viz obrázek dole jak jsem udělal pro SWT). Je takové řešení? Jak udělat jednoduše tabulku viz hore? 

public class SwtTable {
	public static void main(String[] args) {
		Display display = new Display ();
		Shell shell = new Shell (display);
		shell.setLayout(new GridLayout());
		Table table = new Table (shell, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
		table.setLinesVisible (true);
		table.setHeaderVisible (true);
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
		data.heightHint = 200;
		table.setLayoutData(data);
		String[] titles = {"col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8","col9","col10"};
		for (int i=0; i<titles.length; i++) {
			TableColumn column = new TableColumn (table, SWT.NONE);
			column.setText (titles [i]);
		}	
		int count = 5000;
		for (int i=0; i<count; i++) {
			TableItem item = new TableItem (table, SWT.NONE);
			item.setText (0, Integer.toString(i+1));
			item.setText (1, "a");
			item.setText (2, "b");
			item.setText (3, "c");
			item.setText (4, "d");
			item.setText (5, "e");
			item.setText (6, "f");
			item.setText (7, "g");
			item.setText (8, "h");
			item.setText (9, "ch");
		}
		for (int i=0; i<titles.length; i++) {
			table.getColumn (i).pack ();
		}	
		shell.pack ();
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
	} 
Nahlásit jako SPAM
IP: 195.146.119.–
William
~ Anonymní uživatel
16 příspěvků
18. 3. 2014   #6
-
0
-

Můj pokus v JavaFx. Nedaří se mi takto SIMPLY dostat do tabulky data. Kod a jeho vystup priložen.

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class JavaFxTable extends Application {


	private TableView<String> tableView = new TableView<String>();

	private ObservableList<String> dataForTable = FXCollections.observableArrayList();

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void start(Stage primaryStage) {
		Group root = new Group();
		int widthOfColumn = 44;		

		TableColumn col1 = new TableColumn("col1");
		col1.setMinWidth(widthOfColumn);
		TableColumn col2 = new TableColumn("col2");
		col2.setMinWidth(widthOfColumn);
		TableColumn col3 = new TableColumn("col3");
		col3.setMinWidth(widthOfColumn);
		TableColumn col4 = new TableColumn("col4");
		col4.setMinWidth(widthOfColumn);
		TableColumn col5 = new TableColumn("col5");
		col5.setMinWidth(widthOfColumn);
		TableColumn col6 = new TableColumn("col6");
		col6.setMinWidth(widthOfColumn);
		TableColumn col7 = new TableColumn("col7");
		col7.setMinWidth(widthOfColumn);
		TableColumn col8 = new TableColumn("col8");
		col8.setMinWidth(widthOfColumn);
		TableColumn col9 = new TableColumn("col9");
		col9.setMinWidth(widthOfColumn);
		TableColumn col10 = new TableColumn("col10");
		col10.setMinWidth(widthOfColumn);		
		
		tableView.setMaxSize(442, 420);
		tableView.getColumns().addAll(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10);
		
		dataForTable.addAll("1","1","1","1","1","1","1","1","1","1");
		tableView.setItems(dataForTable);		

		VBox vBox = new VBox();
		vBox.setSpacing(10);
		vBox.getChildren().add(tableView);

		root.getChildren().add(vBox);

		primaryStage.setScene(new Scene(root, 500, 500));
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}
}

Připojen obrázek.


Nahlásit jako SPAM
IP: 195.146.119.–
Flowy0
Věrný člen
18. 3. 2014   #7
-
0
-

#6 William
http://docs.oracle.com/javafx/2/ui_controls/table-view.htm

Defining the Data Model

Nahlásit jako SPAM
IP: 95.102.43.–
https://github.com/Flowy
William
~ Anonymní uživatel
16 příspěvků
18. 3. 2014   #8
-
0
-

#7 Flowy
Díky ale nevím proč mi to pořád nefunguje (pořád prázdná tabulka jen s názvy sloupců)

mport javafx.beans.property.SimpleStringProperty;

public class DataModel {
	
    private final SimpleStringProperty column1;
    private final SimpleStringProperty column2;
    private final SimpleStringProperty column3;
    private final SimpleStringProperty column4;
    private final SimpleStringProperty column5;
    private final SimpleStringProperty column6;
    private final SimpleStringProperty column7;
    private final SimpleStringProperty column8;
    private final SimpleStringProperty column9;
    private final SimpleStringProperty column10;
    
    
    
	public DataModel(SimpleStringProperty column1,
			SimpleStringProperty column2, SimpleStringProperty column3,
			SimpleStringProperty column4, SimpleStringProperty column5,
			SimpleStringProperty column6, SimpleStringProperty column7,
			SimpleStringProperty column8, SimpleStringProperty column9,
			SimpleStringProperty column10) {
		
		this.column1 = column1;
		this.column2 = column2;
		this.column3 = column3;
		this.column4 = column4;
		this.column5 = column5;
		this.column6 = column6;
		this.column7 = column7;
		this.column8 = column8;
		this.column9 = column9;
		this.column10 = column10;
	}
	public SimpleStringProperty getColumn1() {
		return column1;
	}
	public SimpleStringProperty getColumn2() {
		return column2;
	}
	public SimpleStringProperty getColumn3() {
		return column3;
	}
	public SimpleStringProperty getColumn4() {
		return column4;
	}
	public SimpleStringProperty getColumn5() {
		return column5;
	}
	public SimpleStringProperty getColumn6() {
		return column6;
	}
	public SimpleStringProperty getColumn7() {
		return column7;
	}
	public SimpleStringProperty getColumn8() {
		return column8;
	}
	public SimpleStringProperty getColumn9() {
		return column9;
	}
	public SimpleStringProperty getColumn10() {
		return column10;
	}
 
   
        
}
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class JavaFxTable extends Application {


	private TableView<DataModel> tableView = new TableView<DataModel>();

	final ObservableList<DataModel> data = FXCollections.observableArrayList(
		    new DataModel(new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1")),
		    new DataModel(new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1")),
		    new DataModel(new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"))
		);
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void start(Stage primaryStage) {
		Group root = new Group();
		int widthOfColumn = 44;		

		TableColumn col1 = new TableColumn("col1");
		col1.setMinWidth(widthOfColumn);
		TableColumn col2 = new TableColumn("col2");
		col2.setMinWidth(widthOfColumn);
		TableColumn col3 = new TableColumn("col3");
		col3.setMinWidth(widthOfColumn);
		TableColumn col4 = new TableColumn("col4");
		col4.setMinWidth(widthOfColumn);
		TableColumn col5 = new TableColumn("col5");
		col5.setMinWidth(widthOfColumn);
		TableColumn col6 = new TableColumn("col6");
		col6.setMinWidth(widthOfColumn);
		TableColumn col7 = new TableColumn("col7");
		col7.setMinWidth(widthOfColumn);
		TableColumn col8 = new TableColumn("col8");
		col8.setMinWidth(widthOfColumn);
		TableColumn col9 = new TableColumn("col9");
		col9.setMinWidth(widthOfColumn);
		TableColumn col10 = new TableColumn("col10");
		col10.setMinWidth(widthOfColumn);		
		
		tableView.setMaxSize(442, 420);
		tableView.getColumns().addAll(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10);
		
		tableView.setItems(data);		

		VBox vBox = new VBox();
		vBox.setSpacing(10);
		vBox.getChildren().add(tableView);

		root.getChildren().add(vBox);

		primaryStage.setScene(new Scene(root, 500, 500));
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}
}
Nahlásit jako SPAM
IP: 195.146.119.–
William
~ Anonymní uživatel
16 příspěvků
18. 3. 2014   #9
-
0
-

#8 William

BLOBST !!!!! mám tam blbě konstruktor v classe DataModel. Sorry

Nahlásit jako SPAM
IP: 195.146.119.–
Flowy0
Věrný člen
18. 3. 2014   #10
-
0
-

#9 William
? co je zle na tom konstruktore?

chyba ti tam priradenie 'funkcneho nazvu' kazdemu stlpcu

firstNameCol.setCellValueFactory(
                new PropertyValueFactory<Person, String>("firstName"));
Nahlásit jako SPAM
IP: 95.102.43.–
https://github.com/Flowy
William
~ Anonymní uživatel
16 příspěvků
18. 3. 2014   #11
-
0
-

#10 Flowy
už mi to jede. Děkuji ti

Nahlásit jako SPAM
IP: 195.146.119.–
Zjistit počet nových příspěvků

Přidej příspěvek

Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!

Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku

×Vložení zdrojáku

×Vložení obrázku

Vložit URL obrázku Vybrat obrázek na disku
Vlož URL adresu obrázku:
Klikni a vyber obrázek z počítače:

×Vložení videa

Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×
 
Podporujeme Gravatara.
Zadej URL adresu Avatara (40 x 40 px) nebo emailovou adresu pro použití Gravatara.
Email nikam neukládáme, po získání Gravatara je zahozen.
-
Pravidla pro psaní příspěvků, používej diakritiku. ENTER pro nový odstavec, SHIFT + ENTER pro nový řádek.
Sledovat nové příspěvky (pouze pro přihlášené)
Sleduj vlákno a v případě přidání nového příspěvku o tom budeš vědět mezi prvními.
Reaguješ na příspěvek:

Uživatelé prohlížející si toto vlákno

Uživatelé on-line: 0 registrovaných, 5 hostů

Podobná vlákna

Klávesnice v JavaFX — založil smajdalf3

Javafx onAction — založil Honza

JavaFX na mobilu — založil goddard

Swing nebo JavaFX ? — založil Darken

JavaFX: stage/scene — založil cheki

Moderátoři diskuze

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý