假设我有如下的单向 @ManyToOne
关系:
@Entity
public class Parent implements Serializable {
@Id
@GeneratedValue
private long id;
}
@Entity
public class Child implements Serializable {
@Id
@GeneratedValue
private long id;
@ManyToOne
@JoinColumn
private Parent parent;
}
Run Code Online (Sandbox Code Playgroud)
如果我有一个父P和子C 1 ... C n引用回P,那么在JPA中有一个干净漂亮的方法可以在删除P时自动删除子C 1 ... C n(即entityManager.remove(P)
)?
我正在寻找的是类似于ON DELETE CASCADE
SQL 的功能.
假设我想分发Java应用程序.
假设我想将它作为单个可执行文件分发.我可以轻松地将一个.jar与应用程序及其所有外部依赖项一起构建在一个文件中(带有一些Ant黑客攻击).
现在假设我想在Windows上将其作为.exe文件分发.这很简单,因为那里有很好的工具(例如Launch4j等).
但是现在假设我也不想依赖于最终用户安装了正确的JRE(或者根本就是任何JRE).我想用我的应用程序分发JRE,我的应用程序应该在这个JRE上运行.创建Windows安装程序可执行文件并嵌入包含所有必需JRE文件的文件夹非常简单.但后来我正在分发安装程序而不是单文件应用程序.
有没有办法将应用程序和 JRE 嵌入到充当应用程序启动器的.exe文件中(而不是作为安装程序)?
使用AffineTransform类在Java中旋转图像时遇到一些问题.
我有以下方法来创建图像的旋转(90度)副本:
private BufferedImage createRotatedCopy(BufferedImage img, Rotation rotation) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage rot = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB);
double theta;
switch (rotation) {
case CLOCKWISE:
theta = Math.PI / 2;
break;
case COUNTERCLOCKWISE:
theta = -Math.PI / 2;
break;
default:
throw new AssertionError();
}
AffineTransform xform = AffineTransform.getRotateInstance(theta, w / 2, h / 2);
Graphics2D g = (Graphics2D) rot.createGraphics();
g.drawImage(img, xform, null);
g.dispose();
return rot;
}
Run Code Online (Sandbox Code Playgroud)
旋转是一个简单的枚举,值为NONE,CLOCKWISE和COUNTERCLOCKWISE.
我的问题的症状显示在这里:
http://perp.se/so/rotate_problems.html
因此,旋转工作正常,但生成的图像不会锚定到正确的坐标(或应该如何放置).因为我真的不知道我在做什么(我的线性代数很弱),我不知道如何自己解决这个问题.
我尝试了一些随机摆弄AffineTransform实例,但它没有帮助我(当然).我试过谷歌搜索(并搜索SO),但我见过的所有例子基本上都使用与我相同的方法...这对我不起作用.
感谢您的建议.
我有一个问题,Swing(在Java 1.6,Windows中)似乎没有像我想要的那样触发mouseEntered和mouseExited事件.我有一个应用程序,我希望在JScrollPane中有多个垂直堆叠的JPanels,并且当鼠标悬停在它们上面时,它们应该以不同的颜色突出显示.足够简单的问题,但每当我使用鼠标滚轮滚动时,它都不会表现得很好.
我做了一个示例应用程序来说明我的问题(下面的代码).下面的图片来自那个,而不是"真正的"应用程序.
当我将鼠标光标悬停在面板边缘时,它会正确突出显示.现在,当我使用鼠标滚轮向下滚动时,我希望光标在框B上方,并且触发正确的mouseEntered/mouseExited事件,使A变为白色,B变为红色.
alt text http://perp.se/so/1.png
alt text http://perp.se/so/2.png
但是,这似乎不会发生.
现在,如果我触发另一个鼠标事件,B将变为高亮显示,无论是"移动1个像素","单击按钮"还是"滚动另一个步骤".知道这一点,我也许可以用一种黑客的方式来解决它,但是如果有一个合适的解决方案我宁愿不解决.
所以基本上我想知道的是,如果这被视为Swing中的一个错误,还是我只是做错了?
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
public class ScrollTest extends JFrame {
public static class LetterPanel extends JPanel {
private static final Font BIG_FONT = new Font(Font.MONOSPACED, Font.BOLD, 24);
public LetterPanel(String text) {
setBackground(Color.WHITE);
setBorder(BorderFactory.createLineBorder(Color.BLACK));
addMouseListener(new MouseAdapter() {
@Override
public void …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Java中的本机Windows文件对话框,使用JNA来调用comdlg32函数GetOpenFileName
.我做了一个静态方法,OpenFileDialog.display
看起来像这样:
public static List<File> display(Window parent, boolean allowMultiSelect)
Run Code Online (Sandbox Code Playgroud)
它应该返回所选文件,如果用户取消了对话框,则返回null.
我有两个简单的测试程序.这个按预期工作:
package nativedialogs;
import java.io.File;
import java.util.List;
public class SimpleTest {
public static void main(String[] args) {
List<File> files = OpenFileDialog.display(null, true);
System.out.println(files);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这个不是:
package nativedialogs;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class SwingTest {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton …
Run Code Online (Sandbox Code Playgroud) 我一直被 Java 中这个老错误/缺失的功能所困扰:
https://bugs.java.com/bugdatabase/view_bug;jsessionid=b2ac8ea11f05c16d948e24d36fb5?bug_id=4673406
问题是,Java 标准打印对话框中的“属性”按钮在 Windows 上似乎始终处于禁用状态。仅当 PrintService.getServiceUIFactory() 返回不为 null 的内容时,才会启用该按钮。不幸的是 Win32PrintService 实例总是返回 null。总是。
通过谷歌搜索,我发现你可以通过调用 rundll32 来调用 Windows 自己的打印属性对话框:
rundll32 printui.dll,PrintUIEntry /e /n "name of printer here"
Run Code Online (Sandbox Code Playgroud)
我希望我可以使用它来规避 Win32PrintService 中的错误/缺失功能。但是,我不知道如何查询 PrintUIEntry 对话框以获取用户的选择。
换句话说,如何获得上述 rundll32 调用的结果?(如果我必须用 C/JNI 编写一些东西并直接使用 Windows API,那就这样吧。不过,我宁愿不这样做。)
或者有更好的方法来解决这个问题吗?
java ×6
swing ×2
windows ×2
comdlg32 ×1
deployment ×1
executable ×1
image ×1
jna ×1
jpa ×1
jpa-2.0 ×1
many-to-one ×1
mouse ×1
mouseevent ×1
mousewheel ×1
printing ×1
rotation ×1
rundll32 ×1
winapi ×1