小编Coo*_*per的帖子

限制JavaFX TextField的字符数会导致撤消时出现IndexOutOfBounds

我要求限制用户可以输入到TextFieldJavaFX控件中的字符数.我已经延长TextField,像这样

public class LengthLimitedTextField extends TextField {
    /**
     * @param maxCharacters The max allowed characters that can be entered into this {@link TextField}.
     */
    public LengthLimitedTextField(final int maxCharacters) {
        final TextField thisField = this;
        this.textProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable,
                                String oldValue, String newValue) {
                // Force correct length by deleting the last entered character if text is longer than maxCharacters
                if (newValue.length() > maxCharacters) {
                    thisField.deleteNextChar();
                }
            }
        });
    }
} …
Run Code Online (Sandbox Code Playgroud)

java text indexoutofboundsexception javafx-2 javafx-8

6
推荐指数
2
解决办法
5890
查看次数

启用GWT SuperDev模式,启用,编译源映射,但不显示源映射

正如标题所说,我试图在Chrome中使用最新版本的GWT(2.6.1)运行SuperDev模式.

我的应用程序由Tomcat服务器提供服务.我有SuperDev模式服务器运行(通过IntelliJ),它成功编译和链接源,并在Chrome中启用源映射.我去了应用程序(http://localhost:8081/example/#example).加载时,我使用DevMode On书签进行编译.完成编译后,我在Chrome开发人员工具中看不到任何Java源代码.

我还在我的应用程序中设置了以下属性 .gwt.xml

<add-linker name="xsiframe"/> <set-configuration-property name="devModeRedirectEnabled" value="true"/> <set-property name="compiler.useSourceMaps" value="true" />

我不确定我还缺少什么?从我在网上找到的各种资源看来,我的所有基础都已覆盖,所以我不确定为什么源地图不会出现.

java gwt gwt-super-dev-mode

6
推荐指数
1
解决办法
2078
查看次数

在Java 7源代码级别编译GWT 2.6.1

我最近将我的GWT项目更新到2.6.1,并开始使用Java 7语法,因为2.6现在支持Java 7.

但是,当我尝试编译时,我收到编译器错误,如

[ERROR] Line 42: '<>' operator is not allowed for source level below 1.7

全输出

Compiling module com.Project
   Validating units:
      Ignored 85 units with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   Computing all possible rebind results for 'com.google.gwt.useragent.client.UserAgentAsserter'
      Rebinding com.google.gwt.useragent.client.UserAgentAsserter
         Checking rule <generate-with class='com.google.gwt.editor.rebind.SimpleBeanEditorDriverGenerator'/>
            [WARN] Detected warnings related to 'com.google.gwt.editor.client.SimpleBeanEditorDriver'.   Are validation-api-<version>.jar and validation-api-<version>-sources.jar on the classpath?
            Specify -logLevel DEBUG to see all errors. …
Run Code Online (Sandbox Code Playgroud)

java ant gwt

5
推荐指数
1
解决办法
2928
查看次数

使用withDefault创建地图,放置元素时导致null

我试图使用Groovy方式创建TreeMap<String, List<Data>>具有默认值的a ,以便在键不存在的情况下轻松地将数据添加到新列表中。

TreeMap<String, List<Data>> myData = (TreeMap<String, List<Data>>) [:].withDefault { [] }

如您所见,我要求使用a TreeMap并且withDefault仅返回一个Map实例,因此我需要进行强制转换。

当我尝试向地图添加新列表时,

myData[newKey].add(newData)

myData[newKey]null。但是,如果我更改Map初始化以删除强制TreeMap类型转换(并将类型更改为just Map而不是TreeMap),则myData[newKey].add(newData)可以按预期工作。

这是什么原因呢?withDefault投射地图后可以使用吗?

groovy

5
推荐指数
1
解决办法
424
查看次数

打包的电子应用程序找不到本地模块

我有一个基于电子反应样板模板项目的电子应用程序。在我的应用程序中,我在一个myClass.js文件中有一个类

app/utils/myClass.js

class MyClass {
// A bunch of stuff...
}
module.exports = MyClass;
Run Code Online (Sandbox Code Playgroud)

我在渲染器进程预加载脚本中引用了这个类。

app/utils/preload.js

const MyClass = require('./myClass.js');
Run Code Online (Sandbox Code Playgroud)

我像这样在渲染器后台工作进程中加载

const workerWindow = new BrowserWindow({
    show: false,
    webPreferences: {
      nodeIntegration: false,
      contextIsolation: true,
      preload: require('path').join(__dirname, 'utils', 'preload.js')
    }
  });
Run Code Online (Sandbox Code Playgroud)

当我在开发/调试模式下运行应用程序时,MyClass发现模块很好,所有代码都可以正常工作。但是,当我打包应用程序(使用电子生成器)并安装在 Windows 上时,运行代码会导致以下错误:

{"code":"MODULE_NOT_FOUND","requireStack":["C:\\Users\\Cooper\\AppData\\Local\\Programs\\my-app\\resources\\app\\utils\\myClass.js","C:\\Users\\Cooper\\AppData\\Local\\Programs\\my-app\\resources\\app\\utils\\preload.js"]}

出于某种原因,该应用程序找不到我的 MyClass 模块,即使我可以确认这些文件位于打包的 .asar 存档中的相应目录中。我已经尝试了许多不同的方法require来调用 MyClass 但无济于事。

为什么我打包的应用程序找不到我的 MyClass 模块?我该如何解决这个问题?值得注意的是,我的 preoload.js 脚本与任何其他依赖项都没有问题。require('electron')例如,我可以毫无问题地做到。

javascript node.js node-modules electron electron-builder

5
推荐指数
1
解决办法
764
查看次数

你能强制在类构造函数中调用一个方法,否则抛出编译错误?

我有一个类,Player,它继承自AnimatedSprite.AnimatedSprite有一个受保护的抽象方法loadAnimations,播放器必须覆盖它才能加载实际的动画(因为动画会根据精灵图像而变化,它需要由派生自AnimatedSprite的类实现).

但是,当我强制类用户实现该方法时,是否有办法强制用户实际调用此方法,最好是在Player构造函数中,以确保始终加载动画?我很确定C#没有任何语言功能可以做到这一点(虽然我可能是错的),所以也许我可以实现一个更好的类设计模式,我正在监督?

一如既往,提前谢谢!

c# inheritance xna class

4
推荐指数
1
解决办法
424
查看次数

Joda Time并根据pivot正确解析两位数年份

我有以下(略有缩写)代码来解析String输入到Joda Time DateTime对象.我需要正确处理多种格式,包括四位和两位数年份.

setupValidDateFormats();
DateTime date = convertToDateTime(thisField.getText());
if (date != null) {
    thisField.setText(date.toString("MM/dd/yyyy"));
} else {
    System.out.println("Invalid date");
}

private void setupValidDateFormats() {
    DateTimeParser[] formats = {
            DateTimeFormat.forPattern("MM/dd/yyyy").getParser(),
            DateTimeFormat.forPattern("MM/dd/yy").getParser(),
            DateTimeFormat.forPattern("MM-dd-yyyy").getParser(),
            DateTimeFormat.forPattern("MM-dd-yy").getParser(),
            DateTimeFormat.forPattern("MMddyyyy").getParser(),
            DateTimeFormat.forPattern("MMddyy").getParser()
    };
    formatter = new DateTimeFormatterBuilder().append(null, formats).appendTwoDigitYear(1950, true).toFormatter()
            .withLocale(Locale.US);
}

private DateTime convertToDateTime(String input) {
    if (isNullOrEmpty(input)) {
        return null;
    }

    DateTime date;
    try {
        // When you parse a date, it'll throw an exception for not only invalid formats,
        // but for invalid …
Run Code Online (Sandbox Code Playgroud)

java datetime 2-digit-year jodatime

4
推荐指数
1
解决办法
3711
查看次数

为什么VS2010在语法正确时会出现语法错误?

我遇到了VS2010(和VS2008)的问题,给出了一个很好的语法错误列表.但是,语法确实是正确的.这是一个小例子;

我在.h文件中有以下代码块

// Prototype Declarations
LIST*   createList     (int (*compare) (void*, void*));
LIST*   destroyList    (LIST* plist);
int     addNode      (LIST* pList, void* dataInPtr);
bool    removeNode      (LIST* pList, void* keyPtr, void** dataOutPtr);
bool    searchList      (LIST* pList, void* pArgu, void** pDataOut);
bool    retrieveNode    (LIST* pList, void* pArgu, void** dataOutPtr);
bool    traverse        (LIST* pList, int fromWhere, void** dataOutPtr);
int     listCount    (LIST* pList);
bool    isListEmpty     (LIST* pList);
bool    isListFull      (LIST* pList);
Run Code Online (Sandbox Code Playgroud)

LIST是一个typedef'd结构,FYI.所有这些函数声明似乎都是正确的语法.然而,在尝试构建时,我从第一个bool函数开始,从列表中获取以下语法错误.

错误2错误C2059:语法错误:';'

我没有看到问题出在哪里.同样,这只是一个小例子.我还收到语法错误,如下所示

bool found;
Run Code Online (Sandbox Code Playgroud)

错误29错误C2065:'bool':未声明的标识符

我真的迷失了这个.这里发布的代码不是我自己的,它来自数据结构书,但它看起来也是正确的.任何帮助,将不胜感激.谢谢!

c boolean visual-c++ visual-c++-2010

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

使用as运算符进行强制转换,即使在使用is运算符后验证C#中的类类型?

我理解通过使用as运算符来转换对象,通过显式转换,通常是更理想的,因为如果转换失败,引用变量将变为null而不是抛出异常.

但是,假设我在使用as运算符之前检查一个对象所在的类的类型,它是在List内部,就像这样,

DrawableGameComponent drawComponent;
foreach (component in Components)
{
     if (component is DrawableGameComponent)
     {
          drawComponent = component as DrawableGameComponent;

         // do something with drawComponent
     }
}
Run Code Online (Sandbox Code Playgroud)

使用as操作员是否通过is首先与操作员核实失去了它的好处?所以做下面的演员也同样好,因为我们is在尝试演员之前首先检查类类型?

if (component is DrawableGameComponent)
{
     ((DrawableGameComponent)componet).Visible = true;
}
Run Code Online (Sandbox Code Playgroud)

我只是想知道是否有一些我缺少的基础部分,或者这是否真的归结为品味使用的模式.后一种模式是否通过显式转换创建了垃圾?

提前致谢!

.net c# xna casting type-conversion

3
推荐指数
2
解决办法
189
查看次数