I have a Vaadin 7 Grid and I would like to set a color to a specific column.
Grid grid = new Grid(container);
grid.setColumnOrder("column1","column 2","column 3");
Use one of the many column renderers. Easiest is probably the HTMLRenderer.
Example:
grid.addColumn("column1", String.class).setRenderer(new HtmlRenderer());
grid.addRow("data for column1", "data for column2", ...,
"<h1 style="background-color:Red;">data for column3</h1>");
See also: https://vaadin.com/docs/v7/framework/components/components-grid/#components.grid.generatedcolumns
This piece of code actually worked for me.I have been using Java 8 ,
Grid.setCellStyleGenerator((Grid.CellStyleGenerator) cellReference ->{
cellReference.getGrid().getHeaderRow(rowIndex: 0).getCell("column name").setStyleName("bg-blue");
}
Note :- bg-blue is the css rule mentioned in CSS file .
Related
I want to style a grid row after clicking on it. I get the grid row / item in the itemClickListener, but I need to avoid using grid.select(item). I have achieved the desired output which would highlight the row I clicked on with the grid select method, but this causes problems for my app since I do not want that row to be selected, but I want it to be just highlighted, e.g. apply a CSS style to said row. This is my code so far:
grid.addItemClickListener(e -> {
grid.deselectAll();
grid.select(e.getItem());
});
as well as:
grid.setStyleGenerator(row -> grid.getSelectedItems().contains(row)
? getRowSelectedStyle(row)
: null);
I cannot seem to find anything on the forums which could apply a style name for the clicked row.
You probably need to add a property to your item Bean, se "clicked".
Then you could do
grid.addItemClickListener(e -> {
e.getItem().setClicked(true);
grid.getDataProvider().refreshItem(e.getItem());
});
And
grid.setStyleGenerator(row -> row.isClicked()
? getRowSelectedStyle(row)
: null);
I have implemented bootstrap 4 data table 4 in angular 4 but not able to change or modify row color. row selection color and header color as well.
I am using the data table 4 example : https://github.com/afermon/angular-4-data-table-bootstrap-4
and in this examples demo go through the demo 1 of link: https://afermon.github.io/angular-4-data-table-bootstrap-4-demo/
Considering the below code snippet present in data-table-component-demo1.ts got by the Git project you downloaded:
<data-table id="persons-grid"
[header] = "false"
[multiSelect] = "false"
[substituteRows]="false"
[indexColumn]="false"
[items]="items"
[itemCount]="itemCount"
(reload)="reloadItems($event)"
[pagination]="false"
(rowClick)="rowClick($event)"
[rowColors] = "callBackForChangineRowColors"
>
<data-table-column
[property]="'name'"
[header]="'Name'"
[sortable]="true"
[styleClass]="someExplicitClass"
In this, we can assign the value 'someExplicitClass' to [styleClass] as shown above and define the class someExplicitClass in our data-table-component-demo1.css file as below:
:host /deep/ .someExplicitClass{
background-color:red;
}
However, this is applied to the whole of the DataColumn and not controllable on a granular level.
We can indirectly apply only background-color using the rowEvent variable available within the rowClick(rowEvent) function of 'data-table-component-demo1.ts'
On click of the row, I will set the selected property of the row to true and thereby will trigger the onRowSelectChanged function of table.component.ts file
Now, once I set [rowColors] value to "callBackForChangineRowColors" as shown above and make the below changes in my data-table-component-demo1.component.ts file:
rowClick(rowEvent) {
console.log('Clicked: ' + rowEvent.row.item.name);
rowEvent.row.selected = true;
}
callBackForChangineRowColors(a,b,c)
{
if(b.selected)
return 'blue';
}
This way, I will be able to apply the color of blue explicitly for the selected Row.
*I could'nt unfortunately find any solution to apply any other styles on a granular level using a readily available input parameter like [styleClass] for it wasnt exposed as an #Input within our column.component.ts. If anyone has an idea, please do help me know it.
Hello Stackeroverflowers,
i'd like to ask how can i change a RadioButton Dot?
I need to define 3 RadioButtons with 3 different Colors to show a state.
Do i have to work with Css?
Would be perfect if anyone could tell me how can i realize that ?
A Example would be:
#FXML
public RadioButton redState = new RadioButton();
.
.
.
redState.setDotColor(red);
or in Fxml to define the Color static:
style="-fx-dot-color: rgb(255,0,0);"
I hope everyone understood my Plan.
It's only about colorize the Dot in a javafx RadioButton.
I'm thankfull for every Answer.
I haven't tested this, but try
redState.getStyleClass().add("red-radio-button");
(or do this in FXML if you prefer).
And then in an external css file
.red-radio-button .dot {
-fx-mark-highlight-color: red ;
-fx-mark-color: red ;
}
i would like to have one list select that will have more than one style, i put two kinds of object's one is a group of users (bold), rest are users (italic or regular) is it possible to add style that will be added to part of added obj?
My code looks like this:
for(Usr usr: userSearchResult){
listSelect.addItem(usr);
}
listSelect.addStyleName("bold");
for (Gr gr : groupSearchResult) {
searchList.addItem(gr);
}
and also have style set in css correct similar to this
.v-select-bold .v-select-select {
font-weight:bold;}
i would be glad to solve this by myself but that was two days ago now i'm in a dot ;)
Thanks in advance for help!
You can store your row as a label with style. In the container there will be a label instance. There you can simply add the style.
Container container = new IndexedContainer();
container.addContainerProperty(NAME_PROPERTY, Label.class , "");
for (int i = 0; i <= 50 ; i++) {
Item item = container.addItem(i);
Label label = new Label(HashUtils.getRandomSalt());
label.addStyleName(style)
item.getItemProperty(NAME_PROPERTY).setValue();
}
return container;
You can't style rows of a ListSelect. You can use a Table component with one column to achieve a similar result. Table.setCellStyleGenerator method is used for differentiating styles for each cell (each row in your case).
i'm new to pyqt , and i'm still facing some newbie problems :D
i have a QTableWidget that is item delegated on a QChoice control ( hope i said it right )
i need to have the cell background color changes whenever a user change the choice control selection
briefly: how to change a cell background color in a table widget ??
i use pyqt4 and python 2.6
thanx in advance
I used something like this:
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
item.setBackground(brush)
Where item is QTableWidgetItem object
Use
QTableWidgetItem QTableWidget.item(row, column)
and
QTableWidgetItem setData(role, data)
with
Qt.BackgroundRole
as follows:
table.item(0, 0).setData(Qt.BackgroundRole, color).
And read about the Roles mechanism used in Qt Model/View.
if you use QTableView use this:
model.setData(model.index(0, 0), QVariant(QBrush(Qt::red)), Qt::BackgroundRole);
Here are some useful lines of code. Sorry for redundancy, I'm trying to gain some reputation.
QStandardItemModel* model = new QStandardItemModel(numRows, numColumns);
QStringList headers;
headers.append("Date");
model->setHorizontalHeaderLabels(headers);
QStandardItem* item = new QStandardItem(text);
item->setData(Qt::AlignCenter, Qt::TextAlignmentRole);
item->setData(QVariant(QBrush(Qt::green)), Qt::BackgroundRole);
model->setItem(row, column, item);
or simply:
item->setBackground(Qt::green);
Hey, you set the delegate method for the table widget. in the paint event of the delegate you handle the color changing technique..
have a look at this example,here they have done custom selection color. same way you handle the item cell painting
For supplement in C++ way, if you want to paint custom color unlike Qt::red and so on, you can do something like :
ui->tableWidget->item(i, j)->setBackground(QColor(152,234,112));