小编Piy*_*ush的帖子

如何使用Button Click在运行时更改子fxml gui部件

我正在尝试为一个复杂的gui构建一个骨架,因此我的想法是在javafx 2.1中使用mvc样式创建所有内容,因此每个组件都有一个fxml文件,如果需要css,controller和model.我试着弄清楚如何改变子场景(运行时的子fxml).有谁知道怎么做?我有点坚持这个.可以添加MainViewController吗?场景:用户点击任务栏中的按钮,包含的content1.fxml将替换为content2.fxml

这里是基本代码

MainApp.java

Loads the MainView.fxml
Run Code Online (Sandbox Code Playgroud)

MainView.fxml

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>


 <BorderPane xmlns:fx="http://javafx.com/fxml">
<center>
    <fx:include source="Content1.fxml"/>
</center>

<bottom>
    <fx:include source="TaskBar.fxml"/>
</bottom>

</BorderPane>
Run Code Online (Sandbox Code Playgroud)

Content1.fxml

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<StackPane xmlns:fx="http://javafx.com/fxml" fx:id="content1">
    <Label text="Hallo Java FX 2.1.1 Content1.fxml"/>
</StackPane>
Run Code Online (Sandbox Code Playgroud)

Content2.fxml

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<StackPane xmlns:fx="http://javafx.com/fxml" fx:id="content2">
    <Label text="Hallo Java FX 2.1.1 Content2.fxml"/>
</StackPane>
Run Code Online (Sandbox Code Playgroud)

TaskBar.fxml

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<HBox xmlns:fx="http://javafx.com/fxml" spacing="10" alignment="center" 
     fx:id="taskBar" fx:controller="TaskBarController">
    <children>
        <Button fx:id="taskBarButton1" onAction="#handleTaskBarButton1Action"/>     
        <Button fx:id="taskBarButton2" onAction="#handleTaskBarButton2Action"/> 
    </children>
</HBox>
Run Code Online (Sandbox Code Playgroud)

TaskBarController.java

import java.net.URL;
import java.util.ResourceBundle;

import javafx.event.ActionEvent; …
Run Code Online (Sandbox Code Playgroud)

javafx-2 fxml

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

如何在React.js中触发keypress事件

我是React.js的新手.我正在尝试触发文本div的按键事件.

这里是我要执行按键触发器的文本框代码.

<div id="test23" contenteditable="true" class="input" placeholder="type a message" data-reactid="137">Hii...</div>
Run Code Online (Sandbox Code Playgroud)

和按键方法是

onKeyPress: function(e) {
   return "Enter" == e.key ? "Enter key event triggered" : void 0)
}
Run Code Online (Sandbox Code Playgroud)

我用jquery尝试了但是我无法触发它.

这是我尝试过的React代码,但它不起作用.

var event = new Event('keypress', {
 'keyCode' : 13,
 'which' : 13,
 'key' : 'Enter'
});
var node = document.getElementById('test23');
node.dispatchEvent(event);
Run Code Online (Sandbox Code Playgroud)

谢谢 :)

javascript jquery javascript-events reactjs

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

使用for循环在文件中逐个写入行

for(i=0;i<10;i++){
    String output = output + "Result "+ i +" : "+ ans +"\n";   //ans from other logic
    FileWriter f0 = new FileWriter("output.txt");
    f0.write(output);
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用,请给一些帮助appendPrintWriter方法,我不知道如何使用这些方法.

我需要文件输出

Result 1 : 45           //here 45 is ans
Result 2 : 564856
Result 3 : 879
.
.
.
.
Result 10 : 564
Run Code Online (Sandbox Code Playgroud)

谢谢

java file-io

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

消耗500条消息后,Amazon SQS java sdk停止

我正在使用来自amazon SQS队列的消息.我在队列中有数千条消息.当我启动应用程序(使用带有spring框架的Java编写)时,它开始从队列中轮询消息,并在收到500条消息后停止.如果我再次启动应用程序它将消耗另外500条消息.

我的代码就像......

连接工厂

@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactoryActiveMQ() {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory());
    factory.setConcurrency("3-15");
    factory.setReceiveTimeout(3000L);
    return factory;
}

@Bean(name = "sqsJmsListenerContainerFactory")
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(CustomDestinationResolver resolver) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(sqsConnectionFactory());
    factory.setConcurrency("3-15");
    factory.setReceiveTimeout(3000L);
    return factory;
}
Run Code Online (Sandbox Code Playgroud)

倾听者

@JmsListener(containerFactory = "sqsJmsListenerContainerFactory", destination = "sqs.queue")
public void onMessage(Message message) {
    //Processing message
}
Run Code Online (Sandbox Code Playgroud)

我需要在亚马逊队列或连接工厂bean中配置什么?
谢谢 :-)

更新:添加了线程转储

Application正在消耗消息
,而线程转储中的DefaultMessageListenerContainer就像

"DefaultMessageListenerContainer-1@8242" prio=5 tid=0x18 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
      at java.net.SocketInputStream.socketRead0(SocketInputStream.java:-1)
      at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
      at java.net.SocketInputStream.read(SocketInputStream.java:170)
      at java.net.SocketInputStream.read(SocketInputStream.java:141)
      at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
      at sun.security.ssl.InputRecord.read(InputRecord.java:503) …
Run Code Online (Sandbox Code Playgroud)

java messaging spring-integration amazon-sqs aws-sdk

11
推荐指数
1
解决办法
1330
查看次数

