Change the text style of a textarea with StyledEditorKit

0

I have a JMenuBar with a menu that has a button that should change the selected text to negritam but it does not work ... I do not know how to make the JTextArea know that I want to change the style of the source

this is the code

class Window extends JFrame{
    JTextArea textarea;
    JMenuItem bold;

    Window(){
        setTitle("Procesador de Texto");
        setSize(600, 400);
        setJMenuBar( new Navbar() );
        setTextArea();
    }

    public void setTextArea(){
        JPanel panel = new JPanel( new BorderLayout() );
        textarea = new JTextArea();

        panel.add(textarea, BorderLayout.CENTER);
        add(panel);
    }

    private class Navbar extends JMenuBar{
        Navbar(){
            JMenu menuStyle = new JMenu("Estilo");

            bold = new JMenuItem("Negrita");

            menuStyle.add(bold);

            bold.addActionListener( new StyledEditorKit.BoldAction() );

            add(menuStyle);
        }
    }
}
    
asked by Franklin'j Gil'z 24.10.2017 в 00:05
source

0 answers