LWUIT ComboBox Text Color Issue - java-me

The ComboBox text color is white even though I've set it to black in my theme. The text color of TextField is black as supposed to. How come the ComboBox text color isn't black?
The theme:
fgColor=FFFFFF
bgColor=000000
sel#fgColor=FFFFFF
sel#bgColor=EE8207
ComboBox.fgColor=000000
ComboBox.bgColor=FFFFFF
ComboBox.sel#fgColor=000000
ComboBox.sel#bgColor=FFFFFF
TextField.fgColor=000000
TextField.bgColor=FFFFFF
TextField.sel#fgColor=000000
TextField.sel#bgColor=FFFFFF

You can change the text color like this
Style selStyle = UIManager.getInstance().getComponentSelectedStyle("ComboBoxItem");
selStyle.setFgColor(0x00AF00); // Selected Item will be in green color
UIManager.getInstance().setComponentSelectedStyle("ComboBoxItem", selStyle);
Style unSelStyle = UIManager.getInstance().getComponentStyle("ComboBoxItem");
unSelStyle.setFgColor(0x000000); // Selected Item will be in black color
UIManager.getInstance().setComponentStyle("ComboBoxItem", unSelStyle);
This will work out!!

You should use hexColors: "0x000000" or "0xffffff"
You can also set the color in your app using following methods.
lwuit uses int's to set a color, to calculate the int use the following function.
public static int colorStringToInt(String hexColor) {
int color;
try {
color = Integer.parseInt(hexColor.substring(2), 16);
return color;
} catch (Exception ex) {
ex.printStackTrace();
return -1;//no negative colors
}
}
set the color like this.
int color = AppUtils.colorStringToInt("0xffffff");//white
if (color != -1) {
b.getStyle().setFgColor(color, true);
}

you can use like this,
ComboBoxItem.fgColor=000000
ComboBoxItem.sel#fgColor=ffffff
Are you using ResourceEdit. If u r not using means use the ResourceEdit and create the theme.

Related

Draw shape over Text with Modifier in Jetpack Compose

I am trying to obfuscate some text with Jetpack Compose. Obviously, the blur modifier works wonders for this use case if you have Android 12.
My alternative for devices running a lower API version would be to simply draw a rectangle with a black colour over the text. I assumed this would be relatively easy with existing modifiers like graphicsLayer or drawBehind but I haven't been able to figure it out and I'm at a loss for ideas right now...
My current text composable looks like this:
Text(
modifier = if (blurText) {
Modifier.blur(16.dp, BlurredEdgeTreatment.Unbounded)
} else {
Modifier
},
text = textToObfuscate,
fontFamily = latoFontFamily,
fontWeight = FontWeight.W700,
fontSize = 16.sp,
color = black,
)
I could wrap the text in a Box and have another Box inside it to draw over the Text but that just seems useless and more work than should be necessary.
If anyone has any ideas on how to achieve this simply using a Modifier extension, that would be amazing!
You can use Modifier.drawWithContent as
Text(
modifier = if (blurText) {
Modifier.blur(16.dp, BlurredEdgeTreatment.Unbounded)
} else {
Modifier.drawWithContent {
drawContent()
drawRect(Color.Black)
}
},
text = "textToObfuscate",
fontWeight = FontWeight.W700,
fontSize = 16.sp,
)

Displaying javafx 2 linechart values on hover

I have been using this example for my project, and it works really nice.
My question: Is it possible to offset the hovered node such that it does not overlay the underlying data point. The example centers the hovered node right over the "normal" node. It kind of gets in the way on a chart with a lot of data points.
A simple solution is to set a custom translation to the displayed Label. The following code is extracted from the example.
private Label createDataThresholdLabel(int priorValue, int value)
{
final Label label = new Label(value + "");
label.setTranslateY(-25); //Move label 25 pixels up
label.getStyleClass().addAll("default-color0", "chart-line-symbol", "chart-series-line");
label.setStyle("-fx-font-size: 20; -fx-font-weight: bold;");
if (priorValue == 0)
{
label.setTextFill(Color.DARKGRAY);
}
else if (value > priorValue)
{
label.setTextFill(Color.FORESTGREEN);
}
else
{
label.setTextFill(Color.FIREBRICK);
}
label.setMinSize(Label.USE_PREF_SIZE, Label.USE_PREF_SIZE);
return label;
}

Javafx change PieChart color

