我正在寻找一个用于在JavaScript中开发的游戏的keylistener.我不知道这在实际代码中是如何工作的,但它会是这样的.
if(keyPress == upKey)
{
playerSpriteX += 10;
}
else if(keyPress == downKey)
{
playerSpriteY -= 10;
}
Run Code Online (Sandbox Code Playgroud)
等等...
我搜索了一下,Google提出了涉及AJAX的内容,我还不明白.javascript中是否有内置函数可以执行此操作?
我在一个标签中创建了一些标签TabPane.每次我制作一个标签时,它的右侧都有一个关闭(x)按钮.我不希望从TtabPane我使用过的标签中删除标签:
TabPane tabPane = new TabPane();
Tab tab = new Tab("new tab");
tab.setContents(new Label("Please help"));
tabPane.getTabs().add(tab);
tab.setOnCloseRequest(e -> e.consume());
Run Code Online (Sandbox Code Playgroud)
这样它就不会被删除.有没有办法不在选项卡上显示此关闭按钮.
任何帮助表示赞赏.
我正在为一家小商店开发一个程序.当我单击"报告"按钮时,它必须显示一个表,如下所示:

列名"A","B"......"N"必须是员工的姓名.但我无法弄清楚如何.这是我的代码:
public void Inform()
{
String[] employee;
String[] product[];
this.setLayout(null);
Inform=new JTable(nulo, employee.length);
model = new DefaultTableModel() {
private static final long serialVersionUID = 1L;
@Override
public int getColumnCount() {
return 1;
}
@Override
public boolean isCellEditable(int row, int col) {
return false;
}
@Override
public int getRowCount() {
return Inform.getRowCount();
}
};
headerTable = new JTable(model);
for (int i = 0; i < Inform.getRowCount(); i++)
headerTable.setValueAt(product[i], i, 0);
headerTable.setShowGrid(false);
headerTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
headerTable.setPreferredScrollableViewportSize(new Dimension(50, 0));
headerTable.getColumnModel().getColumn(0).setPreferredWidth(50);
scrollPane = new JScrollPane(Inform); …Run Code Online (Sandbox Code Playgroud) I am trying to change the value of a TextField for display only. Ie - when users attempt to enter phone number, they only enter the digits and when they leave the field, it displays formatted without changing the data in the field.
Let's say I have a TextField for a phone number and it should allow digits only, maximum of 10 characters:
2085551212
I can handle that with a TextFormatter using a UnaryOperator.
UnaryOperator<TextFormatter.Change> filter = new UnaryOperator<TextFormatter.Change>() …Run Code Online (Sandbox Code Playgroud) 我认为仅通过使用app:layout_constraintTop_toBottomOf="@+id/label_proximity"就足以设置ImageView以下内容TextView。我需要使用marginTop才能使两者都TextView可见吗?或者我缺少任何属性?为什么在这种情况下约束不起作用?
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/label_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_light"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/label_proximity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_proximity"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/label_light" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/label_proximity" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud) 我有一个JLabel包含GUI中某个位置的可变文本.问题是文本显示在所在空间的底部JLabel.这不会向最终用户传达关于GUI的其他内容的相关信息.相反,我需要将文本JLabel打印在垂直轴的中间JLabel.我的代码的简化版本如下.任何人都可以告诉我如何改变它,使文本显示在垂直轴的中间而不是底部?
Main.java:
import java.awt.*;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("Main");
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(new VerticalLabel("Hello"));
Dimension prefSize = new Dimension(400, 300);
frame.setPreferredSize(prefSize);
frame.setMinimumSize(prefSize);
frame.pack();
frame.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
VerticalLabel.java:
import javax.swing.*;
import java.awt.*;
import javax.swing.border.EtchedBorder;
public class VerticalLabel extends JLabel {
public VerticalLabel(String labelText) {
Dimension myDim = new Dimension(15, 250);
this.setPreferredSize(myDim);
this.setHorizontalAlignment(LEFT);
this.setVerticalAlignment(CENTER);
this.setText(labelText);
this.setVerticalTextPosition(CENTER);
this.setUI(new VerticalLabelUI(false));
this.setBorder(new EtchedBorder());
}
}
Run Code Online (Sandbox Code Playgroud) 我在attrs.xml文件中创建一个属性:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Custom">
<attr name="src" format="integer" />
</declare-styleable>
</resource>
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我得到的属性值是这样的:attrs.getAttributeIntValue(“ mynamespace”,“ src”,-1);
有用。我从布局xml文件获取“ src”的值。但是我的问题是,为什么android在R类中不生成值,所以我不需要在Java代码中再次使用字符串'src'?
我正在尝试添加图像,tableView但我无法添加图像.
我正在获取图像,byte[]我可以设置此图像,imageView但有没有办法添加它tableView?
person3 类:
public class person3 {
private final StringProperty firstName7 = new SimpleStringProperty("");
private final StringProperty firstName8 = new SimpleStringProperty("");
public person3(String firstName4, String firstName5) {
setFirstName7(firstName4);
setFirstName8(firstName5);
}
public String getFirstName7() {
return firstName7.get();
}
public void setFirstName7(String name) {
this.firstName7.set(name);
}
public StringProperty firstNameProperty7() {
return firstName7;
}
public String getFirstName8() {
return firstName8.get();
}
public void setFirstName8(String name) {
this.firstName8.set(name);
}
public StringProperty firstNameProperty8() {
return firstName8; …Run Code Online (Sandbox Code Playgroud) 我尝试填充tableView,我遵循了docs.oracle中给出的教程,但是在我的表中有Integer字段,所以我做同样的事情来添加它们。
信息类(如Person类)中的代码:
private SimpleIntegerProperty gel;
public int getGel() {
return gel.get();
}
public void setGel(int pop) {
gel.set(pop);
}Run Code Online (Sandbox Code Playgroud)
Main该类中的代码:
TableColumn gel = new TableColumn("Gel");
gel.setMinWidth(100);
gel.setCellValueFactory(new PropertyValueFactory<Information, Integer>("gel"));
gel.setCellFactory(TextFieldTableCell.forTableColumn());
gel.setOnEditCommit(new EventHandler<CellEditEvent<Information, Integer>>() {
@Override
public void handle(CellEditEvent<Information, Integer> t) {
((Information) t.getTableView().getItems()
.get(t.getTablePosition().getRow()))
.setGel(t.getNewValue());
}
});Run Code Online (Sandbox Code Playgroud)
但我有错误:
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at javafx.util.converter.DefaultStringConverter.toString(DefaultStringConverter.java:34)
at javafx.scene.control.cell.CellUtils.getItemText(CellUtils.java:100)
at javafx.scene.control.cell.CellUtils.updateItem(CellUtils.java:201)
at javafx.scene.control.cell.TextFieldTableCell.updateItem(TextFieldTableCell.java:204)
Run Code Online (Sandbox Code Playgroud) 我正在尝试tableView使用Apache POI导出到excel
一切都很好,但是我需要导出所有表而不仅仅是项目,我的意思是使用此代码时使用列名:
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet spreadsheet = workbook.createSheet("sample");
HSSFRow row = null;
for (int i = 0; i < TousEmpSusp.getItems().size(); i++) {
row = spreadsheet.createRow(i);
for (int j = 0; j < TousEmpSusp.getColumns().size(); j++) {
row.createCell(j).setCellValue(TousEmpSusp.getColumns().get(j).getCellData(i).toString());
}
}
Run Code Online (Sandbox Code Playgroud)
它只导出项目,我试图像这样修改它:
for (int j = 0; j < TousEmpView.getColumns().size(); j++) {
row.createCell(j).setCellValue(TousEmpView.getColumns().get(j).getText());
}
for (int i = 0; i < TousEmpView.getItems().size(); i++) {
row = spreadsheet.createRow(i+1);
for (int j = 0; j < TousEmpView.getColumns().size(); …Run Code Online (Sandbox Code Playgroud) 我是新手,TableView并在JavaFx中自定义它.我已经完成了很多教程,我已经了解了一些,但是在我的表中添加了行.例如,我有一个名为的表Table1.根据我的理解,我可以创建列ArrayList和:
for (int i = 0; i <= columnlist.size() - 1; i++) {
TableView col = new TableView(columnlist.get(i));
Table1.getColumns().add(col);
}
Run Code Online (Sandbox Code Playgroud)
现在我该如何为此添加一行?如果你能给我一个非常简单的例子,我会很感激,因为我已经通过其他例子,但它们太复杂了:)
我有一个简单的javafx样本tableView.我想在列标题标签下插入一个文本字段来过滤表数据.
我找到了一个例子,但它插入了文本字段而不是标题标签,而我想同时拥有标签和文本字段:
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TableWithTextHeaders extends Application {
public static void main(String[] args) { launch(args); }
@Override
public void start(Stage stage) {
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setCellValueFactory(new PropertyValueFactory<Person,String>("firstName"));
TableColumn lastNameCol = new TableColumn("Last Name");
lastNameCol.setCellValueFactory(new PropertyValueFactory<Person,String>("lastName"));
TableColumn searchCol = new TableColumn<>();
TableView table = new TableView();
table.getColumns().addAll(firstNameCol, lastNameCol);
table.setItems(FXCollections.observableArrayList(
new Person("Jacob", "Smith"),
new Person("Isabella", "Johnson"),
new …Run Code Online (Sandbox Code Playgroud)