package test;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;public class Frame1 extends JFrame {
JPanel contentPane;
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
FlowLayout flowLayout1 = new FlowLayout();
TitledBorder titledBorder1; //Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
titledBorder1 = new TitledBorder("");
contentPane.setLayout(flowLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jLabel1.setText("jLabel1");
jPanel1.setBorder(titledBorder1);
jPanel1.setDoubleBuffered(true);
contentPane.add(jPanel1, null);
jPanel1.add(jLabel1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;public class Frame1 extends JFrame {
JPanel contentPane;
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
FlowLayout flowLayout1 = new FlowLayout();
TitledBorder titledBorder1; //Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
titledBorder1 = new TitledBorder("");
contentPane.setLayout(flowLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jLabel1.setText("jLabel1");
jPanel1.setBorder(titledBorder1);
jPanel1.setDoubleBuffered(true);
contentPane.add(jPanel1, null);
jPanel1.add(jLabel1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
String canvasOutput(String str)
{
StringBuffer sb = new StringBuffer("|");
for (int i = 0; i < str.length(); i++)
sb.append("-");
sb.append("|\n|");
sb.append(str);
sb.append("|\n|");
for (int i = 0; i < str.length(); i++)
sb.append("-");
sb.append("|");
return sb.toString();
}
hayai(生命树) : 你那是绘制一个 和我例子一样的东西, 我要得边框是线条! 谢谢!
shkwh(龙威) :请问如何计算字符的精确位置信息?
谢谢大家的关注哈!
可以算出指定字体的字符串的大小
用java.awt.font参考一下http://java.sun.com/docs/books/tutorial/2d/textandfonts/linebreakmeasure.html
http://java.sun.com/docs/books/tutorial/2d/TOC.html