我正在尝试使用以下代码将图像设置为背景:
root.setStyle("-fx-background-image: url('splash.jpg');
-fx-background-position: center center;
-fx-background-repeat: stretch;");
Run Code Online (Sandbox Code Playgroud)
但它不起作用.如果我用CSS设置它,它完美地工作:
root.setId("pane");
primaryStage.getScene().getStylesheets().add(JavaFXApplication9.class.getResource("style.css").toExternalForm());
Run Code Online (Sandbox Code Playgroud)
和CSS:
#pane{
-fx-background-image: url('splash.jpg');
-fx-background-repeat: stretch;
-fx-background-position: center center;
}
Run Code Online (Sandbox Code Playgroud)
我的所有文件(主类,CSS和图像)都放在同一个包中.
那么,如何使用代码设置背景图像?或者,如何从应用程序代码中覆盖(替换)CSS中某些元素的背景图像的线条?谢谢!
我想要一个代码来使ScrollView节目具有无穷无尽的滚动一遍又一遍的相同图像.
这对于布局非常好,我想知道将它添加到ScrollView无限滚动所需的代码是什么.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" …Run Code Online (Sandbox Code Playgroud) 我试图nameField在点击Label被叫label1后使输入出现在Button被叫button1中.现在它说:'txt',我理解为什么.但我不知道如何使用字符串!谁能解释一下我做错了什么以及如何正确使用这个字符串?
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class thisismytest2 {
public static void main(String[] args) {
final JFrame frame = new JFrame();
JPanel panel = new JPanel();
JTextField nameField = new JTextField("...", 2);
JButton button1 = new JButton();
final JLabel label1 = new JLabel();
label1.setText("txt");
label1.setVisible(false);
String txt = nameField.getText();
frame.add(panel);
panel.add(button1);
panel.add(label1);
frame.setSize(200,200);
frame.setVisible(true);
panel.add(nameField);
frame.setSize(600,400);
nameField.setBounds(400, 40, …Run Code Online (Sandbox Code Playgroud) 我一直试图在构造函数之外设置场景的宽度和高度,但一直无济于事.在查看SceneAPI之后,我看到了一个方法,它可以让你分别获得高度和宽度但不能设置方法..:s(设计缺陷可能).
经过进一步的研究,我SceneBuilder发现并找到了可以修改高度和宽度的方法.但是,我不知道如何将其应用于已创建的场景对象或如何创建SceneBuilder可用于代替场景对象的对象.
我试图在自定义中绘制一条线View.在这里,我创建了一个简单Path的只有一个片段,PathShape从中创建了一个,最后将其粘贴到一个中ShapeDrawable,意图使用它在Canvas内部绘制onDraw().但是,这不起作用.在这里看我的例子.
package com.example.test;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
import android.util.Log;
import android.view.View;
public class TestView extends View {
private Path mPath = null;
private Paint mPaint = null;
private PathShape mPathShape = null;
private ShapeDrawable mShapeDrawable = null;
public TestView(Context context) {
super(context);
}
private void init() {
int width = this.getWidth() / 2;
int height = this.getHeight() / …Run Code Online (Sandbox Code Playgroud) 我想在其父窗口的中心上方打开一个对话框窗口,因此我使用以下公式:
Window window = ((Node) actionEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(new Group(new DialogWindow()));
Stage dialog = new Stage();
dialog.initOwner(window);
dialog.sizeToScene();
dialog.setX(stage.getX() + stage.getWidth() / 2 - dialog.getWidth() / 2); //dialog.getWidth() = NaN
dialog.setY(stage.getY() + stage.getHeight() / 2 - dialog.getHeight() / 2); //dialog.getHeight() = NaN
dialog.setScene(scene);
dialog.show(); //it is better to showAndWait();
Run Code Online (Sandbox Code Playgroud)
我没有手动设置大小,因为我需要自动调整窗口大小以适应其内容的大小.
在Linux下,它在父窗口的中心直接设置窗口.但是在Windows中它不起作用并导致不同的结果.
如果我不手动设置对话框的宽度和高度,怎么能得到它?
如何通过导航栏和状态栏包含屏幕大小(以像素为单位)?
我已经尝试使用大小,DisplayMetrics但大小不包括软件导航栏.
我正在Windows 8.1 64bit上开发一个JavaFX应用程序,带有4GB RAM,JDK版本为8u45 64bit.
我想捕获部分屏幕使用,Robot但问题是我无法获取我想要捕获的锚窗格的屏幕坐标,我不想使用,snapshot因为输出质量很差.这是我的代码.
我在这个链接中看到了这个问题在 JavaFX中获取Node的全局坐标, 并且这个 在javaFX中获得了一个节点的真实位置, 我尝试了每个答案,但没有任何工作,图像显示了屏幕的不同部分.
private void capturePane() {
try {
Bounds bounds = pane.getLayoutBounds();
Point2D coordinates = pane.localToScene(bounds.getMinX(), bounds.getMinY());
int X = (int) coordinates.getX();
int Y = (int) coordinates.getY();
int width = (int) pane.getWidth();
int height = (int) pane.getHeight();
Rectangle screenRect = new Rectangle(X, Y, width, height);
BufferedImage capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, "png", new File("image.png"));
} catch (IOException | AWTException ex) {
ex.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud) 我努力使含有一组Rectangle和Text对象来放大和缩小使用ScrollEvent.我无法从滚动的三角形中获取正确的比例.以下代码是我目前所拥有的.任何帮助将不胜感激.
谢谢
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.ScrollEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;
// demonstrates scaling a test pane with content in it.
public class ScaleTest extends Application {
Group page;
double textScale =1.0;
public static void main(String[] args) {
launch();
}
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("scale test");
Group root = new Group();
page= new Group();
Rectangle r = new Rectangle(300,300);
Text t …Run Code Online (Sandbox Code Playgroud) 我正在制作一个C程序,其中我有两个十六进制数,即十六进制数num1=25 num2=71.我想把它作为num3=2571然后我必须转换2571成十进制数.我该怎么做呢?请帮忙,谢谢!