我想编辑我的文本对齐到中心。我已经知道你可以这样做:intro.setHorizontalAlignment(JLabel.CENTER); 使其居中。但我想这样做,这样当你做那个图标时,它就像在 microsoft word 中一样。到目前为止,这是我的程序:
import javax.swing.*;
import javax.swing.JLabel;
public class FrameStuff
{
public static void main(String[] args)
{
// Creating and setting up a regular frame
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Setting up frame characteristics
frame.setSize(800, 600);
frame.setTitle("FrameStuff");
// Making it visible
frame.setVisible(true);
//Making and assigning a new string
String textintro = new String("<html>This is my program <br/>I am having loads of fun <br/>Thanks for helping me!</html>");
// Made a new label (just happened to call it intro
JLabel intro = new JLabel(textintro );
// Set some sort of alignment within the frame
intro.setHorizontalAlignment(JLabel.CENTER);
//Add the dang label to the frame.
frame.add(intro);
}
}
我第一次使用这个和编程新手。