我在 Jlabel 中显示多行时遇到问题。我尝试使用 html 标签,但这对我没有帮助。我只是想知道为什么以下代码不起作用。我使用<br>
了标签,直到它显示在一行中。任何帮助请...
我的Java代码如下
package p1;
import javax.swing.*;
import java.awt.*;
public class MemoryUtil
{
private static final int MegaBytes = 10241024;
public static void main(String args[])
{
long freeMemory = Runtime.getRuntime().freeMemory()/MegaBytes;
long totalMemory = Runtime.getRuntime().totalMemory()/MegaBytes;
long maxMemory = Runtime.getRuntime().maxMemory()/MegaBytes;
String data="";
data= data + " <html> JVM Free Memory: " + Long.toString(freeMemory)+" MB <br>";
data=data + "Initial Heap Size of JVM : "+ Long.toString(totalMemory) +" MB <br>";
data= data + " Maximum Heap Size <br>of JVM: " + Long.toBinaryString(maxMemory) +" MB </html>";
createAndShowGUI(data);
}
private static void createAndShowGUI(String input)
{
JFrame frame = new JFrame("JVM Setting of your Machine ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout( new GridLayout());
frame.setSize(new Dimension(450, 400));
frame.setLocation(new Point(400, 200));
frame.setResizable(true);
JLabel label = new JLabel(input);
label.setFont(new Font("Serif", Font.BOLD, 20));
label.setHorizontalAlignment(JLabel.CENTER);
frame.add(label);
frame.setVisible(true);
}
}