日期:2014-05-20  浏览次数:20985 次

新手学习java,关于自定义窗口显示文本内容时,内容出现省略号
窗口大小设置为setSize(605,403)
文本大小设置为textJLabel.setSize(400,88);
文本内容是Welcome to Java Programming!
这时候会出现省略号,可当文本大小超过550后,就会完整显示出来
源代码如下
import java.awt.*;
import javax.swing.*;

public class Welcome extends JFrame
{
private JLabel textJLabel; // JLabel that displays text
private JLabel pictureJLabel; // JLabel that displays an image

// no-argument constructor
public Welcome()
{
  createUserInterface();
}

// create and position GUI components; register event handlers
private void createUserInterface()
{
  // get content pane and set layout to null
  Container contentPane = getContentPane();
  contentPane.setBackground( Color.BLACK);
  contentPane.setLayout( null );
   
  // set up textJLabel
  textJLabel = new JLabel(); //分配空间
  textJLabel.setText( "Welcome to Java Programming!" );
  textJLabel.setLocation(10,40);
  textJLabel.setSize(500,88);
  textJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 36 ) );
  textJLabel.setHorizontalAlignment( JLabel.CENTER );
  contentPane.add( textJLabel );
   
  // set up pictureJLabel
  pictureJLabel = new JLabel();
  pictureJLabel.setIcon( new ImageIcon( "bug.png" ) );
  pictureJLabel.setBounds( 54, 120, 500, 250 );
  pictureJLabel.setHorizontalAlignment( JLabel.CENTER );
  contentPane.add( pictureJLabel );

  // set properties of application's window
  setTitle( "Welcome to pengbin's world" ); // set JFrame's title bar string
  setSize( 605,413 ); // set width and height of JFrame
  setVisible( true ); // display JFrame on screen

} // end method createUserInterface

// main method
public static void main( String[] args )
{
  Welcome application = new Welcome();
  application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

} // end method main

} // end class Welcome

------解决方案--------------------
因为你文字太大了,你把文字大小改成32以下你看看。所以你要么改变JLabel组件大小,要么改变文字大小。