I have a list of color representing a color sequence. I want to apply the new color sequence to the piechart data.
private final int CASPIAN_COLOR_COUNTS = 8;
public void setPieChartColor(PieChart chart, List<String> colors) {
chart.getData().get(i); // for debug to get the node name (.data)
/**
* Set Pie color
*/
int i = 0;
for (String color : colors) {
final Node node = chart.lookup(".data" + i);
node.getStyleClass().remove("default-color" + (i % CASPIAN_COLOR_COUNTS));
node.getStyleClass().add(color);
i++;
}
but all chart data take Only one color from Caspian color.
You can achieve custom pie colors in code using a method such as:
private void applyCustomColorSequence(
ObservableList<PieChart.Data> pieChartData,
String... pieColors) {
int i = 0;
for (PieChart.Data data : pieChartData) {
data.getNode().setStyle(
"-fx-pie-color: " + pieColors[i % pieColors.length] + ";"
);
i++;
}
}
Note that the method must be applied after the chart has been shown on an active scene (otherwise the data.getNode() call will return null).
Here is some sample code which uses it.
You can accomplish the same effect using css stylesheets.
For example a css stylesheet containing the following style definitions will change the default colors of a pie chart when the stylesheet is applied against a given chart.
.default-color0.chart-pie { -fx-pie-color: #ffd700; }
.default-color1.chart-pie { -fx-pie-color: #ffa500; }
.default-color2.chart-pie { -fx-pie-color: #860061; }
.default-color3.chart-pie { -fx-pie-color: #adff2f; }
.default-color4.chart-pie { -fx-pie-color: #ff5700; }
For an example of the stylesheet based approach: see the "Setting Colors of a Pie Chart" section of the Styling Charts with CSS tutorial.
The stylesheet approach has an advantage that the styles are separated from the code. It has the disadvantage that the colors are must be set the time the stylesheet are created rather than at runtime and the color sequence is restricted to a fixed number of colors (8).
In general, the stylesheet approach is recommended for most applications.
The css styles might not work if your values are negative. This might be a bug but I had to convert my values to positive values for the styles to work. When the values were negative all pies were white in color.

UI is not fixed on painting the background in VerticalFieldManager in BlackBerry?

I have prepared a screen in which I am allowing user to create an account. as shown in the first image I have used an image(bg_BB.png image) as MainScreen Background, after that i have taken another VFM and painting that white Background (white_bg2.png)on that vertical field manager and ADDING ALL MY FIELD ON THAT VFM.
But the problem arises when the keyboard is pops-up. All the fields apears to be floating over the background as shown in the second pic.
Below is the code which I am using:
Bitmap backGroundImage = Bitmap.getBitmapResource("bg_BB.png");
((VerticalFieldManager) getMainManager()).setBackground(BackgroundFactory.createBitmapBackground(backGroundImage));
final Bitmap tabBackGroundImage = Bitmap.getBitmapResource("white_bg2.png");
_mainVfm = new VerticalFieldManager(Field.USE_ALL_WIDTH) {
protected void paint(Graphics graphics) {
int y = CreateUserAccountScreen.this.getMainManager().getVerticalScroll();
graphics.drawBitmap(0, y,
tabBackGroundImage.getWidth(),
tabBackGroundImage.getHeight(),
tabBackGroundImage,
0, 0 );
super.paint( graphics );
}
};
replace your code with:
Bitmap tabBackGroundImage = Bitmap.getBitmapResource("white_bg2.png");
VerticalFieldManager _mainVfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL |
Manager.VERTICAL_SCROLLBAR|
Manager.USE_ALL_WIDTH);
_mainVfm.setBorder( BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), tabBackGroundImage
)
);
make sure that your border image have white background.
i use this method and it works perfectly.

Hide the border of the selected cell in qtablewidget in pyqt?

Is there a way i can hide the border of the selected cell(or make the border color as white)in a qtablewidget.. By default a border with dotted line is shown.. Can u help me...
I prefer to do:
ui->tableWidget->setFocusPolicy(Qt::NoFocus);
You can also change the focus policy using the design tab.
It looks like this dotted border around selected cell you're trying to hide is a focus rectangle. Any given cell can have focus and not be selected at the same time and vice-versa. If you want this border to not get painted use an item delegate. There you can remove State_HasFocus style from the item's state before painting it. Pls, see an example below on how to do this, it's c++, let me know if you have troubles converting it to python
// custom item delegate class
class NoFocusDelegate : public QStyledItemDelegate
{
protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
};
void NoFocusDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const
{
QStyleOptionViewItem itemOption(option);
if (itemOption.state & QStyle::State_HasFocus)
itemOption.state = itemOption.state ^ QStyle::State_HasFocus;
QStyledItemDelegate::paint(painter, itemOption, index);
}
...
// set the item delegate to your table widget
ui->tableView->setItemDelegate(new NoFocusDelegate());
hope this helps, regards
Qt::NoFocus will remove the selected state of rows in QTableWidget.
The Python3/PySide2 version to the accepted answer:
class NoFocusDelegate(QtWidgets.QStyledItemDelegate):
def paint(self, painter: PySide2.QtGui.QPainter, option: PySide2.QtWidgets.QStyleOptionViewItem, index: PySide2.QtCore.QModelIndex) -> None:
itemOption = QtWidgets.QStyleOptionViewItem(option)
if option.state & QtWidgets.QStyle.State_HasFocus:
itemOption.state = itemOption.state ^ QtWidgets.QStyle.State_HasFocus
super().paint(painter, itemOption, index)
table.setItemDelegate(NoFocusDelegate())
Worked perfectly for me.

Resources