标题:怎么使textArea怎么实现combobox里面的Item事件
取消只看楼主
zy5303335
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2010-8-30
结帖率:83.33%
已结贴  问题点数:0 回复次数:0 
怎么使textArea怎么实现combobox里面的Item事件
还有别的JRadioButton啊什么的,怎么写事件才能让多行文本框实现这些事件

这是代码 监听事件写不来

package com.great.nf1108.demo;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class LayoutExciseFrame extends JFrame {

    JLabel labFace = new JLabel("字体");
    JLabel labSize = new JLabel("大小");
    JComboBox comboBoxFace = new JComboBox();
    JComboBox comboBoxSize = new JComboBox();
    JRadioButton checkBoxBold = new JRadioButton("粗体");
    JRadioButton checkBoxItalic = new JRadioButton("斜体");
    JTextArea txtArea = new JTextArea("这里是设置字体的预览区,示例文字");
    ButtonGroup spRadioButton = new ButtonGroup();

    public LayoutExciseFrame() {

        setTitle("设置字体");
        setSize(500, 400);

        initComponent();

        initLayout();

        setMenu();
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    /**
     * 初始化布局
     */
    private void initLayout() {
        JPanel panelLeft = new JPanel();// 左侧布局面板
        JPanel panelTop = new JPanel();// 顶部布局面板
        JPanel panelBottom = new JPanel();// 底部布局面板
        JPanel panelFace = new JPanel();// 放置字体设置相关控件的 面板
        JPanel panelSize = new JPanel();// 放置大小设置相关控件的 面板

        panelFace.setLayout(new FlowLayout(FlowLayout.LEFT));
        panelFace.add(labFace);

        spRadioButton.add(checkBoxBold);
        spRadioButton.add(checkBoxItalic);
        panelFace.add(comboBoxFace);

        panelSize.setLayout(new FlowLayout(FlowLayout.LEFT));
        panelSize.add(labSize);
        panelSize.add(comboBoxSize);

        panelTop.setLayout(new GridLayout(2, 1));
        panelTop.add(panelFace);
        panelTop.add(panelSize);

        panelBottom.setLayout(new GridLayout(6, 1));
        panelBottom.add(new JPanel());
        panelBottom.add(new JPanel());
        JPanel panelBold = new JPanel();
        panelBold.add(checkBoxBold);
        JPanel panelItatic = new JPanel();
        panelItatic.add(checkBoxItalic);
        panelBottom.add(panelBold);
        panelBottom.add(panelItatic);
        panelBottom.add(new JPanel());
        panelBottom.add(new JPanel());

        panelLeft.setLayout(new BorderLayout());
        panelLeft.add(panelTop, BorderLayout.NORTH);
        panelLeft.add(panelBottom);

        add(panelLeft, BorderLayout.WEST);
        add(txtArea);
    }

    /**
     * 初始化组件
     */
    public void initComponent() {

        comboBoxFace.addItem("宋体");
        comboBoxFace.addItem("楷体-GB2312");
        comboBoxSize.addItem(12);
        comboBoxSize.addItem(14);
        comboBoxSize.addItem(24);
    }

    /**
     * 设置菜单
     */
    private void setMenu() {
        MenuBar menuBar = new MenuBar();

        Menu menuColor = new Menu("字体颜色");

        MenuItem menuItemRed = new MenuItem("红色");
        MenuItem menuItemBlue = new MenuItem("蓝色");
        MenuItem menuItemGreen = new MenuItem("绿色");

        // 把菜单项放入菜单
        menuColor.add(menuItemRed);
        menuColor.add(menuItemGreen);
        menuColor.add(menuItemBlue);

        // 将菜单加入到菜单条中
        menuBar.add(menuColor);

        setMenuBar(menuBar);// 设置菜单条到当前窗口中

    }

}
搜索更多相关主题的帖子: check 
2011-09-19 00:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-350268-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.173766 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved