formatter

Android NumberPicker with Formatter doesn't format on first rendering

a 夏天 提交于 2019-11-27 12:39:08
I have a NumberPicker that has a formatter that formats the displayed numbers either when the NumberPicker spins or when a value is entered manually. This works fine, but when the NumberPicker is first shown and I initialize it with setValue(0) the 0 does not get formatted (it should display as "-" instead of 0). As soon as I spin the NumberPicker from that point on everything works. How can I force the NumberPicker to format always - Both on first rendering and also when I enter a number manually with the keyboard? This is my formatter public class PickerFormatter implements Formatter {

Understanding the $ in Java's format strings

我的未来我决定 提交于 2019-11-27 09:22:57
问题 StringBuilder sb = new StringBuilder(); // Send all output to the Appendable object sb Formatter formatter = new Formatter(sb, Locale.US); // Explicit argument indices may be used to re-order output. formatter.format("%4$2s %3$2s %2$2s %1$2s", "a", "b", "c", "d") // -> " d c b a" In this case, why is a 2 appended to $? 回答1: The 2 has nothing to do with the $ : % = Start of format string 4$ = Fourth argument ('d') 2 = width of two (right-aligned) s = type of String 回答2: The 2$ means put the

How can I change the background color of a cell in a jqgrid custom formatter?

瘦欲@ 提交于 2019-11-27 07:54:47
I can change the text color by doing this in jqgrid custom formatter: function YNFormatter(cellvalue, options, rowObject) { var color = (cellvalue == "Y") ? "green" : "red"; var cellHtml = "<span style='color:" + color + "' originalValue='" + cellvalue + "'>" + cellvalue + "</span>"; return cellHtml; } but I want to now change the background color of the whole cell (instead of the text color). Is this possible? Oleg If you want use <span> element inside of the custom cell formatter you can return from the custom formatter return '<span class="cellWithoutBackground" style="background-color:' +

jqGrid - format ratio field as percent value

陌路散爱 提交于 2019-11-27 05:13:31
My server code transfers some column as a ratio value, 0.0 to 1.0. I need to format and edit it as a percent. I would like to do it on JavaScript side, without modifying server-side. So if I add a custom formatter to just multiply the value by 100, display works as expected. Moreover, when I hit edit button, inline edit box also displays value as percentage. The trouble starts when I save - the value gets converted with formatter one more time , giving me things like 10000. So OK, I need symmetry here, so I create an unformatter which just divides value by 100. But that doesn't work too - now

Numeric TextField for Integers in JavaFX 8 with TextFormatter and/or UnaryOperator

好久不见. 提交于 2019-11-26 22:42:23
I am trying to create a numeric TextField for Integers by using the TextFormatter of JavaFX 8. Solution with UnaryOperator: UnaryOperator<Change> integerFilter = change -> { String input = change.getText(); if (input.matches("[0-9]*")) { return change; } return null; }; myNumericField.setTextFormatter(new TextFormatter<String>(integerFilter)); Solution with IntegerStringConverter: myNumericField.setTextFormatter(new TextFormatter<>(new IntegerStringConverter())); Both solutions have their own problems. With the UnaryOperator, I can only enter digits from 0 to 9 like intended, but I also need

Java string align to right

喜夏-厌秋 提交于 2019-11-26 21:09:04
问题 I have an array of these numbers 61672 8414449 264957 I use a DecimalFormat object like this DecimalFormat formatter = new DecimalFormat("###,### bytes"); to get these results 61,672 bytes 8,414,449 bytes 264,957 bytes but I need the results to be aligned to right like the following 61,672 bytes 8,414,449 bytes 264,957 bytes Your help is already appreciated. 回答1: You can wrap it into a String.format call like this: String.format("%15s", formatter.format(i)) 来源: https://stackoverflow.com

Making Eclipse's Java code formatter ignore block comments

China☆狼群 提交于 2019-11-26 19:13:37
问题 Is there a way to make Eclipse's built-in Java code formatter ignore comments? Whenever I run it, it turns this: /* * PSEUDOCODE * Read in user's string/paragraph * * Three cases are possible * Case 1: foobar * do case 1 things * Case 2: fred hacker * do case 2 things * Case 3: cowboyneal * do case 3 things * * In all cases, do some other thing */ into this: /* * PSEUDOCODE Read in user's string/paragraph * * Three cases are possible Case 1: foobar do case 1 things Case 2: fred * hacker do

Can the Eclipse Java formatter be used stand-alone

北城以北 提交于 2019-11-26 16:28:54
问题 Is there a way to use the formatter that comes with eclipse, outside of eclipse? I would like to format some java files using my formatter.xml file that I have configured using eclipse. Does anyone have any code examples that would allow me to do this? I would also like to use this standalone, so the specific jars that are used would be nice. 回答1: Apparently you can directly invoke Eclipse's code formatter from the command line. 回答2: Never tried to pull something like that off, but I remember

Android NumberPicker with Formatter doesn't format on first rendering

笑着哭i 提交于 2019-11-26 16:05:54
问题 I have a NumberPicker that has a formatter that formats the displayed numbers either when the NumberPicker spins or when a value is entered manually. This works fine, but when the NumberPicker is first shown and I initialize it with setValue(0) the 0 does not get formatted (it should display as "-" instead of 0). As soon as I spin the NumberPicker from that point on everything works. How can I force the NumberPicker to format always - Both on first rendering and also when I enter a number

How to properly format currency on ios

给你一囗甜甜゛ 提交于 2019-11-26 13:56:46
问题 I'm looking for a way to format a string into currency without using the TextField hack. For example, i'd like to have the number "521242" converted into "5,212.42" Or if I have a number under 1$, I would like it to look like this: "52" -> "0.52" Thanks 回答1: You probably want something like this (assuming currency is a float): NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle]; NSString *numberAsString =