I'm trying to use a Table to create a menu with lined-up Buttons and Labels. I'm using the latest nightly builds of libgdx, which changed the Table API (amongst other things).
Here's the code in my Screen constructor:
this.mStage = new Stage();
this.mTable = new Table();
this.mTable.setFillParent(true);
this.mTable.debugTable();
this.mStage.addActor(this.mTable);
// now I add some stuff to the table
// ...
My resize function looks like this:
this.mStage.setViewport(width, height, true);
this.mTable.setFillParent(true);
this.mTable.invalidate();
My render function has the following:
System.out.println("Table size is " +
this.mTable.getWidth() + " by " +
this.mTable.getHeight());
this.mStage.draw();
Table.drawDebug();
Although my console shows the correct size:
Table size is 480.0 by 640.0
the Table size is shrink-wrapped around its children, and does not extend to the correct size of 480x640.
Any ideas?
Answering my own question for the benefit of others. The way I was adding widgets to the table was incorrect:
this.mTable.row();
this.mTable.add(button).fillX();
I needed to call the fillX() method of the row():
this.mTable.row().fillX();
this.mTable.add(button);
Hope this helps someone.
To add to the above answers, it may be helpful to know that you can make these setting defaults for the table like so:
this.mTable.defaults().expandX().fillX();
The settings will apply uniformly to all rows and cells.
Your incorrect version of adding widget to the table can be easily
corrected by expanding a cell first using .expandX() method and then
by filling that cell with a widget by calling fillX().
so your initial code:
this.mTable.row();
this.mTable.add(button).fillX();
should be corrected to the following version:
this.mTable.row();
this.mTable.add(button).expandX().fillX();
these 2 lines can be shorten to one:
this.mTable.add(button).expandX().fillX().row();
Related
Im pretty pretty new to Dynamic-Jasper, but due to work i had to add a new feature to our already implemented solution.
My Problem
The Goal is to add a Column to a report that consists only out of a background-color based on some Information. I managed to do that, but while testing I stumbled upon a Problem. While all my Columns in the html and pdf view had the right color, the Excel one only colored the fields in the last Color.
While debugging i noticed, that the same colored Fields had the same templateId, but while all Views run through mostly the same Code the Excel one showed different behavior and had the same ID in all fields.
My Code where I manipulate the template
for(JRPrintElement elemt : jasperPrint.getPages().get(0).getElements()) {
if(elemt instanceof JRTemplatePrintText) {
JRTemplatePrintText text = (JRTemplatePrintText) elemt;
(...)
if (text.getFullText().startsWith("COLOR_IDENTIFIER")) {
String marker = text.getFullText().substring(text.getFullText().indexOf('#') + 1);
text.setText("ID = " + ((JRTemplatePrintText) elemt).getTemplate().getId());
int rgb = TypeConverter.string2int(Integer.parseInt(marker, 16) + "", 0);
((JRTemplatePrintText) elemt).getTemplate().setBackcolor(new Color(rgb));
}
}
}
The html view
The Excel view
Temporary Conclusion
The same styles uses the same Objects in the background and the JR-Excel export messes something up by assigning the same Object to all the Fields that I manipulated there. If anyone knows of a misstake by me or potential Solutions to change something different to result the same thing please let me know.
Something different I tried earlier, was trying to set the field in an evaluate Method that was called by Jasper. In that method we assign the textvalue of each field. It contained a map with JRFillFields, but unfortunatelly the Map-Implementation denied access to them and just retuned the Value of those. The map was provided by dj and couldn't be switched with a different one.
Edit
We are using JasperReports 6.7.1
I found a Solution, where I replaced each template with a new one that was supposed to look exactly alike. That way every Field has its own ID guaranteed and its not up to chance, how JasperReports handles its Data internaly.
JRTemplateElement custom =
new JRTemplateText(((JRTemplatePrintText) elemt).getTemplate().getOrigin(),
((JRTemplatePrintText) elemt).getTemplate().getDefaultStyleProvider());
custom.setBackcolor(new Color(rgb));
custom.setStyle(((JRTemplatePrintText) elemt).getTemplate().getStyle());
((JRTemplatePrintText) elemt).setTemplate(custom);
I am trying to create a small application where I have various file locations stored in a Vaadin grid, the grid currently only shows two columns - ID and File Name, and I would like to see as a notification the file location too whenever I click on a row.
Meaning, every time I click a row from the grid I would like it to show me the location, using Notification.show(), like that:
(Please ignore the <b></b>s, they are irrelevant.)
As my grids selection model is MULTI, per default the click listener cannot register which row it is clicked on and selecting the row via checkbox is not what I want to have the data displayed. Simply, I would like to get the item for every row I click and have the location displayed as a notification.
So far, I found a solution for a similar issue but it deals with columns and the rows in Vaadin grids are rather different from what I am used to.
public static <T> void addColumnClickListener(Grid<T> grid, Consumer<Column<T>> listener)
{
String expression = "function(){const col=element.getEventContext(event).column;return col ? col.id : '';}()";
grid.getElement().addEventListener("click", e ->
{
String colId = e.getEventData().getString(expression);
Optional<Column<T>> column = grid.getColumns().stream().filter(col -> colId.equals(col.getId().get())).findFirst();
column.ifPresent(listener);
}
).addEventData(expression);
}
And I am to call the function like that:
addColumnClickListener(grid, column -> Notification.show("fubar"));
This code snippet is from the Vaadin forums and I do not quite understand it. The string expression seems to be that it contains possible JavaScript code and the rest overrides the type of the column. (I think, I really do not understand this snippet fully)
Is there any way to do something similar to the snippet above but for rows?
You can do this with an ItemClickListener on the Grid:
grid.addItemClickListener(item -> {
Notification.show(String.format("File location: %s", item.getLocation()));
});
I want to insert a new JavaFX bean in a grid using an "insert" button. Everything is fine, except for a display problem. After insertion, a "ghost selection" is displayed lower in the grid, as shown in this screenshot. In this example, a fourth section bean was added and selected as requested. But a fake selection appears 10 lines under the last real bean, where no bean is set for this row.
Has anyone experienced this kind of behavior? Any clue how get rid of this ghost selection? Here is what the code for the insert button looks like:
#FXML
private Button insert;
...
insert.setOnAction(event -> {
JfxBean newBean = createBean();
tableView.getItems().add(newBean);
int index = tableView.getItems().indexOf(newBean);
tableView.getSelectionModel().clearSelection();
tableView.requestFocus();
tableView.scrollTo(index);
tableView.getSelectionModel().focus(index);
tableView.getSelectionModel().select(index);
};
According to javaFX-8 documentation, SelectionModel.java does not expose any focus() method. FocusModel.java does instead. Therefore JVM will fail to compile your presented code.
Below is a possible solution:
insert.setOnAction(event -> {
JfxBean newBean = createBean();
tableView.getItems().add(newBean);
int index = tableView.getItems().indexOf(newBean);
tableView.getSelectionModel().clearSelection();
tableView.requestFocus();
tableView.scrollTo(index);
// below line is the amendment
tableView.getFocusModel().focus(index);
tableView.getSelectionModel().select(index);
};
Finally, adding tableView.refresh() corrected this weird behavior. No more ghost selection.
I have a SWT table which wrapped by the JFace TableViewer, but this problem also applies to org.eclipse.swt.widgets.Table.
When I use a StyledCellLabelProvider, the text is always left aligned, even when I use
colA.getColumn().setAlignment(SWT.RIGHT);
Here is the label provider and setup:
TableViewerColumn colA = new TableViewerColumn(measureTable, SWT.NONE);
colA.setLabelProvider(new StyledCellLabelProvider() {
#Override
public void update(ViewerCell cell) {
ModelItem item = (ModelItem) cell.getElement();
cell.setFont(FONT_REGISTRY.get(MY_SPECIAL_FONT));
cell.setText(item.getText());
super.update(cell);
}
});
Any sort of workaround would be great. For e.g, nesting a widget inside the table and right aligning the text in the widget somehow.
Platform: Windows 7
You found a bug in StyledCellLabelProvider. It will not occur with any other CellLabelProvider.
StyledCellLabelProvider uses "owner draw" for drawing the Table cells. That means, the cell content is not drawn natively by the OS. It is drawn in an SWT.PaintItem event by the Table "owner".
StyledCellLabelProvider does not respect the alignment of the TableColumn. You can see the source here, the method getTextLayoutForInfo(.) is of interest.
A workaround could be to copy that class, fix the bug by adding
TableColumn col = ((Table)viewer.getControl()).getColumn(cell.getColumnIndex());
layout.setAlignment(col.getAlignment());
in the method getTextLayoutForInfo(.) (I didn't test this fix, but if it doesn't work, you should get the idea, and be able to make it work)
You should also add a bug report: Eclipse Bugzilla
I have write the code to create the report using itext.For that,i have to add the header
which is like
BSJ Economy Report Date:31/12/10
For that i need to put the tab character(\t) between the above strings.But i can't find out the tab character in itext.I have used "\t" and "\t".This was not working.Please help me to resolve this issue.
There isn't one.
Sounds like a job for a 3-column table. Or perhaps a ColumnText drawing into the same rectangle with three different alignments?
Lots of options.
to put tab caracter. We do like that
p = new Paragraph();
p.setTabSettings(new TabSettings(56f));
p.add(Chunk.TABBING);
p.add(new Chunk("Hello World with tab."));