Java Swing笔记
2024-10-20 04:09:49
想到了解一下GUI主要是想用来做点小工具,记录一些笔记。
文本框自动换行和滚动条
private static JTextArea addJTextArea(JPanel panel, int x, int y, int width, int height, String text) {
JTextArea jsText = new JTextArea(text);
jsText.setLineWrap(true);
jsText.setWrapStyleWord(true);
JScrollPane jsScrollPane = new JScrollPane(jsText);
jsScrollPane.setBounds(x, y, width, height);
//分别设置水平和垂直滚动条自动出现
jsScrollPane.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jsScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
panel.add(jsScrollPane);
return jsText;
}
用yuicompressor做个js压缩工具
pom
<dependency>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>2.4.8</version>
</dependency>
执行压缩并显示在文本框:
compressJsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
ByteArrayInputStream stream = new ByteArrayInputStream(jsText.getText().getBytes());
JavaScriptCompressor jscompressor = new JavaScriptCompressor(new BufferedReader(new InputStreamReader(stream)), new ErrorReporter() {
@Override
public void warning(String s, String s1, int i, String s2, int i1) {
jsResultText.setText(String.format("warning: %s,%s,%s,%s,%s", s, s1, i, s2, i1));
}
@Override
public void error(String s, String s1, int i, String s2, int i1) {
jsResultText.setText(String.format("error: %s,%s,%s,%s,%s", s, s1, i, s2, i1));
}
@Override
public EvaluatorException runtimeError(String s, String s1, int i, String s2, int i1) {
jsResultText.setText(String.format("runtimeError: %s,%s,%s,%s,%s", s, s1, i, s2, i1));
return null;
}
});
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
int linebreakpos = -1;
boolean munge = true;
boolean verbose = false;
boolean preserveAllSemiColons = false;
boolean disableOptimizations = false;
jscompressor.compress(bufferedWriter, linebreakpos, munge, verbose, preserveAllSemiColons, disableOptimizations);
bufferedWriter.flush();
jsResultText.setText(new String(outputStream.toByteArray()));
} catch (IOException e1) {
jsResultText.setText(e1.toString());
}
}
});
打包jar
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!-- 此处指定main方法入口的class -->
<mainClass>com.xxx.xxx</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
参考
最新文章
- 转载--redis密码管理
- IIS 8 下使用 WCF
- PeopleTools预警程序制作
- MJExtension框架介绍
- 铭飞MCMS内容管理系统完整开源版J2EE代码
- JSTL,自定义一个标签的功能案例
- Java-->;IO流模拟实现用户登录以及登录信息
- hdu 4193 Non-negative Partial Sums
- akka创建actor时报错:IllegalArgumentException: no matching constructor found on class $iwC$$iwC$$iwC$$iwC$
- ios--UIButton简单使用
- twsited(4)--不同模块用redis共享以及用web发送数据到tcpserver
- (转)在Android的webview中定制js的alert,confirm和prompt对话框的方法
- 我的MYSQL学习心得(二)
- Visual Studio 2013 的 Browser Link 功能
- C++虚函数继承的bug
- SQLAlchemy入门
- NYOJ 925 国王的烦恼
- Python3基础 nonlocal关键字 内部函数访问到外部函数的变量
- VS2015安装时问题汇总
- spring入门 依赖入注的三种方式(1)
热门文章
- LibreOJ 6004 圆桌聚餐 (最大流)
- C#字符串string的常用使用方法(转载)
- Redis 占用Windows系统盘空间23G
- IdentityServer4实现单点登录统一认证
- 十五、Node.js-fs模块(中)
- vs2015+opencv3.3.1+ c++实现 静态背景下多运动目标提取,检测
- linux系统使用sh文件传参数给matlab程序
- MVC进阶篇(四)——[HttpGet]和[HttpPost]
- CKEditor编辑器的使用方法
- WebApplicationContext wac=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());这句话的意思