小编Jam*_*ith的帖子

JavaFX java.lang.IllegalArgumentException:无法将javafx.scene.control.Label字段sample.Controller.location设置为java.net.URL

我的JavaFX应用程序具有fx:id为的Label location。它在FXML文件中定义。当我尝试运行该应用程序时,出现以下错误:

java.lang.IllegalArgumentException:无法将javafx.scene.control.Label字段sample.Controller.location设置为java.net.URL

我正在将JDK 12与JavaFX 11.0.2一起使用。

我在SO上看到了其他答案,说这是由locationLabel 类型冲突引起的。例如,它可以在FXML文件中声明为Label,但在Java代码中则是别的(在本例中为java.net.URL)。但是,正如您在下面的代码中看到的那样,我没有在任何地方使用URL类。

将fx:id更改为其他名称(例如loc)会使错误消失,因此location必须是一个“魔术”名称。

是什么原因造成的?

sample.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
   <children>
      <Label fx:id="location" layoutX="133.0" layoutY="146.0" text="Output" />
   </children>
</Pane>
Run Code Online (Sandbox Code Playgroud)

Main.java

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application
{

    @Override
    public void start(Stage primaryStage) throws Exception
    {
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 400, …
Run Code Online (Sandbox Code Playgroud)

java javafx fxml

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

如何使用useStyle在Material Ui中设置类组件的样式

我想使用useStyle设置类Component的样式。但这很容易实现。但我想改用Component。但是我不知道该怎么做。

import React,{Component} from 'react';
import Avatar from '@material-ui/core/Avatar';
import { makeStyles } from '@material-ui/core/styles';
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';


    const useStyles = makeStyles(theme => ({
      '@global': {
        body: {
          backgroundColor: theme.palette.common.white,
        },
      },
      paper: {
        marginTop: theme.spacing(8),
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
      },
      avatar: {
        margin: theme.spacing(1),
        backgroundColor: theme.palette.secondary.main,
      }
}));

class SignIn extends Component{
  const classes = useStyle(); // how to assign UseStyle
  render(){
     return(
    <div className={classes.paper}>
    <Avatar className={classes.avatar}>
      <LockOutlinedIcon />
    </Avatar>
    </div>
  }
}
export default SignIn;
Run Code Online (Sandbox Code Playgroud)

javascript reactjs material-ui react-component react-hooks

3
推荐指数
4
解决办法
4020
查看次数