本题的功能是在文本域面板中添加一个带有行数的面板。窗口中有一个文本域,在文本域的左侧有一个带有数字的面板,该面板上的数字指示着文本域中的行数。import javax.swing.*;import javax.swing.event.*;import java.awt.*;public class java3 extends JFrame{public static JTextPane textPane;public static JScrollPane scrollPane;JPanel panel;public java3(){super("java3()");panel=new JPanel();panel.setLayout(new BorderLayout());panel.setBorder(BorderFactory.createEmptyBor-der(20,20,20,20));textPane=new JTextPane();textPane.setFont(new Font("monospaeed",Font.PLAIN,12));scrollPane=new JScrollPane(textPane);panel.add(scrollPane);scrollPane.setPreferredsize(new Dimension(300,250));setContentPane(panel);setCloseOperation(JFrame.EXIT_ON_CLOSE);LineNumber lineNumber=new LineNumber();scrollPane.setRowHeaderView(lineNumber);}public static void main(String[]args){java3 ttp=new java3();ttp.pack();ttp.setVisible(true);}}class LineNumber extends JTextPane{private final static Color DEFAULT_BACK-GROUND=Color.gray;private final static Color DEFAULT_FORE-GROUND=Color.black;private final static Font DEFAUl。T—FONT=newFont("monospaced",Font.PLAIN,12);private final static int HEIGHT=Integer.MAX_VALUE-1000000;private final static int MARGIN=5;private FontMetrics fontMetrics;private int lineHeight;private int currentRowWidth;private JComponent component;private int componentFontHeight;private int componentFontAscent;public LineNumber(JComponent component){if(component= =null){setBackground(DEFAULT_BACKGROUND);setForegroun"DEFAULT_FOREGROUND);setFont(DEFAULT FONT);this.component=this;}else{setBaekground(DEFAULT_BACKGROUND);setForeground(component.getForeground());setFont(component.getFont());this.component=component;}componentFontHeight=component.getFontMet-rics(component.getFont()).getHeight();componentFontAscent=component.getFontMet-ries(component.getFont()).getAscent();setPreferredWidth(9999);}public void setPreferredWidth(int row){int width=fontMetrics.stringWidth(String.val-ueOf(row));if(currentRowWidth<width){currentRowWidth=width;setPreferredSize(new Dfimension(2 * MARGIN+width,HEIGHT));}}public void setFont(Font font){super.setFont(font);fontMetrics=getFontMetrics(getFont());}public int getLineHeight(){if(hneHeight= =0)return componentFontHeight;elsereturn lineHeight;}public void setLineHeight(int lineHeight){if(hneHeight>0)this.lineHeight=lineHeight;}public int getStartOffset(){return component.getlnsets().top+component-FontAscent;}public void paintComponent(Graphics g){int lineHeight=getLineHeight();int startOffset=getStartOffset();Rectangle drawHere=g.getClipBounds();g.setColor(getBackground());g.fillRect(drawHere.x,drawHere.Y,drawHere.width,drawHere.height);g.setColor(getForeground());int startLineNumber=(drawHere.y/line-Height)+1;int endLineNUmber = startLineNumber+(drawHere.height/lineHeight);int start=(drawHere.Y/hneHeight)*line-Height+startOffset;for(int i=startLineNumber;i<=endLineN-umber;i++){String lineNumber=String.valueOf(i);int width=fontMetrics.stringWidth(lineNumber);g.drawstring(lineNumber,MARGIN+current-RowWidth-width,start);start+=lineHeight:}setPreferredWidth(endLineNumber);}}

本题的功能是在文本域面板中添加一个带有行数的面板。窗口中有一个文本域,在文本域的左侧有一个带有数字的面板,该面板上的数字指示着文本域中的行数。

import javax.swing.*;

import javax.swing.event.*;

import java.awt.*;

public class java3 extends JFrame

{

public static JTextPane textPane;

public static JScrollPane scrollPane;

JPanel panel;

public java3()

{

super("java3()");

panel=new JPanel();

panel.setLayout(new BorderLayout());

panel.setBorder(BorderFactory.createEmptyBor-

der(20,20,20,20));

textPane=new JTextPane();

textPane.setFont(new Font("monospaeed",

Font.PLAIN,12));

scrollPane=new JScrollPane(textPane);

panel.add(scrollPane);

scrollPane.setPreferredsize(new Dimension(300,

250));

setContentPane(panel);

setCloseOperation(JFrame.EXIT_ON_CLOSE);

LineNumber lineNumber=new LineNumber();

scrollPane.setRowHeaderView(lineNumber);

}

public static void main(String[]args)

{

java3 ttp=new java3();

ttp.pack();

ttp.setVisible(true);

}

}

class LineNumber extends JTextPane

{

private final static Color DEFAULT_BACK-

GROUND=Color.gray;

private final static Color DEFAULT_FORE-

GROUND=Color.black;

private final static Font DEFAUl。T—FONT=new

Font("monospaced",Font.PLAIN,12);

private final static int HEIGHT=Integer.MAX_

VALUE-1000000;

private final static int MARGIN=5;

private FontMetrics fontMetrics;

private int lineHeight;

private int currentRowWidth;

private JComponent component;

private int componentFontHeight;

private int componentFontAscent;

public LineNumber(JComponent component)

{

if(component= =null)

{

setBackground(DEFAULT_BACKGROUND);

setForegroun"DEFAULT_FOREGROUND);

setFont(DEFAULT FONT);

this.component=this;

}

else

{

setBaekground(DEFAULT_BACKGROUND);

setForeground(component.getForeground());

setFont(component.getFont());

this.component=component;

}

componentFontHeight=component.getFontMet-

rics(component.getFont()).getHeight();

componentFontAscent=component.getFontMet-

ries(component.getFont()).getAscent();

setPreferredWidth(9999);

}

public void setPreferredWidth(int row)

{

int width=fontMetrics.stringWidth(String.val-

ueOf(row));

if(currentRowWidth<;width)

{

currentRowWidth=width;

setPreferredSize(new Dfimension(2 * MARGIN

+width,HEIGHT));

}

}

public void setFont(Font font)

{

super.setFont(font);

fontMetrics=getFontMetrics(getFont());

}

public int getLineHeight()

{

if(hneHeight= =0)

return componentFontHeight;

else

return lineHeight;

}

public void setLineHeight(int lineHeight)

{

if(hneHeight>;0)

this.lineHeight=lineHeight;

}

public int getStartOffset()

{

return component.getlnsets().top+component-

FontAscent;

}

public void paintComponent(Graphics g)

{

int lineHeight=getLineHeight();

int startOffset=getStartOffset();

Rectangle drawHere=g.getClipBounds();

g.setColor(getBackground());

g.fillRect(drawHere.x,drawHere.Y,drawHere.

width,drawHere.height);

g.setColor(getForeground());

int startLineNumber=(drawHere.y/line-

Height)+1;

int endLineNUmber = startLineNumber+

(drawHere.height/lineHeight);

int start=(drawHere.Y/hneHeight)*line-

Height+startOffset;

for(int i=startLineNumber;i<;=endLineN-

umber;i++)

{

String lineNumber=String.valueOf(i);

int width=fontMetrics.stringWidth(lineNumber

);

g.drawstring(lineNumber,MARGIN+current-

RowWidth-width,start);

start+=lineHeight:

}

setPreferredWidth(endLineNumber);

}

}


相关考题:

在文本域属性设置面板里,设置用于文本域的CSS样式的属性是()。 A.类型B.类C.文本域D.初始值

下列关于域控件的说法,错误的是A.从数据环境设置器中,每拖放一个字段到报表设置器中就是一个域控件B.域控件用于打印表或视图中的字段、变量和表达式的计算结果C.域控件的“表达式生成器”对话框中的“表达式”文本框中必须要有数值表达式,否则将不能添加该域控件D.如果域控件的“表达式生成器”对话框中的“表达式”文本框中没有数值表达式,可在“格式”文本框中设置表达式添加该域控件

在一个Windows域树中,第一个域被称为()。A.信任域B.树根域C.子域D.被信任域控制面板

本题的功能是用按钮来控制文本框中文本的颜色。窗口中有两个带有文字标题的而板“Sample text”和“Text col-or control”。窗口的底部还有一个复选按钮“Disable changes”。在“Sample text”面板中有一个带有字符串的文本框,而在“Text color control”面板中有三个按钮:“Black”、“Red”和“Green”,并且每个按钮上都有一个对应颜色的圆。单击任意按钮,文本框中的文本变成对应的颜色,如果选中“Dis—able changes”复选项,则三个颜色按钮变为不可用,如果取消选中复选项,则三个按钮变为可用。

在DreamweaverCS4表单中,关于文本域说法错误的是() A.密码文本域输入值后显示为“*”B.多行文本域不能进行最大字符数设置C.密码文本和单行文本域一样,都可以进行最大字符数的设置D.多行文本域的行数设定以后,输入内容将不能超过设定的行数

在Dreamweaver中插入单行文本域时,下面不是文本域形式的是()A、限制行域B、单行域C、密码域D、多行域

表单域是获得用户在表单中输入文本的主要方式。其中有3种类型的表单域,不属于这3种类型的是?()A、文本域B、文件域C、隐藏域D、图像域

表单中有哪些表单域,如何设置密码文本域?

文本域标签是〈textarea〉可以通过标签中的height属性来设置文本域。

根据文本域的行数和显示方式,文本域可分为单行、多行、和()3种。

要想在浏览窗口的状态栏显示文本消息,应在“添加行为”——“设置文本”菜单中选择()命令。A、设置框架文本B、设置层文本C、设置状态条文本D、设置文本域文本

文本域标签是〈textarea〉可以通过标签中的height属性来设置文本域有多少行。

关于文本域的说法错误的是()。A、在【属性】面板中可以设置文本域的字符宽度B、在【属性】面板中可以设置文本域的字符高度C、在【属性】面板中可以设置文本域所能接受的最多字符数D、在【属性】面板中可以设置文本域的初始值

在Dreamweaver中插入单行文本域时,下面不是文本域形式的是:()A、单行域B、口令域密码C、多行域D、限制行域

业务实体对象中每个字段的编辑器类型包含几类()A、文本域,选择类,其他B、文本域,其他C、文本域,选择类D、文本域,选择类,链接选择器

在制作一个“信息反馈表”网页时,用到“用户名、口令、意见”3个文本域,请问应分别设计何种格式的文本域。

在Dreamweaver表单中,关于文本域说法错误的是()A、密码文本域输入值后显示为“*”B、多行文本域不能进行最大字符数设置C、密码文本和单行文本域一样,都可以进行最大字符数的设置D、多行文本域的行数设定以后,输入内容将不能超过设定的行数

在表单对象中,()在网页中一般不显现。A、隐藏域B、文本域C、文件域D、文本区域

能够设置咸口令域的()A、只有单行文本域B、只有多行文本域C、是单行、多行文本域D、是多行文本标识

在dreammeaver中插入单行文本域时,下面是文本域形式的是:()。A、单行域B、口令域C、限制行域D、多行域

单选题在Dreamweaver表单中,关于文本域说法错误的是()A密码文本域输入值后显示为“*”B多行文本域不能进行最大字符数设置C密码文本和单行文本域一样,都可以进行最大字符数的设置D多行文本域的行数设定以后,输入内容将不能超过设定的行数

单选题业务实体对象中每个字段的编辑器类型包含几类()A文本域,选择类,其他B文本域,其他C文本域,选择类D文本域,选择类,链接选择器

单选题能够设置咸口令域的()A只有单行文本域B只有多行文本域C是单行、多行文本域D是多行文本标识

单选题能够设置成口令域的是文本字段是()。A只有单行文本域B只有多行文本域C单行、多行文本域D多行“Textarea”标识

多选题在dreammeaver中插入单行文本域时,下面是文本域形式的是:()。A单行域B口令域C限制行域D多行域

单选题在DreamweaverCS4表单中,关于文本域说法错误的是()A密码文本域输入值后显示为“*”B多行文本域不能进行最大字符数设置C密码文本和单行文本域一样,都可以进行最大字符数的设置D多行文本域的行数设定以后,输入内容将不能超过设定的行数

单选题在Dreamweaver中插入单行文本域时,下面不是文本域形式的是:()A单行域B口令域密码C多行域D限制行域

单选题关于文本域的说法错误的是()。A在【属性】面板中可以设置文本域的字符宽度B在【属性】面板中可以设置文本域的字符高度C在【属性】面板中可以设置文本域所能接受的最多字符数D在【属性】面板中可以设置文本域的初始值