我正在尝试使用 Java 11 将 JDBC 连接器模块添加到我的项目中。我下载了用于 Java 11 的 MSSqlServer JDBC 驱动程序 7.2
https://www.microsoft.com/en-us/download/details.aspx?id=57782
我添加了模块:
requires com.microsoft.sqlserver.jdbc;
Run Code Online (Sandbox Code Playgroud)
然而,当我尝试清理+构建时,NetBeans 告诉我:
Error: automatic module cannot be used with jlink: com.microsoft.sqlserver.jdbc from file: /sqljdbc_7.2/enu/mssql-jdbc-7.2.2.jre11.jar
Run Code Online (Sandbox Code Playgroud)
我很确定这是因为 jar 没有编译的module-info.java. 但是,我想知道是否有办法在那里注入一个?
我有一个TableView,其中包含始终显示可写文本字段的列.如果column1的值的"BigDecimal"值大于column2的值,我想让textfield更改颜色.我可以在EditableTextCell类中对文本字段进行样式化(例如,如果文本不是有效数字),但似乎它无法访问模型以进行其他比较.这是我的代码:
EditableTextCell.java
package tester;
import java.util.Objects;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.WritableValue;
import javafx.geometry.Pos;
import javafx.scene.control.TableCell;
import javafx.scene.control.TextField;
public class EditableTextCell<E> extends TableCell<E, String>
{
private final TextField textField;
private boolean updating = false;
public EditableTextCell(boolean editable)
{
textField = new TextField();
textField.setAlignment(Pos.CENTER_RIGHT);
textField.setEditable(editable);
textField.textProperty().addListener((ObservableValue<? extends String> o, String oldValue, String newValue) ->
{
if (!updating)
{
((WritableValue<String>) getTableColumn().getCellObservableValue((E) getTableRow().getItem())).setValue(newValue);
getTableView().scrollTo(getTableRow().getIndex());
getTableView().scrollToColumn(getTableColumn());
}
// this is where I would like stylize the textfield based on the input
});
}
@Override
protected void …Run Code Online (Sandbox Code Playgroud) 我这里有一个拼写检查器演示,从视觉上看,它正是我想要的(不正确的单词有红色下划线),但我在创建右键单击上下文菜单来应用建议时遇到问题。
我能够获得该Text对象的上下文菜单,但无法使用预测找到要替换的文本在框中的位置。
这是代码:
pom.xml
<dependency>
<groupId>org.fxmisc.richtext</groupId>
<artifactId>richtextfx</artifactId>
<version>0.10.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
<type>jar</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
拼写检查演示.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.BreakIterator;
import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.StyleClassedTextArea;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyleSpansBuilder;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.ContextMenuEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import org.apache.commons.text.similarity.JaroWinklerDistance;
import org.reactfx.Subscription;
public class SpellCheckingDemo extends Application
{
private static final Set<String> dictionary = new HashSet<String>(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个选择多个日期的 DatePicker。我可以选择多个日期,但我想在选择它们时保持 DatePicker 打开。问题是,每次我选择日期时,DatePicker 都会关闭。
我不想使用私有 API。我正在考虑添加这个:
datePicker.setOnHiding(event -> {
event.consume();
});
Run Code Online (Sandbox Code Playgroud)
但这不起作用。
这是我的代码:
public static DatePicker getDatePicker() {
ObservableList<LocalDate> selectedDates = FXCollections.observableArrayList();
String pattern = "yyyy-MM-dd";
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(pattern);
DatePicker datePicker = new DatePicker();
datePicker.setPromptText(pattern);
datePicker.setConverter(new StringConverter<LocalDate>() {
@Override
public String toString(LocalDate date) {
return (date == null) ? "" : dateFormatter.format(date);
}
@Override
public LocalDate fromString(String string) {
return ((string == null) || string.isEmpty()) ? null : LocalDate.parse(string, dateFormatter);
}
});
datePicker.setOnAction(event -> {
selectedDates.add(datePicker.getValue());
event.consume();
}); …Run Code Online (Sandbox Code Playgroud) 我将此依赖项添加到我的 Spring Boot 应用程序中
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.3</version>
<type>pom.sha512</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
然后我就可以打开:https://localhost:8443/v3/api-docs
浏览器确实会询问我的凭据,只要我正确输入用户/密码,它就可以工作,但它会向我显示全局可用的所有方法。我只希望用户有权使用的方法显示在 api 文档中。
对于特定方法是使用此标签来授权我的调用:
@PreAuthorize("hasRole('USER') OR hasRole('ADMIN')")
这是我的网络安全配置类:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
{
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception
{
auth.inMemoryAuthentication()
.passwordEncoder(new BCryptPasswordEncoder())
.withUser("user").password(new BCryptPasswordEncoder().encode("blabl")).roles("USER")
.and()
.withUser("admin").password(new BCryptPasswordEncoder().encode("blabla")).roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception
{
http.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic();
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含 java.sql.Date 的列,我希望它按升序将空值放在底部:
现在,他们最终名列前茅。
followupCol.setCellFactory((TableColumn<DisabilityCase, Date> p) ->
{
TableCell<DisabilityCase, Date> cell = new TableCell<DisabilityCase, Date>()
{
@Override
protected void updateItem(Date item, boolean empty)
{
super.updateItem(item, empty);
if (item == null || empty)
{
setText(null);
} else
{
if (!LocalDate.now().isBefore(item.toLocalDate()))
{
setTextFill(Color.RED);
} else
{
setTextFill(Color.BLACK);
}
setText(new SimpleDateFormat(DATE_FORMAT).format(item));
}
}
};
return cell;
});
Run Code Online (Sandbox Code Playgroud) LineItem我正在尝试使用以下行创建金额列表的绑定:
ReadOnlyObjectWrapper<BigDecimal> total = new ReadOnlyObjectWrapper<>();
total.bind(Bindings.createObjectBinding(() -> items.stream()
.collect(Collectors.summingDouble(LineItem::getTotal)),
items));
Run Code Online (Sandbox Code Playgroud)
显然,它Collectors.summingDouble不会工作,因为它是BigDecimal. 有没有办法用 BigDecimal 来做到这一点?
LineItem.java
public class LineItem
{
private final SimpleObjectProperty<BigDecimal> amount;
public LineItem()
{
this.amount = new SimpleObjectProperty<>();
}
public BigDecimal getTotal()
{
return this.amount.get();
}
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,属性的更改将反映在总属性中......
我一直在使用 aExecutors.newScheduledThreadPool在后台运行一些任务。我将它们设置为守护线程,这样如果您使用主窗口右上角的 X 按钮退出程序,程序就会正常退出。
我尝试添加另一个 ExecutorService,仅使用第二个 ExecutorService,当您单击 X 按钮时应用程序不再退出。窗口关闭,但程序仍在运行预定的线程。
是什么赋予了?
这是代码:
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class ThreadTest extends Application
{
public final static ExecutorService executorService;
public final static ScheduledExecutorService scheduledExecutorService;
static
{
executorService = Executors.newFixedThreadPool(3);
scheduledExecutorService = Executors.newScheduledThreadPool(2, r ->
{
Thread thread = Executors.defaultThreadFactory().newThread(r);
thread.setDaemon(true);
return thread;
});
scheduledExecutorService.scheduleAtFixedRate((() ->
{
System.out.println("Scheduler thread");
}), 1, 1, TimeUnit.SECONDS); …Run Code Online (Sandbox Code Playgroud) java ×8
javafx ×6
date-range ×1
datepicker ×1
jdbc ×1
jlink ×1
openapi ×1
richtextfx ×1
spring ×1
spring-boot ×1