java在线聊天项目 swt可视化窗口Design 重新设计聊天窗口
Posted Advancing Swift
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java在线聊天项目 swt可视化窗口Design 重新设计聊天窗口相关的知识,希望对你有一定的参考价值。
设计的聊天窗口如下:
制作过程:
首先,在默认的BorderLayout视图下,
上边也就是North处添加一个JPanel,将Layout调整为BorderLayout,West放一个JLabel用来放照片,
Center再放一个JPanel,布局调整为BorderLayout,Center和South各方一个JLabel,分别放用户昵称和名言。
下边模仿QQ是一个上下可以自行拆分大小的JSplitPane,调整为垂直的上下模式。
拆分框的下边放一个JPanel,设布局为BorderLayout,
再在上中下分别放JPanel,JScrollPane,JPanel,
上边放一个按钮调整为左对齐,下边放两个按钮调整为右对齐,中间放一个JTextArea
最后,拆分框上边放一个JScrollPane,里边放一个JTextArea。
全部完整代码如下:
package com.swift; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTextArea; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class ChatFrame extends JFrame { private JTextArea textArea_1; private JTextArea textArea; public static void main(String args[]) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (UnsupportedLookAndFeelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } EventQueue.invokeLater(new Runnable() { public void run() { try { ChatFrame frame = new ChatFrame(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public ChatFrame() { super(); setTitle("飞燕—聊天窗"); setBounds(100, 100, 558, 576); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(5,5)); getContentPane().add(panel, BorderLayout.NORTH); final JLabel label = new JLabel(new ImageIcon("Images/logo.jpg")); panel.add(label, BorderLayout.WEST); label.setText("New JLabel"); label.setPreferredSize(new Dimension(74,74)); final JPanel panel_1 = new JPanel(); panel_1.setLayout(new BorderLayout()); panel.add(panel_1, BorderLayout.CENTER); final JLabel advancingSwiftLabel = new JLabel(); advancingSwiftLabel.setText("Advancing Swift"); panel_1.add(advancingSwiftLabel, BorderLayout.CENTER); final JLabel neverWasteTimeLabel = new JLabel(); neverWasteTimeLabel.setText("Never waste time any more"); panel_1.add(neverWasteTimeLabel, BorderLayout.SOUTH); final JSplitPane splitPane = new JSplitPane(); splitPane.setDividerLocation(300); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); getContentPane().add(splitPane, BorderLayout.CENTER); final JPanel panel_2 = new JPanel(); panel_2.setLayout(new BorderLayout()); splitPane.setRightComponent(panel_2); final JPanel panel_3 = new JPanel(); final FlowLayout flowLayout = new FlowLayout(); flowLayout.setAlignment(FlowLayout.LEFT); panel_3.setLayout(flowLayout); panel_2.add(panel_3, BorderLayout.NORTH); final JButton button = new JButton(); button.setText("字体"); panel_3.add(button); final JPanel panel_4 = new JPanel(); final FlowLayout flowLayout_1 = new FlowLayout(); flowLayout_1.setAlignment(FlowLayout.RIGHT); panel_4.setLayout(flowLayout_1); panel_2.add(panel_4, BorderLayout.SOUTH); final JButton button_1 = new JButton(); button_1.setText("关闭"); panel_4.add(button_1); final JButton button_2 = new JButton(); button_2.setText("发送"); panel_4.add(button_2); final JScrollPane scrollPane = new JScrollPane(); panel_2.add(scrollPane, BorderLayout.CENTER); textArea_1 = new JTextArea(); scrollPane.setViewportView(textArea_1); final JScrollPane scrollPane_1 = new JScrollPane(); splitPane.setLeftComponent(scrollPane_1); textArea = new JTextArea(); scrollPane_1.setViewportView(textArea); } }
以上是关于java在线聊天项目 swt可视化窗口Design 重新设计聊天窗口的主要内容,如果未能解决你的问题,请参考以下文章
java在线聊天项目 swt可视化窗口Design 登录框注册按钮点击改变窗口大小——出现注册面板 实现打开登录框时屏幕居中
java在线聊天项目 使用SWT快速制作登录窗口,可视化窗口Design 更换窗口默认皮肤(切换Swing自带的几种皮肤如矩形带圆角)
eclipse里打开SWT项目找不到source/design的图形UI设计界面
java在线聊天项目 实现基本聊天功能后补充的其他功能详细需求分析 及所需要掌握的Java知识基础