gwt grid header align - java

I used to gwt 2.5.1, java 1.6.
when used grid,
I want to centerd just grid header.
No data, Only Header.
Source
.getGrid().getColumnModel().getColumns().get(i).setAlignment(HorizontalAlignment.CENTER);
But,
Both are aligned.
So,
What Can I do?
Thank you.

Use DOM inspector and fish out the style that corresponds to your header cell.
If you named your column as "test" then the style may be named something like "x-grid3-td-test".
Add the following to your stylesheet:
.x-grid3-td-test* {
text-align: center;
}

Related

How to style grid cells in vaadin

I have created a simple grid with one column:
public MyGrid() {
addComponentColumn(this::getIcon).setClassNameGenerator(i -> "icon-img");
setItems(/** some items */);
setClassName("sidebar-grid");
}
And I have a css theme called mangaTheme. I use it like this #Theme("mangaTheme"). In the mangaTheme folder I have styles.css file with the following content:
.icon-img {
padding: 0;
}
.sidebar-grid {
width: 102px;
margin: auto;
margin-left: -30%;
}
The sidebar-grid css properties are applied properly as the grid is moved, but the icon-img properties are not applied whatsoever:
The classnames are applied:
What am I doing wrong or missing? I have also read this guide: https://cookbook.vaadin.com/dynamic-grid-cell-styling
EDIT: After configuring my workspace as was mentioned in the answer this is the resulting structure, but it still does not seem to function properly.
What you're missing is that the cell <td> element is inside the shadow DOM of the vaadin-grid component, and thus cannot be styled with global CSS. To style parts of components that are inside the component's shadow DOM, you need to inject the CSS into the component.
In the Cookbook example, this is done through the themeFor parameter in the annotation that loads the stylesheet:
#CssImport(themeFor = "vaadin-grid", value = "./recipe/dynamicgridcellstyling/dynamic-grid-cell-styling.css")
In your theme folder, however, you can do the same thing by putting that CSS in a stylesheet called vaadin-grid.css in the components subfolder, i.e.:
themes/mangaTheme/components/vaadin-grid.css
Another thing you're missing is that the classname is applied to the <td> cell, but the padding is on the vaadin-grid-cell-content element slotted into the cell, not the cell itself, so you need to rewrite your selector:
.icon-img ::slotted(vaadin-grid-cell-content) {
padding: 0;
}
(The sidebar-grid CSS class works fine as-is because it's applied to the vaadin-grid root element, which is in the page's regular DOM.)

Change selected row color in NatTable

How do I change the default row selection color? I do not see where to access this in the code snippet below:
SelectionLayer selectionLayer = glazedListsGridLayer.getBodyLayerStack()
.getSelectionLayer();
selectionLayer.setSelectionModel(new RowSelectionModel<T>(selectionLayer,
glazedListsGridLayer.getBodyDataProvider(), myRowIdAccessor));
You need to register a style for the DisplayMode.SELECT. This can be done with a custom style configuration, a theme configuration or CSS if you are in an Eclipse 4 application.
To get a basic understanding of the styling concepts have a look here: https://eclipse.org/nattable/documentation.php?page=styling
To see how the default selection style configuration is configured check the DefaultSelectionStyleConfiguration

Does JavaFX support regular expressions (or wild cards) in CSS?

I've tried using wild cards in CSS selectors for JavaFX UI (TableView), but that doesn't seem to work, although JavaFX CSS reference notes that it's based on CSS version 2.1:
JavaFX Cascading Style Sheets (CSS) is based on the W3C CSS version
2.1 with some additions from current work on version 3.
For example:
TableColumnHeader[id|="column"] > .label
{
-fx-graphic: url("ico.png");
}
The above CSS is an attempt to show an icon "ico.png" on all column headers of a TableView
TableColumnHeader is the type selector for the table's column header Node
.label is the style class for the Label node rendered within the column header
[id|="column"] is similar to the example mentioned here: https://www.w3.org/TR/CSS21/selector.html#matching-attrs
The id of column header is inherited from its TableColumn. The id is set on the TableColumn object as follows: tableColumn.setId("column-"+ columnName) where columnName is a String variable
The above CSS doesn't work. Any variation that includes [id=...], or any other attribute other than id doesn't work.
Is this a limitation in JavaFX? or is there a way to make it work?

GWT TextColumn in CellTable -> Horizontal alignment

I am trying to align a column in my cell table to the right. Therefore I use the "setHorizontalAlignment" of my column object. The resulting cell is actually rendered with the "align=right", but it is not aligned to the right because the cell contains another div that fills the complete cell.
Is this a bug in GWT or am I doing it wrong?
TextColumn<String> myColumn = new TextColumn<String>() {
#Override
public String getValue(String myObj) {
return myObj;
}
};
myColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
myCellTable.addColumn(myColumn, "anyColumnName");
I know I can also align it right via CSS, but I hope, I can get this approach working because it seems to be the cleaner solution.
You can do it using css and Column#setCellStyleNames().
Sample code:
myColumn.setCellStyleNames("rightAlign");
css:
.rightAlign{
text-align: right;
}
Note: change css as per your requirement
I have the same code, and it renders the same way - with a div element that takes 100% of the width. And the text inside this cell is displayed aligned to the right - as it should. So this is not a GWT bug.
There is another style in your CSS that interferes here. Most likely, you have something like this in your CSS:
td {
text-align: left;
}

Changing a single element of the widget style

How to change single element of the widget style in GWT. I would like to create new version of TextBox style, so that only the border color changed to red, for example.How to get to the style responsible for the TextBox?
I tried to create new style
.gwt-TextBox.invalid {
border-color: red;
}
but it does not work.
Make sure you add class invalid to your TextBox:
textBox.addStyleName("invalid");
Use CssResource to associate your CSS file with GWT: http://code.google.com/webtoolkit/doc/latest/DevGuideUiCss.html#cssfiles

Categories

Resources