小编voi*_*oid的帖子

如何在TextField中的文本更改时获取事件?JavaFX的

每当TextField的文本发生变化时,如何生成新事件来处理?

events javafx textfield

11
推荐指数
2
解决办法
2万
查看次数

Android系统.CheckBoxPreference颜色

如何更改CheckBoxPreference的复选框颜色?我指定主题属性不起作用.我也在清单中设置了主题,但它没有用强调色显示,而是用默认颜色显示.

在此输入图像描述

表现:

<activity android:name=".ui.activities.AppPreferencesActivity"
android:theme="@style/PreferencesTheme"/>
Run Code Online (Sandbox Code Playgroud)

样式:

<style name="PreferencesTheme">
    <item name="colorAccent">#FF4081</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?提前致谢.

checkbox android colors preferenceactivity

9
推荐指数
3
解决办法
2481
查看次数

如何限制TextField,使其只能包含一个'.' 字符?JavaFX的

在Internet上,我发现了非常有用的类,使用它我可以限制TextField.我遇到了一个问题,我的TextField只能包含一个'.' 字符.我怀疑我可以通过编写appripriate正则表达式并将其设置为对该类实例的限制来处理此问题.我使用以下正则表达式:"[0-9.-]",但它允许与用户类型一样多的点.我可以请你帮我配置我的TextField,使其不超过一个'.' 被允许.

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.TextField;

/**
 * Created by Anton on 7/14/2015.
 */
public class RestrictiveTextField extends TextField {
private IntegerProperty maxLength = new SimpleIntegerProperty(this, "maxLength", -1);
private StringProperty restrict = new SimpleStringProperty(this, "restrict");

public RestrictiveTextField() {
    super("0");
    textProperty().addListener(new ChangeListener<String>() {

        private boolean ignore;

        @Override
        public void changed(ObservableValue<? extends String> observableValue, String s, String s1) {

            if (ignore || s1 == null)
                return;
            if (maxLength.get() > -1 && …
Run Code Online (Sandbox Code Playgroud)

java regex javafx textfield

3
推荐指数
1
解决办法
1万
查看次数

验证 Java 中的字符串是否为 UTF-8 编码

有很多方法可以检查字符串是否是 UTF-8 编码的,例如:

public static boolean isUTF8(String s){
    try{
        byte[]bytes = s.getBytes("UTF-8");
    }catch(UnsupportedEncodingException e){
        e.printStackTrace();
        System.exit(-1);
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

的文档java.lang.String#getBytes(java.nio.charset.Charset)说:

此方法始终用此字符集的默认替换字节数组替换格式错误的输入和不可映射的字符序列。

  1. 它总是返回正确的 UTF-8 字节是否正确?
  2. String对对象执行此类检查是否有意义?true当 String 对象已经编码时,它不会总是返回吗?
  3. 据我了解,此类检查应该在字节上执行,而不是在String对象上执行:
public static final boolean isUTF8(final byte[] inputBytes) {
    final String converted = new String(inputBytes, StandardCharsets.UTF_8);
    final byte[] outputBytes = converted.getBytes(StandardCharsets.UTF_8);
    return Arrays.equals(inputBytes, outputBytes);
}
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,我不确定我是否理解应该从哪里获取这些butes,因为直接从对象中获取它String是不正确的。

java string encoding utf-8 utf-16

3
推荐指数
1
解决办法
1万
查看次数

一些 AtomicInteger 方法的实际例子

能否请您帮助我掌握 AtomicInteger 类的一些方法的要点:updateAndGet, accumulateAndGet.

为什么第一个接收IntUnaryOperator作为参数?在这个接口的功能方法中可以应用什么逻辑?我的想法是,获得普通int价值会更容易。(与IntBinaryOperator界面相同)。

提前致谢。

java integer atomic atomicinteger

2
推荐指数
1
解决办法
1059
查看次数

Log4j2 路由附加器 JavaScript 配置错误

我正在使用 lombok 的 log4j2 记录器,我需要根据 ThreadContext 映射配置路由附加程序。路由键由脚本确定。这是整个 log4j2.xml 配置文件:

<Appenders>
    <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout pattern="%highlight{%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %c{1}: %msg%n%throwable}"/>
    </Console>

    <RollingFile name="GeneralRollingFile" filename="log/test-log.log"
                 filepattern="log/test-log-%d{yyyy-MM-dd HH:mm:ss}.log">
        <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %c{1}: %msg%n%throwable"/>
        <Policies>
            <SizeBasedTriggeringPolicy size="25 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="20"/>
    </RollingFile>

    <Routing name="Routing">

        <Routes>
            <Script name="RoutingInit" language="JavaScript">
                <![CDATA[
                if (logEvent.getContextMap().containsKey("operation-1")) {
                    return "operation-1";
                } else if (logEvent.getContextMap().containsKey("operation-2")) {
                    return "operation-2";
                } else {
                    return "general";
                }
            ]]>
            </Script>

            <Route key="general" ref="GeneralRollingFile"/>

            <Route key="operation-1"> 
                <RollingFile name="operation-1-rolling"
                             fileName="log/operation-1/${ctx:operation-1}.log"
                             filePattern="log/operation-1/${ctx:operation-1}-%d{yyyy-MM-dd HH:mm:ss}.log">

                    <PatternLayout pattern="%d{yyyy-MM-dd …
Run Code Online (Sandbox Code Playgroud)

javascript java logging appender log4j2

2
推荐指数
1
解决办法
1603
查看次数

在Java中建立关系

我知道,有两种方法可以在java中建立before-before关系:synchronized块和方法,volatile关键字.(如果我是正确的,它不适用于最终字段).我的问题是:并发包中的原子变量是否相似?可以发生 - 之前由他们建立?

java concurrency multithreading java.util.concurrent happens-before

0
推荐指数
1
解决办法
191
查看次数