JavaFX:在textArea中设置文本后,在单独的线程中设置滚动到底部不起作用

我创建了一个JavaFX应用程序,我用一个后台进程更新日志.所以我在TextArea中设置日志文本并使用设置滚动到底部logs.setScrollTop(Double.MAX_VALUE).但滚动条从底部设置为一点点.我还在ScrollPan中尝试了TextFlow,并使用设置滚动到底部logDisplay.setVvalue(1.0).它也给出了相同的结果.

Platform.runLater(() -> {
    logs.setText([setting log text]);//TextArea logs
    logs.setScrollTop(Double.MAX_VALUE));
});

//For TextFlow inside ScrollPane
Platform.runLater(() -> {
    logs.setText([setting log text]);//Text logs
    logDisplay.setVvalue(1.0);
});
Run Code Online (Sandbox Code Playgroud)

我也尝试在单独的线程中运行代码

new Thread() {
    public void run(){
        System.out.println("called set test");
        logs.setText([setting log text]);//Text logs
        logDisplay.setVvalue(1.0);
    }
}.start();
Run Code Online (Sandbox Code Playgroud)

但没有什么工作:(
你能帮我解决这个问题吗?
谢谢

- 编辑 -
看起来问题是因为线程问题.滚动条值正在更新为上一个文本值.实际上,在检索滚动值时,它不会检索最新值,但是它的值越来越大,因此滚动条设置为上一条消息的结尾,而不是实际的最后一行.

java multithreading javafx javafx-2

7
推荐指数
1
解决办法
3776
查看次数

如何使用AsciiDoclet从.java文件中的javadoc注释生成asciidoc文件

我是asciidoc的新手。我想从java文件中带注释的javadoc(asciidoc格式)生成HTML文档。

例如java文件

/**
 * = Asciidoclet
 *
 * Sample comments that include `source code`.
 *
 * [source,java]
 * --
 * public class Asciidoclet extends Doclet {
 *     private final Asciidoctor asciidoctor = Asciidoctor.Factory.create();
 *
 *     @SuppressWarnings("UnusedDeclaration")
 *     public static boolean start(RootDoc rootDoc) {
 *         new Asciidoclet().render(rootDoc);
 *         return Standard.start(rootDoc);
 *     }
 * }
 * --
 *
 * @author https://github.com/johncarl81[John Ericksen]
 */
public class Asciidoclet extends Doclet {
}
Run Code Online (Sandbox Code Playgroud)

我可以从.ad文件生成html文件,但是我不知道如何从javadoc生成.ad(或任何asciidoc格式的文件)。
所以我想生成.ad(asciidoc文件),我正在使用asciidoctor-maven-plugin生成html文档。asciidoctor-maven-plugin将在sourceDirectory中检查.ad文件,并在outputDirectory中生成html文件。

</plugin>
<plugin>
    <groupId>org.asciidoctor</groupId>
    <artifactId>asciidoctor-maven-plugin</artifactId>
    <version>${asciidoctor.version}</version>
    <executions>
        <execution>
            <id>output-html</id>
            <phase>generate-resources</phase>
            <goals> …
Run Code Online (Sandbox Code Playgroud)

java javadoc asciidoc maven maven-javadoc-plugin

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

Maven:使用 Inno Setup 脚本构建 javaFX 应用程序的本机安装程序

最近我完成了一个 JavaFX 项目,现在我想为 Windows 创建本机安装程序。我用来exec-maven-plugin创建一个安装程序,它工作正常,并使用 inno 安装脚本的默认设置生成 exe 文件。

我创建了一个名为 [project-name].iss 的 inno 安装脚本,并将其放置在app\src\main\deploy\package\windows\[project-name].iss.

我的 Maven 插件代码看起来像

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>package-jar</id>
            <phase>package</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>
                    ${env.JAVA_HOME}/bin/javapackager
                </executable>
                <arguments>
                    <argument>-createjar</argument>
                    <argument>-appclass</argument>
                    <argument>${app.main.class}</argument>
                    <argument>-srcdir</argument>
                    <argument>
                        ${project.build.directory}/classes
                    </argument>
                    <argument>-outdir</argument>
                    <argument>./target</argument>
                    <argument>-outfile</argument>
                    <argument>
                        ${project.artifactId}-app
                    </argument>
                    <argument>-v</argument>
                </arguments>
            </configuration>
        </execution>
        <execution>
            <id>package-jar2</id>
            <phase>package</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>
                    ${env.JAVA_HOME}/bin/javapackager
                </executable>

                <arguments>
                    <argument>-deploy</argument>
                    <argument>-native</argument>
                    <argument>installer</argument>
                    <argument>-appclass</argument>
                    <argument>${app.main.class}</argument>
                    <argument>-srcfiles</argument>
                    <argument>
                        ${project.build.directory}/${artifactId}-app.jar
                    </argument>
                    <argument>-outdir</argument>
                    <argument>./target</argument>
                    <argument>-outfile</argument>
                    <argument>
                        ${project.artifactId}-app
                    </argument>
                    <argument>-v</argument> …
Run Code Online (Sandbox Code Playgroud)

java javafx inno-setup maven

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

使用正则表达式过滤固定长度为0或4位的年份

我想在php或javascript中使用正则表达式过滤年份.

只包含数字,其长度为0(如果没有输入)或4如果(插入)它不接受前123的1,2或3长度.

我知道正则表达式0到4位数是^[0-9]{0,4}$^\d{0,4}$

javascript php regex

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