The button in nattable is covering half of my table, can someone explain why? - button

i have used the following code for the button
natTable.addOverlayPainter(new NatTableBorderOverlayPainter());
Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 5;
layout.marginWidth = 8;
panel.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
Composite gridPanel = new Composite(panel, SWT.NONE);
gridPanel.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new RowLayout());
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
Button addButton = new Button(gridPanel, SWT.PUSH);
addButton.setText("Export");
addButton.setSize(1, 1);
addButton.setLocation(450, 150);
addButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new ExportCommand(natTable
.getConfigRegistry(), null, editable));
natTable.updateResize();
}
but at the end i am getting this as a result
https://imgur.com/EFcPaqo

Your layout is broken. Probably because the NatTable instance is not created on one of your Composites. But hard to tell without seeing the creation of it.
Either have a look at Understanding layouts in SWT or even check the NatTable examples PrintExample that shows exactly the same. There you can see that NatTable is created on the gridPanel.

Related

(JavaFX) After maximizing the window (stage), i cant select items in the tableview anymore

since my code is quite long, I'll try to only describe the issue first to see if someone has faced it before.
I have a TableView that i populate with various objects which works just fine. I created a context menu so whenever I right-click an Item i can edit certain columns. Everything works fine but when i maximize the window, I cant select any Items anymore by clicking on them.
Has anyone faced that issue before?
Thx for the help!
edit:
I added some lines of code. Im using Java 1.8.
anchorPane = new AnchorPane();
anchorPane.setMaxWidth(550.0);
tabPane = new TabPane();
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
tabPane.setTabMinHeight(22.0);
tabPane.setPrefWidth(this.navigationWidth);
homeTableView = new TableView<Player>();
homeTableView.setEditable(true);
homeTableView.setContextMenu(homeContextMenu);
List<Player> test= mainWindow.getHomeTeamPlayer();
ObservableList<Player> homeTeamPlayer = FXCollections.observableArrayList(test);
homeTableView.setItems(homeTeamPlayer);
homeTableView.setContextMenu(homeContextMenu);
Field[] fields = Player.class.getDeclaredFields();
for(Field field: fields){
// Get column information from Metadata
ColumnMetadata columnMetadata = field.getAnnotation(ColumnMetadata.class);
if(!columnMetadata.showInTable()) continue;
TableColumn<Player, String> HomeCol = new TableColumn<>(columnMetadata.displayTitle());
HomeCol.setCellValueFactory(new PropertyValueFactory<>(field.getName()));
if(columnMetadata.isEditable()){
HomeCol.setEditable(true);
}
homeTableView.getColumns().add(HomeCol);
}
homeTab = addTab("homename", homeTableView);
AnchorPane.setRightAnchor(tabPane, 0.0);
AnchorPane.setLeftAnchor(tabPane, 0.0);
AnchorPane.setTopAnchor(tabPane, 0.0);
AnchorPane.setBottomAnchor(tabPane, 0.0);
anchorPane.getChildren().addAll(tabPane);
public Tab addTab(String name, TableView tableView){
Tab tab = new Tab();
tab.setText(name);
tab.setContent(tableView);
tabPane.getTabs().addAll(tab);
return tab;
}

JavaFX architecture in building dynamic "rows"

