- 浏览: 735849 次
- 性别:
- 来自: 广州
-
文章分类
最新评论
-
lingsuch:
Android网络连接判断与处理 -
月光照着我:
写的不错,作为笔记了
Android中LayoutInflater的使用 -
智博王锋:
好文章是要顶的!
Android中LayoutInflater的使用 -
云南白药:
...
Android中LayoutInflater的使用 -
万新one:
理解了许多。解释的不错。3Q.
Android中LayoutInflater的使用
import javax.swing.*; import javax.swing.text.*; import java.awt.*; public class StylesExample7 { public static void createDocumentStyles(StyleContext sc) { Style defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE); // Create and add the main document style Style mainStyle = sc.addStyle(mainStyleName, defaultStyle); StyleConstants.setLeftIndent(mainStyle, 16); StyleConstants.setRightIndent(mainStyle, 16); StyleConstants.setFirstLineIndent(mainStyle, 16); StyleConstants.setFontFamily(mainStyle, "serif"); StyleConstants.setFontSize(mainStyle, 12); // Create and add the constant width style Style cwStyle = sc.addStyle(charStyleName, null); StyleConstants.setFontFamily(cwStyle, "monospaced"); StyleConstants.setForeground(cwStyle, Color.green); // Create and add the heading style Style heading2Style = sc.addStyle(heading2StyleName, null); StyleConstants.setForeground(heading2Style, Color.red); StyleConstants.setFontSize(heading2Style, 16); StyleConstants.setFontFamily(heading2Style, "serif"); StyleConstants.setBold(heading2Style, true); StyleConstants.setLeftIndent(heading2Style, 8); StyleConstants.setFirstLineIndent(heading2Style, 0); } public static void addText(JTextPane pane, StyleContext sc, Style logicalStyle, Paragraph[] content) { // The outer loop adds paragraphs, while the // inner loop adds character runs. int paragraphs = content.length; for (int i = 0; i < paragraphs; i++) { Run[] runs = content[i].content; for (int j = 0; j < runs.length; j++) { pane.setCharacterAttributes( runs[j].styleName == null ? SimpleAttributeSet.EMPTY : sc.getStyle(runs[j].styleName), true); pane.replaceSelection(runs[j].content); } // At the end of the paragraph, add the logical style and // any overriding paragraph style and then terminate the // paragraph with a newline. pane.setParagraphAttributes(SimpleAttributeSet.EMPTY, true); if (logicalStyle != null) { pane.setLogicalStyle(logicalStyle); } if (content[i].styleName != null) { pane.setParagraphAttributes(sc.getStyle(content[i].styleName), false); } pane.replaceSelection("\n"); } } public static void main(String[] args) { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) {} JFrame f = new JFrame("Styles Example 7"); // Create the StyleContext, the document and the pane final StyleContext sc = new StyleContext(); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); final JTextPane pane = new JTextPane(doc); // Build the styles createDocumentStyles(sc); try { // Add the text and apply the styles SwingUtilities.invokeAndWait(new Runnable() { public void run() { // Add the text addText(pane, sc, sc.getStyle(mainStyleName), content); } }); } catch (Exception e) { System.out.println("Exception when constructing document: " + e); System.exit(1); } f.getContentPane().add(new JScrollPane(pane)); f.setSize(400, 300); f.setVisible(true); } // Style names public static final String mainStyleName = "MainStyle"; public static final String heading2StyleName = "Heading2"; public static final String charStyleName = "ConstantWidth"; // Inner classes used to define paragraph structure public static class Run { public Run(String styleName, String content) { this.styleName = styleName; this.content = content; } public String styleName; public String content; } public static class Paragraph { public Paragraph(String styleName, Run[] content) { this.styleName = styleName; this.content = content; } public String styleName; public Run[] content; } public static final Paragraph[] content = new Paragraph[] { new Paragraph(heading2StyleName, new Run[] { new Run(null, "Attributes, Styles and Style Contexts") }), new Paragraph(null, new Run[] { new Run(null, "The simple "), new Run(charStyleName, "PlainDocument"), new Run(null, " class that you saw in the previous " + "chapter is only capable of holding text. " + "The more complex text components use a more " + "sophisticated model that implements the "), new Run(charStyleName, "StyledDocument"), new Run(null, " interface. "), new Run(charStyleName, "StyledDocument"), new Run(null, " is a sub-interface of "), new Run(charStyleName, "Document"), new Run(null, " that contains methods for manipulating attributes " + "that control the way in which the text in the " + "document is displayed. The Swing text package " + "contains a concrete implementation of "), new Run(charStyleName, "StyledDocument"), new Run(null, " called "), new Run(charStyleName, "DefaultStyledDocument"), new Run(null, " that is used as the default model for "), new Run(charStyleName, "JTextPane"), new Run(null, " and is also the base class from which " + "more specific models, such as the "), new Run(charStyleName, "HTMLDocument"), new Run(null, " class that handles input in HTML format, can be " + "created. In order to make use of "), new Run(charStyleName, "DefaultStyledDocument"), new Run(null, " and "), new Run(charStyleName, "JTextPane"), new Run(null, " you need to understand how Swing represents " + "and uses attributes.") }) }; }
发表评论
-
Swing中引入Android的NinePatch技术,让Swing拥有Android的外观定制能力
2012-09-21 09:22 1641【摘要】 本文诣在 ... -
JavaSwing实现支持合并拆分的JTable
2010-12-16 15:39 1993GridBagModel:抽象模型接口。该接口用于描述表格中单 ... -
JTable小例子,表格中使用JComboBox下拉按钮
2010-12-16 15:21 5439import java.awt.BorderLayout; ... -
配合滚动面板实现JTable上下翻页的效果
2010-12-16 14:26 3442import java.awt.BorderLayout; ... -
JScrollBar简单演示例子
2010-12-06 19:28 6639import java.awt.*; import java ... -
点击jtable的表头,数据会根据根据表头来排序
2010-12-06 11:47 5158import javax.swing.JFrame; imp ... -
重写JSplitPane的BasicSplitPaneUI
2010-09-18 13:39 1598import java.awt.Color; import ... -
Swing窗口初始最大化的方法
2010-08-20 11:09 79561.设置窗口最大(伪最大化) JFrame frame =n ... -
Tree目录实现拖拽功能演示实例(DragAndDrop)
2010-08-10 16:49 1815import java.awt.BorderLayout; ... -
设置JTextPane指定内容的颜色
2010-05-21 14:29 1393package Assis; import java.a ... -
ScaleImageDemo图像缩小与放大演示
2010-05-12 14:59 2141package Assis; import java.a ... -
TreesDemo
2010-05-04 11:19 1118import java.awt.*; import java ... -
TableDemo
2010-05-04 11:17 1215import javax.swing.JTable; imp ... -
分割面板演示JSplitPaneDemo
2010-05-04 11:12 1419//Java Swing 带分隔条的面板代码 impor ... -
StylesExample8
2010-04-08 12:55 1237import javax.swing.*; import j ... -
StylesExample6
2010-04-08 12:52 1084import javax.swing.*; import j ... -
StylesExample5
2010-04-08 12:51 1013import javax.swing.*; import j ... -
StylesExample4
2010-04-08 12:50 1145import javax.swing.*; import j ... -
StylesExample3
2010-04-08 12:50 1029import javax.swing.*; import j ... -
StylesExample2
2010-04-08 12:49 1076import javax.swing.*; import j ...
相关推荐
python学习资源
jfinal-undertow 用于开发、部署由 jfinal 开发的 web 项目
基于Andorid的音乐播放器项目设计(国外开源)实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。
python学习资源
python学习资源
python学习一些项目和资源
【毕业设计】java-springboot+vue家具销售平台实现源码(完整前后端+mysql+说明文档+LunW).zip
HTML+CSS+JavaScarip开发的前端网页源代码
python学习资源
【毕业设计】java-springboot-vue健身房信息管理系统源码(完整前后端+mysql+说明文档+LunW).zip
成绩管理系统C/Go。大学生期末小作业,指针实现,C语言版本(ANSI C)和Go语言版本
1_基于大数据的智能菜品个性化推荐与点餐系统的设计与实现.docx
【毕业设计】java-springboot-vue交流互动平台实现源码(完整前后端+mysql+说明文档+LunW).zip
内容概要:本文主要探讨了在高并发情况下如何设计并优化火车票秒杀系统,确保系统的高性能与稳定性。通过对比分析三种库存管理模式(下单减库存、支付减库存、预扣库存),强调了预扣库存结合本地缓存及远程Redis统一库存的优势,同时介绍了如何利用Nginx的加权轮询策略、MQ消息队列异步处理等方式降低系统压力,保障交易完整性和数据一致性,防止超卖现象。 适用人群:具有一定互联网应用开发经验的研发人员和技术管理人员。 使用场景及目标:适用于电商、票务等行业需要处理大量瞬时并发请求的业务场景。其目标在于通过合理的架构规划,实现在高峰期保持平台的稳定运行,保证用户体验的同时最大化销售额。 其他说明:文中提及的技术细节如Epoll I/O多路复用模型以及分布式系统中的容错措施等内容,对于深入理解大规模并发系统的构建有着重要指导意义。
基于 OpenCV 和 PyTorch 的深度车牌识别
【毕业设计-java】springboot-vue教学资料管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
此数据集包含有关出租车行程的详细信息,包括乘客人数、行程距离、付款类型、车费金额和行程时长。它可用于各种数据分析和机器学习应用程序,例如票价预测和乘车模式分析。
把代码放到Word中,通过开发工具——Visual Basic——插入模块,粘贴在里在,把在硅基流动中申请的API放到VBA代码中。在Word中,选择一个问题,运行这个DeepSeekV3的宏就可以实现在线问答
【毕业设计】java-springboot+vue机动车号牌管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
【毕业设计】java-springboot-vue交通管理在线服务系统的开发源码(完整前后端+mysql+说明文档+LunW).zip