用Java编写一段打印字体的代码,frame中显示了JScrollPane,但是不显示JTextArea,这是为什么???
importjava.awt.*;importjavax.swing.*;@SuppressWarnings("serial")publicclassFontDispla...
import java.awt.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class FontDisplay extends JFrame
{
private JScrollPane panel;
public FontDisplay(int w,int h)
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenW = screenSize.width;
int screenH = screenSize.height;
this.setBounds(screenW / 2 - w / 2,screenH / 2 - h / 2,w,h);
this.setTitle("FontDisplay");
this.getContentPane().setBackground(Color.WHITE);
this.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
this.panel = new JScrollPane();
}
public static void main(String[] args)
{
FontDisplay display = new FontDisplay(500,400);
display.addTextArea();
display.add(display.panel);
display.setVisible(true);
}
public void addTextArea()
{
JTextArea area = new JTextArea();
String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();
for(String s : fonts)
{
area.append(s + "\n");
}
System.out.print(area.getText());
this.panel.add(area);
area.setLineWrap(true);
}
} 展开
import javax.swing.*;
@SuppressWarnings("serial")
public class FontDisplay extends JFrame
{
private JScrollPane panel;
public FontDisplay(int w,int h)
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenW = screenSize.width;
int screenH = screenSize.height;
this.setBounds(screenW / 2 - w / 2,screenH / 2 - h / 2,w,h);
this.setTitle("FontDisplay");
this.getContentPane().setBackground(Color.WHITE);
this.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
this.panel = new JScrollPane();
}
public static void main(String[] args)
{
FontDisplay display = new FontDisplay(500,400);
display.addTextArea();
display.add(display.panel);
display.setVisible(true);
}
public void addTextArea()
{
JTextArea area = new JTextArea();
String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();
for(String s : fonts)
{
area.append(s + "\n");
}
System.out.print(area.getText());
this.panel.add(area);
area.setLineWrap(true);
}
} 展开
1个回答
2014-05-11
展开全部
this.panel = new JScrollPane(area);
把代码修改成这样,简单地处理。
把代码修改成这样,简单地处理。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询