想到了解一下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>

参考

  1. java中TextArea和JTextArea的自动换行和滚动条

  2. [Maven]Maven构建可执行的jar包(包含依赖jar包)

  3. swing教程

  4. Java Swing 介绍

  5. 容器(JFrame); 其他

最新文章

  1. 转载--redis密码管理
  2. IIS 8 下使用 WCF
  3. PeopleTools预警程序制作
  4. MJExtension框架介绍
  5. 铭飞MCMS内容管理系统完整开源版J2EE代码
  6. JSTL,自定义一个标签的功能案例
  7. Java--&gt;IO流模拟实现用户登录以及登录信息
  8. hdu 4193 Non-negative Partial Sums
  9. akka创建actor时报错:IllegalArgumentException: no matching constructor found on class $iwC$$iwC$$iwC$$iwC$
  10. ios--UIButton简单使用
  11. twsited(4)--不同模块用redis共享以及用web发送数据到tcpserver
  12. (转)在Android的webview中定制js的alert,confirm和prompt对话框的方法
  13. 我的MYSQL学习心得(二)
  14. Visual Studio 2013 的 Browser Link 功能
  15. C++虚函数继承的bug
  16. SQLAlchemy入门
  17. NYOJ 925 国王的烦恼
  18. Python3基础 nonlocal关键字 内部函数访问到外部函数的变量
  19. VS2015安装时问题汇总
  20. spring入门 依赖入注的三种方式(1)

热门文章

  1. LibreOJ 6004 圆桌聚餐 (最大流)
  2. C#字符串string的常用使用方法(转载)
  3. Redis 占用Windows系统盘空间23G
  4. IdentityServer4实现单点登录统一认证
  5. 十五、Node.js-fs模块(中)
  6. vs2015+opencv3.3.1+ c++实现 静态背景下多运动目标提取,检测
  7. linux系统使用sh文件传参数给matlab程序
  8. MVC进阶篇(四)——[HttpGet]和[HttpPost]
  9. CKEditor编辑器的使用方法
  10. WebApplicationContext wac=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());这句话的意思