当我在IntelliJ中以调试模式运行我的项目时,我收到以下错误.
有谁知道原因是什么?
我已经增加了我的堆大小idea.vmoptions
:
-ea
-server
-Xms1g
-Xmx3G
-Xss16m
-Xverify:none
-XX:PermSize=512m
-XX:MaxPermSize=1024m
Run Code Online (Sandbox Code Playgroud)
我已经将编译器的堆大小增加到1024,如下所示:
我已将JOptionPane添加到我的应用程序中,但我不知道如何将背景颜色更改为白色?
`int option = JOptionPane.showConfirmDialog(bcfiDownloadPanel,
new Object[]{"Host: " + source, panel},
"Authorization Required",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE
);
if (option == JOptionPane.OK_OPTION) { }`
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中有一个textField,当用户在JList中的一个项目中单击时,它将以编程方式启动(textField.setText()).以后的用户将手动更改此值.我不得不使用文档侦听器来检测此文本字段中的更改.当以编程方式发生更改时,它必须执行任何操作,但如果手动发生,则应将背景更改为红色.
如何检测textField是手动填写还是通过textField.setText()填写?
txtMode.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
if (!mode.equals(e.getDocument()))
txtMode.setBackground(Color.red);
}
public void removeUpdate(DocumentEvent e) {
if (mode.equals(e.getDocument()))
txtMode.setBackground(Color.white);
}
public void changedUpdate(DocumentEvent e) {
//To change body of implemented methods
}
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试下载一个zip文件,但我收到了Stream Closed Exception.当我使用摇摆gui它得到这个错误,但如果我使用控制台没有问题.为什么我会得到这个例外?我该如何解决?
这是我的代码:
URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
FileOutputStream out = new FileOutputStream(destination.getPath());
byte[] b = new byte[1024];
int count;
while ((count = in.read(b)) >= 0) {
out.write(b, 0, count);
}
out.flush();
out.close();
in.close();
OptionPane.showMessageDialog(null, "Download is finished");
} catch (HttpUnauthorizedException e) {
JOptionPane.showMessageDialog(null, "Proxy or Server Authentication Required");
} catch (IOException e) {
System.out.println(e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪
java.io.IOException: Stream closed.
at java.net.PlainSocketImpl.available(PlainSocketImpl.java:428)
at java.net.SocketInputStream.available(SocketInputStream.java:217)
at java.io.BufferedInputStream.read(BufferedInputStream.java:321)
at weblogic.net.http.KeepAliveStream.read(KeepAliveStream.java:86)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at be.azvub.ext.bcfidownloder.Download.downloadZipFile(Download.java:130)
at be.azvub.ext.bcfidownloder.Download.authorize(Download.java:91) …
Run Code Online (Sandbox Code Playgroud) 当我使用以下代码下载文件时,它只是将文件写入本地目标,但文件大小都为零.有人可以说为什么会发生这种情况以及如何解决这个问题?
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import java.io.FileOutputStream;
import java.io.IOException;
public class FtpDownload {
public static void main(String[] args) {
FTPClient client = new FTPClient();
FileOutputStream fos = null;
String filename = "config.zip";
try {
client.connect("ftpsrv");
client.login("user", "user");
for (FTPFile file : client.listFiles()) {
filename = "C:\\tmp\\user\\" + file.getName();
if (file.isFile()) {
fos = new FileOutputStream(filename);
client.retrieveFile(filename, fos);
System.out.println(file.getName());
} else if (file.isDirectory()) {
System.out.println("directory: " + file.getName());
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try …
Run Code Online (Sandbox Code Playgroud) 我正在使用paintComponent()
在背景上绘制一个gif动画图像JPanel
.它显示了gif但没有动画.我使用java 1.5,我知道我可以使用带有图标的标签.
有没有人知道为什么以及如何解决它?
private static class CirclePanel extends JPanel {
ImageIcon imageIcon = new ImageIcon(BarcodeModel.class.getResource("verify.gif"));
Point point = f.getLocation();
protected void paintComponent(Graphics g) {
Graphics gc = g.create();
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
g2d.setColor(Color.BLUE);
g2d.drawImage(imageIcon.getImage(), getWidth() / 2, getHeight() / 2, null);
g2d.drawRect(0, 0, getWidth(), getHeight());
g2d.setStroke(new BasicStroke(10f,BasicStroke.CAP_ROUND,BasicStroke.JOIN_MITER));
g2d.setFont(g.getFont().deriveFont(Font.BOLD | Font.ITALIC,15f));
g2d.drawString("Wait Please ...",getWidth()/2-imageIcon.getIconHeight()/3,getHeight()/2+imageIcon.getIconHeight()+15);
g2d.dispose();
}
Run Code Online (Sandbox Code Playgroud)
这是gif图像.
编辑:只需将图像观察者添加到g2d.drawImage()方法.
g2d.drawImage(imageIcon.getImage(), getWidth() / 2, getHeight() / 2, this);
Run Code Online (Sandbox Code Playgroud) 我有对象的集合Collection basics = periodic.getGeneratedBasic();
当迭代这个集合并获取每个对象并投射它时,我可以提取每个对象的日期.现在,在这一点上,我想查看这个对象的集合,哪一个是小和最大的日期.
有谁知道这是怎么做到的吗?
Date max;
Date min;
for(Object o:basics){
Basic b = (Basic) o;
Date temp;
if(b.State=='U'){
basicAList.add(ba);
dateCollection.add(b.firstDateTime);
temp= ;
if(b.firstDateTime <)
}
}
Run Code Online (Sandbox Code Playgroud) 我想在我的swing应用程序中显示进度条,它会压缩所选文件.对于这个过程,我想在处理时显示进度条.它可能在JOptionPane或给定面板中作为实用程序的参数.
//Select a text file to be zip
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
public boolean accept(File f) {
return f.getName().toLowerCase().endsWith(".txt")
|| f.isDirectory();
}
public String getDescription() {
return "GIF Images";
}
});
String source ="";
int r = chooser.showOpenDialog(new JFrame());
if (r == JFileChooser.APPROVE_OPTION) {
source = chooser.getSelectedFile().getPath();
File file = chooser.getSelectedFile();
//Start ZIP
try {
String target = "upload/data-1.zip";
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(target));
FileInputStream fis = new FileInputStream(file);
// put a new …
Run Code Online (Sandbox Code Playgroud) 我有一个字符串,其中有许多段由点(.
)分隔,如下所示:
codes.FIFA.buf.OT.1207.2206.idu
我想得到一个子串只到第二个点,就像codes.FIFA
.
如何直到第二个点的子串?
我想将Map的所有键/值添加到二维数组中.
有没有人知道更好的方法? 我做了如下,但我寻找更好的方法.
Map<String, String> memoMap = AvoCollection.getMemoMap();
String[][] data = new String[memoMap.size()][2];
int ii =0;
for(Map.Entry entry : memoMap.entrySet()){
data[ii][0] = entry.getKey().toString();
data[ii][1] = entry.getValue().toString();
ii++;
}
final DefaultTableModel model = new DefaultTableModel(data,new String[]{"Memo","ID"});
Run Code Online (Sandbox Code Playgroud) java ×10
swing ×4
animated-gif ×1
arraylist ×1
connection ×1
date ×1
datetime ×1
ftp ×1
inputstream ×1
intellij-13 ×1
joptionpane ×1
jpanel ×1
jtextfield ×1
map ×1
progress-bar ×1
regex ×1
string ×1
substring ×1
unzip ×1
zip ×1