- 浏览: 620243 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (314)
- 生活 (2)
- c# (37)
- 技术 (3)
- 400电话 (0)
- 400常见问题 (0)
- 400资费 (0)
- html (7)
- css (0)
- 数据库 (7)
- javascript (16)
- php (33)
- asp.net mvc2 (10)
- mysql (9)
- C# 3.0 LinQ (10)
- vs2005或vs2008 (4)
- flash and as3 (7)
- fms (1)
- dedeCMS (11)
- java (33)
- j2me (1)
- swing (1)
- c++ (1)
- jquery easyui (3)
- jquery (5)
- android (29)
- MongoDB (9)
- VtigerCRM (1)
- test (0)
- linux (30)
- nutch (2)
- SqlServer数据库 (2)
- 数据检索 (2)
- java抓取 (11)
- 乐天 (1)
- 淘宝 (1)
- Silverlight4.0 (6)
- sphinx实时索引 (5)
- ecshop (9)
- codeigniter(CI) (3)
- axure6 (1)
- 京东店铺装修教程 (2)
- xpath (1)
- joomla (2)
- bpm (1)
- Bootstrap (2)
- knockout (4)
- ecstore (4)
- css3 (1)
- 微信 (2)
- dede (0)
- soa_edi (1)
- odoo (0)
- web (1)
最新评论
-
骑着蜗牛超F1:
在ie6下报了个stack overflow at line ...
兼容ie6和ie7 的16进制码流在html中显示为图片代码(base64) -
冰之海洋:
好像少了一句代码吧? FloatingFunc.show(th ...
android 一直在最前面的浮动窗口效果 -
yanzhoupuzhang:
连接有问题!
iis7.0官方下载 IIS 7.0(微软Web服务器组件IIS 7.0) 官方(windows 2003,XP,2000) -
whatable:
唉,楼主你都没有搞清楚重量级和轻量级。。。。既然引用了SWT, ...
java swing 内置浏览器打开网页显示flash图表-swt Browser应用 -
yy_owen:
我晕啊,你链接的什么内容额,我要的iis,你链接个视频什么意思 ...
iis7.0官方下载 IIS 7.0(微软Web服务器组件IIS 7.0) 官方(windows 2003,XP,2000)
用java swing 中的jTextPane实现局部文本改色添加删除线等操作,以下是执行图片:
实现代码如下:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJFrame.java
*
* Created on 2011-2-21, 9:04:46
*/
package desktopapplicationmenu;
import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
/**
*
* @author
*/
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
jTextPane1.setText("http://www.my400800.cn
");
// jEditorPane1.("<html> <head> <style type=´text/css´> A{text-decoration: none; color: #000000; } A:hover {text-decoration: underline; color: #FF0000; } </style> </head> <body> <a href=\"www.google.com\">Google</a><br> <a href=\"www.yahoo.com\">Yahoo!</a> </body> </html> ");
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setName("Form"); // NOI18N
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopapplicationmenu.DesktopApplicationMenu.class).getContext().getResourceMap(NewJFrame.class);
jButton1.setLabel(resourceMap.getString("jButton1.label")); // NOI18N
jButton1.setName("jButton1"); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
jButton2.setName("jButton2"); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jScrollPane2.setName("jScrollPane2"); // NOI18N
jTextPane1.setText(resourceMap.getString("jTextPane1.text")); // NOI18N
jTextPane1.setName("jTextPane1"); // NOI18N
jScrollPane2.setViewportView(jTextPane1);
jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
jButton3.setName("jButton3"); // NOI18N
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(247, 247, 247)
.addComponent(jButton2)
.addGap(33, 33, 33)
.addComponent(jButton1)
.addGap(55, 55, 55)
.addComponent(jButton3))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 838, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(39, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 512, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton3)
.addComponent(jButton2))
.addGap(37, 37, 37))
);
jButton3.getAccessibleContext().setAccessibleName(resourceMap.getString("jButton3.AccessibleContext.accessibleName")); // NOI18N
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Document doc = jTextPane1.getStyledDocument();
int istartPosition = 1;
int iType = 1;
int iPK = 1;
SetAddText(istartPosition, iType, iPK, jTextPane1, doc);
// String str = "";
// Document doc = jTextPane1.getStyledDocument();
//
// str = jTextPane1.getText();
//
//
// int iStart = str.indexOf("7891");
// int iEnd = str.indexOf("1011");
// try {
// String strReplace = str.substring(iStart, iEnd);
// System.out.println(strReplace);
//
// doc.remove(iStart, strReplace.replace("\n", "").length());
//
// doc.insertString(iStart, strReplace, getAddAttrSet());
// } catch (BadLocationException ex) {
// Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
// }
//
// jTextPane1.setSelectionStart(iStart);
// jTextPane1.setSelectionEnd(iEnd);
// jTextPane1.setSelectionEnd(iStart);
// //DefaultStyledDocument.ElementEdit;
// jTextPane1.setSelectedTextColor(Color.red);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String str = "";
for (int i = 0; i < 10; i++) {
str += "" + i + (i + 1) + (i + 2) + (i + 3) + (i + 4) + "\r\n";
}
Document doc = jTextPane1.getStyledDocument();
jTextPane1.setText(str);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Document doc = jTextPane1.getStyledDocument();
int istartPosition = 1;
int iType = 1;
int iPK = 1;
SetDelText(istartPosition, iType, iPK, jTextPane1, doc);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextPane jTextPane1;
// End of variables declaration
/**
* 返回 新添加属性样式
*
* @return
*/
public SimpleAttributeSet getAddAttrSet() {
SimpleAttributeSet attrSet = new SimpleAttributeSet();
StyleConstants.setItalic(attrSet, false);
StyleConstants.setUnderline(attrSet, false);
StyleConstants.setFontSize(attrSet, 16);
StyleConstants.setForeground(attrSet, Color.red);
return attrSet;
}
/**
* 返回 删除加属性样式
*
* @return
*/
public SimpleAttributeSet getDelAttrSet() {
SimpleAttributeSet attrSet = new SimpleAttributeSet();
StyleConstants.setItalic(attrSet, true);
StyleConstants.setUnderline(attrSet, true);
StyleConstants.setFontSize(attrSet, 16);
StyleConstants.setForeground(attrSet, Color.BLUE);
StyleConstants.setStrikeThrough(attrSet, true);
return attrSet;
}
/**
* 设定添加文本颜色
* @param istartPosition 字符开始检索位置
* @param iType 类型:属性、段位、状态
* @param iPK 设定属性PK
*/
public void SetAddText(int istartPosition, int iType, int iPK, javax.swing.JTextPane jTextPaneObj, Document doc) {
String strReplaceForm = "";
istartPosition = 10;
String strReplaceTo = "http://www.my400800.cn";
SimpleAttributeSet attrSet = getAddAttrSet();
SetText(istartPosition, jTextPaneObj, doc, strReplaceForm, strReplaceTo, attrSet);
}
/**
* 设定添加文本颜色
* @param istartPosition 字符开始检索位置
* @param iType 类型:属性、段位、状态
* @param iPK 设定属性PK
*/
public void SetDelText(int istartPosition, int iType, int iPK, javax.swing.JTextPane jTextPaneObj, Document doc) {
String strReplaceForm = "http://www.my400800.cn";
String strReplaceTo = "http://www.my400800.cn";
//istartPosition = 10;
SimpleAttributeSet attrSet = getDelAttrSet();
SetText(istartPosition, jTextPaneObj, doc, strReplaceForm, strReplaceTo, attrSet);
}
/**
* 设定实际控件上的显示状态
* @param istartPosition 文本检索开始位置
* @param jTextPaneObj 文本存放控件
* @param doc 属性设定样式雷
* @param strReplaceForm 替换前内容(如果该值为空,重该位置直接插入)
* @param strReplaceTo 替换后内容
* @param attrSet
*/
public void SetText(int istartPosition, javax.swing.JTextPane jTextPaneObj, Document doc, String strReplaceForm, String strReplaceTo, SimpleAttributeSet attrSet) {
try {
String str = jTextPaneObj.getText();
int iStart = istartPosition;
if (strReplaceForm != null && strReplaceForm.length() > 0) {
istartPosition = str.replace("\n", "").indexOf(strReplaceForm, istartPosition);
iStart = istartPosition;
int iEnd = iStart + strReplaceTo.length();
String strReplace = str.substring(iStart, iEnd);
System.out.println(strReplace);
doc.remove(iStart, strReplace.replace("\n", "").length());
}
doc.insertString(iStart, strReplaceTo, attrSet);
jTextPane1.setSelectionStart(iStart);
jTextPane1.setSelectionEnd(iStart + 1);
} catch (BadLocationException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
发表评论
-
Java 线程中的Join、wait、notify,sleep
2016-06-22 17:28 4191.wait和notify这两个方法都是Object中的方法 ... -
Java多线程sleep(),join(),interrupt(),wait(),notify()
2016-06-22 17:25 480浅析 Java Thread.join() ... -
Java和C#运行命令行并获取返回值 运行bat文件
2015-08-04 10:45 1273Java运行命令行的例子 import java.io.B ... -
HttpClient的超时用法小记
2012-05-06 08:23 905HttpClient在使用中有两个超时时间,是一直接触 ... -
JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecutor)使用简介
2012-05-05 21:29 746在多线程大师Doug Lea的 ... -
XPath 语法 org.dom4j.Document
2012-02-07 13:12 1245XPath 使用路径表达式 ... -
Nutch命令大全
2011-12-28 15:12 1387Nutch采用了一种命令的方式进行工作,其命令可以是对局域网方 ... -
Nutch1.2搜索引擎使用详解
2011-12-27 17:12 1623Nutch作为一款刚刚诞生 ... -
ECLIPSE java.lang.OutOfMemoryError: PermGen space 错误
2011-12-21 15:03 1075ECLIPSE 最近一段时间经常报错,看了日志,有如下错误信息 ... -
nutch环境配置在windows系统上(借助Cygwin)
2011-11-16 11:09 1742nutch环境配置在windows系统上必须要安装【Cygwi ... -
Heritrix 和 Nutch 比较与分析(java开源网络爬虫)
2011-11-15 11:01 7399Heritrix项目介绍 Heritrix工程 ... -
heritrix 下载、安装、配置、以及简单开发
2011-11-04 11:36 1349一、下载: 到www.sourcef ... -
java 如何判断Socket已断开
2011-09-14 13:34 1686最近在开发中遇到一个问题,就是如何判断远端服务器是否已经断开连 ... -
java 程序内存溢出问题查找
2011-04-10 18:00 945这段是时间用java swing做了一个小程序,但是运行一点时 ... -
jtable 隐藏表头标题行
2011-04-08 10:59 3243今天需要把JTable的表头也就是标题行给隐藏掉,在晚上找了一 ... -
java FrameView 启动最大化
2011-03-30 08:49 1494FrameViewzView = new ... -
Swing窗口Linux下不支持最大化问题
2011-03-28 10:15 972由于最近一直在Linux下工作,今天遇到了Swing窗口不能最 ... -
java 抓取网页内容,可设定代理(HttpURLConnection)
2011-03-11 09:41 1435/* * To change this template, ... -
swing下 改变窗口样式为windows风格(swing控件样式不美观解决方案)
2011-03-02 15:52 2599在windows环境下可以用下面两种方法使窗口显示window ... -
swt Browser 如何打开新url链接地址
2011-02-28 17:27 1681上一篇文章【java swing 内置浏览器打开网页显示fla ...
相关推荐
使用java,swing 实现gps, 源码提供,简要如下: package gps; import java.awt.event.ActionListener; import javax.swing.*; import java.awt.event.*; import java.io.*; public class GpsFrame extends JFrame ...
JAVA-----JTextPane实例 代码
SWT JTextPane 可以把控件中需要的字符串的颜色修改成自己想要的颜色
java文本设计 实用代码import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing....
这个示例并不是Swing的完整演示,演示了一些常规组件的使用方法,也演示了一些组件的巧妙运用(YY一下,哈哈),如JTextArea的取消重做,用JLayeredPane实现动态的悬浮框,JTextPane演示等等。 我上传的是NetBean的...
JTextPane使用,可以传图片,文字等
我使用了Java Swing库来创建用户界面,并使用Java I/O库来处理文件操作。我还使用了一些其他的Java类和方法,例如JFileChooser、JTextPane、JMenuBar等等。 我希望这个简单的记事本可以帮助其他学习Java编程的人,...
java写的文本组件,带行号,做的比较简单
第1章 Java概述 1 1.1 Java语言的发展简史 2 1.2 Java的竞争对手及各自优势 4 1.2.1 C#简介和优势 4 1.2.2 Ruby简介和优势 4 1.2.3 Python的简介和优势 5 1.3 Java程序运行机制 5 1.3.1 高级语言的运行机制 6...
java写的文本组件,带行号,做的比较简单,还有些小问题
Swing组件(javax.swing.-) 面板:JPanel 标签化窗格:JTabbedPane 拆分窗格:JSplitPane 滚动窗格:JScrollPane 工具栏:JToolBar 桌面窗格:JDesktopPane 内部框架:JInternalFrame 分层窗格:JLayeredPane ...
NULL 博文链接:https://icarusliu.iteye.com/blog/1412007
本书是第II卷,以开发人员在项目开发中经常遇到的问题和必须掌握的技术为中心,介绍了应用Java进行桌面程序开发各个方面的知识和技巧,主要包括Java语法与面向对象技术、Java高级应用、窗体与控件应用、文件操作典型...
本源码实现了 文本区里加图片和插入艺术字的功能 窗口使用Windows窗体风格
演示、说明程序 博文链接:https://bps.iteye.com/blog/136627