如何将背景图片调整为窗口大小?

时间:2019-03-31 19:27:59

标签: java eclipse javafx background-image image-resizing

如何获取将背景图像调整为窗口大小的应用程序?每当程序启动时,它仅显示图像的一部分,而不显示整个图像。

我尝试使用以下代码行:

export default class TodayWeather extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      latitude: '',
      longitude: ''
    };
  }

  getMyLocation = (getData) => {
    const location = navigator.geolocation;
    if (location) {
      location.getCurrentPosition((position) => {
        getData(position);
      });
    }
  };

  getWeather = () => {
    const getData = (position) => {
      this.setState({
        latitude: position.coords.latitude,
        longitude: position.coords.longitude
      });

      const API = `http://api.openweathermap.org/data/2.5/forecast?lat=${
        position.coords.latitude
      }&lon=139&appid=${apiKey}`;

      fetch(API)
        .then((response) => {
          if (response.ok) {
            return response;
          }
          throw Error('');
        })
        .then((response) => response.json())
        .then((data) => {
          const time = new Date().toLocaleString();
          this.setState({ time });
        });
    };

    this.getMyLocation(getData);
  };

  componentDidMount() {
    this.getWeather();
  }

  render() {
    return (
      <div className="App">
        <Result className="result" weather={this.state} />
        <p> {this.state.latitude} </p>
      </div>
    );
  }
}

但是,背景图像只会完全消失。

以下是我要使用的一些代码:

bpane.setStyle("-fx-background-size: cover, auto;");

我需要的是将图像缩小到当前窗口的大小,或者至少要看到大部分图像。

请帮助!

0 个答案:

没有答案