私はJavaのグラフィカルユーザーインターフェイスにかなり不慣れであり、現在達成しようとしていることに便利であるため、JavaのGUIライブラリのみを使用しています。私はJPanelを持っていますが、その中には...複数の問題があります。
- JEditorPaneはテキスト上にあり、JLabelを覆っています。
- JPanelの周りに境界線は表示されません。
- GUIが開くと、サイズが最小に変更されます。
- JEditorPaneのサイズは変更されていません。
- グリッドレイアウトを追加しようとしても機能しません。エラーが表示され
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string (or null)
ます。 - 初心者の質問に対する歓声の半分:境界線を追加するにはどうすればよいですか?
これが私のコードです:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import javax.activation.MimetypesFileTypeMap;
public class UpdateMechanism {
private static void showGUI() {
JFrame frame = new JFrame("The Neverhood Restoration Project");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BufferedImage icoImage = null;
try {
icoImage = ImageIO.read(
frame.getClass().getResource("/nhood.bmp"));
} catch (IOException e) {
System.out.println(e);
}
frame.setIconImage(icoImage);
JPanel heapPanel = new JPanel();
frame.setSize(new Dimension(1024, 600));
heapPanel.setBackground(new Color(0xA64343));
JLabel headerLabel = new JLabel("The Neverhood Restoration Project");
headerLabel.setHorizontalTextPosition(JLabel.CENTER);
try {
Font sFont = Font.createFont(Font.TRUETYPE_FONT, new File("DUGFB___.TTF"));
sFont = sFont.deriveFont(Font.PLAIN, 48);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(sFont);
headerLabel.setFont(sFont);
} catch (FontFormatException|IOException e) {
System.out.println(e);
}
JEditorPane updateLog = new JEditorPane();
updateLog.setSize(800, Short.MAX_VALUE);
JScrollPane scrollPane = new JScrollPane(updateLog);
updateLog.setEditable(false);
try {
updateLog.setPage("http://theneverhood.sourceforge.net/");
} catch (IOException e) {
updateLog.setContentType("text/html");
updateLog.setText("<html>The application could not load the webpage.</html>");
}
frame.add(headerLabel);
frame.add(scrollPane);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
showGUI();
}
});
}
}