I have an application that I am building that has a table in it, I'm not using a tableview to build this table because I need each row to be able to expand similar to an accordion. I was able to achieve what I need by using a timeline and looping through the data and building each row (its kind of crude right now since I'm still working with dummy data eventually it will be a list iterator and not just a for loop) but I'm not happy with how its done. There are a lot of default values that will never change so I don't really need to set them in my worker class every time, I decided to just add them to the object class that I put together. So basically, at a high level it looks something like this:
for (int i = 0; i < 30; i++) {
RowBuilder builder = new RowBuilder(tableBox, i);
try {
builder.run();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I'm passing it the parent which is a VBox - tableBox, then I'm passing the count for later use.
Inside the RowBuilder I'm getting a new instance of the object DashboardRow which has all the defaults set in it, then I'm setting the data for each row and returning the DashboardRow.
Here is an example of a getter setting values in the DashboardRow
public HBox getMainRow() {
mainRow.setAlignment(Pos.CENTER_LEFT);
mainRow.setPrefHeight(60);
mainRow.setMinHeight(60);
mainRow.setMaxHeight(60);
mainRow.setPrefWidth(-1);
mainRow.setStyle("-fx-background-color:#FFFFFF;");
return mainRow;
}
Inside the DashboardRow class I have a ton of new objects being created for every element I need in the row. There are 21 for each row, mostly VBox, HBox and StackPane to build the actual row, the rest are just labels and buttons.
This is what is looks like so far. Opened and closed states.
Is there a better way to dynamically build things like this in javafx? I'm basically pulling data from a database and looping through that data to populate a row.
I can't comment but it may be an answer anyway. Why can't you use the setGraphic method of a custom table cell and put the accordion node in a table. setGraphic takes any kind of node.
It sounds simpler than what you're doing.
I just tried it out with the Oracle sample and it works great.
I added
Callback<TableColumn<Person, String>, TableCell<Person, String>> accCellFactory
= new Callback<TableColumn<Person, String>, TableCell<Person, String>>() {
#Override
public TableCell call(TableColumn p) {
TitledPane t1 = new TitledPane("T1", new Button("B1"));
TitledPane t2 = new TitledPane("T2", new Button("B2"));
TitledPane t3 = new TitledPane("T3", new Button("B3"));
Accordion accordion = new Accordion();
accordion.getPanes().addAll(t1, t2, t3);
TableCell tc = new TableCell();
tc.setGraphic(accordion);
return tc;
}
};
and changed this line firstNameCol.setCellFactory(accCellFactory);
and I get
Of course you might want something other than buttons but I just copied the Accordion sample from the javadoc.

QCompleter and QListWidget as custom popup issue

I have a QCompleter using a QStringListModel for my QPlainTextEdit (check this example):
QStringListModel* model = new QStringListModel(names);
QCompleter* completer = new QCompleter(model);
completer->setCompletionMode(QCompleter::PopupCompletion);
completer->setModelSorting(QCompleter::UnsortedModel);
It works fine. Now I need some Icon, Tooltips for each suggestion I'm trying to use a QListWidget as custom popup:
QListWidget* w = new QListWidget();
foreach(name, names) {
QListWidgetItem* i = new QListWidgetItem(name);
i->setIcon(/*my Icon*/);
i->setToolTip("");
w->addItem(i);
}
completer->setPopup(w);
The popup ok, just like I need, but the completion no more work. I cannot type the text to make it filter the suggestion, just Up/Down key.
I have try:
completer->setModel(w->model());
but no help!
What is my misstake or just QStringListModel give me the ability to filter the suggestions? What do you suggest?
Thanks you!
I mostly deal with PyQt, but same deal. My syntax may be off, but you should use a QStandardItemModel vs. a QStringListModel. From there, you can leave it as the standard popup (QListView)
Something like:
QStandardItemModel* model = new QStandardItemModel();
// initialize the model
int rows = names.count(); // assuming this is a QStringList
model->setRowCount(rows);
model->setColumnCount(1);
// load the items
int row = 0;
foreach(name, names) {
QStandardItem* item = new QStandardItem(name);
item->setIcon(QIcon(":some/icon.png");
item->setToolTip("some tool tip");
model->setItem(row, 0, item);
row++;
}
completer->setModel(model);
completer->popup()->setModel(model); // may or may not be needed

Qt: view added to layout not updating, but will update when not in layout

A widget called Tachometer will update accordingly when a signal is sent from its corresponding model, but it will not respond at all when I add the widget to a layout. What might account for this? Without showing the internals of the model or the view (which would be exhaustive), I will attempt to point out where it is not working:
void MainWindow::setupWidgets()
{
QHBoxLayout *horiz1 = new QHBoxLayout();
QHBoxLayout *horiz2 = new QHBoxLayout();
odometer = new Odometer(ui->dashFrame);
fuelGauge = new FuelGauge(ui->dashFrame);
tripometer = new Tripometer(ui->dashFrame);
tachometer = new Tachometer(ui->dashFrame);
temperatureGauge = new TemperatureGauge(ui->dashFrame);
oilPressureGauge = new OilPressureGauge();
QVBoxLayout *vertOPG = new QVBoxLayout();
if ( oilPressureGauge->getTitle() != "" )
{
QLabel *OPGLabel = new QLabel(oilPressureGauge->getTitle());
vertOPG->addWidget(OPGLabel);
}
vertOPG->addWidget(oilPressureGauge);
speedometer = new Speedometer(ui->dashFrame);
horiz1->addWidget(tachometer);
horiz1->addWidget(speedometer);
horiz2->addWidget(fuelGauge);
horiz2->addWidget(temperatureGauge);
horiz2->addLayout(vertOPG);
horiz2->addWidget(tripometer);
horiz2->addWidget(odometer); // will NOT update when added to layout
QVBoxLayout *vert1 = new QVBoxLayout(ui->dashFrame);
vert1->addLayout(horiz1);
vert1->addLayout(horiz2);
this->ui->dashFrame->setLayout(vert1);
}
I am perplexed that the other Widgets will update as expected, but not the object named tachometer. As I said before, if I don't add it to the layout, e.g.
// ...
tachometer = new Tachometer(ui->dashFrame);
// ...
it appears to work just fine. Furthermore, by debugging on the console I see that the RPM value for the tachometer is being sent to the appropriate slot that updates the view for the tachometer (I just noticed the tachometer finally responded to the update, but it isn't updating after every timeout as it should). It seems like some latency issues are clearly involved here.
If anyone might have an idea as to why this might be, I would greatly appreciate some clarification.

DevExpress edit template combobox value to parameter

I have two pre populated combo boxes with value = “ID” and Text = Relevant data...
I am doing an edit in a grid view and I adjusted the template to have the two combo boxes (each relevant field has its own).
I have searched high and low and I assume this is so easy people don’t even ask about it... but if you see below the combo boxes do not populate the parameters with the value of the combo boxes.
So I have tried this:
protected void aspxGridviewUsers_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
e.NewValues["StoreID"] = GetStoreID();
e.NewValues["GroupID"] = GetGroupID();
}
protected int GetStoreID()
{
ASPxComboBox CBID = new ASPxComboBox();
CBID = aspxGridviewUsers.FindEditFormTemplateControl("ASPxComboBoxStoreEdit") as ASPxComboBox;
return Convert.ToInt32(CBID.SelectedItem.Value.ToString());
}
protected int GetGroupID()
{
ASPxComboBox CBID = new ASPxComboBox();
CBID = aspxGridviewUsers.FindEditFormTemplateControl("ASPxComboBoxGroupEdit") as ASPxComboBox;
return Convert.ToInt32(CBID.SelectedItem.Value.ToString());
}
This did not work. What am I doing wrong here?
How can I use those values in the comboboxes to update against my update statement?
I would suggest that you use the following code:
return Convert.ToInt32(CBID.Value);
code. Does it work for you?

Resources