Results 1 to 3 of 3
  1. #1
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default JTextPane problem

    Hi.........

    I have a problem about setText() of JTextPane class.

    I have a two class - FrameOutput.java and FrameInput.java.

    In FrameInput.java I have globally declared and initialize the JTextPane like below ------



    jpmsgTxtPane=new JTextPane();
    jpmsgTxtPane.setForeground(Color.darkGray);
    Font fn=new Font("Arial",Font.BOLD,12);
    jpmsgTxtPane.setFont(fn);
    jpmsgTxtPane.setText("At first you select draw mode then draw item.\n Observe the canvas....");
    jpmsgTxtPane.setEditable(false);

    jpmsg=new JPanel(new GridLayout(1,1));
    jpmsg.setBorder(BorderFactory.createTitledBorder(" Instruction:"));
    jpmsg.add(jpmsgTxtPane);
    add(jpmsg,BorderLayout.CENTER);

    its working fine, and it shows the message in the user interface "At first you select draw mode then draw item.\n Observe the canvas....".

    An now when I try to set new string for JTextPane using setText() within stateChange method it won't run due to error.

    So please help me, how can I set new text for JTextPane from FrameOutput.java.

    I have attached three java files, the two are mentioned above and another is Main_Input_Output.java and this is the main class.

    Thank u guys........._
    Attached Files Attached Files

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,987
    Rep Power
    9

    Default

    If you want help, provide an SSCCE that demonstrates the behavior, and paste the full error message here.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    If you want help, provide an SSCCE that demonstrates the behavior, and paste the full error message here.

    Quote Originally Posted by KevinWorkman View Post
    If you want help, provide an SSCCE that demonstrates the behavior, and paste the full error message here.

    Thank for ur reply and sorry for my improper description.

    So let u explain in details.


    So first I have three .java file ----- MainClass, OutputClass and InputClass.
    MainClass.java is just called OutputClass.java and OutputClass.java called InputClass.java.

    InputClass.java is just for input componennts, such as JTextPane, JCheckBox and so on. And OutputClass is just for showing the output.
    In InputClass flie I have added one JTabbedPane with three JPanel - DRAW, DRAG and MEASURE.
    Within DRAW pane I have added two JCheckBox and added them to addItemListener.

    And Finally I have added a JTextPane.

    In the OutputClass I have implemented ItemListener and ChangeListener and their corresponding abstract methods.
    itemStateChanged(ItemEvent e) method workd fine but the changeEvent(ChangeEvent) method not working, because of I can't add addChangeListener() to the JTextPane in the input class.

    So how can I get the name of the panes in the JTabbedPane of the InputClass.java file?
    Or what Listener should I use for JTabbedPane?

    Hope this will help u.
    Thank u.






    //MainClass.java


    import javax.swing.JApplet;
    import javax.swing.JFrame;

    public class MainClass extends JApplet {

    OutputClass oc;

    @Override
    public void init(){
    oc = new OutputClass();
    oc.setVisible(true);
    oc.setSize(600,600);
    oc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    }



    //OututClass.java

    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JTabbedPane;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;

    public class OutputClass extends JFrame implements ItemListener,ChangeListener {
    InputClass ic;

    public OutputClass(){
    ic = new InputClass(this);
    ic.setVisible(true);
    ic.setSize(300,300);
    }

    public void itemStateChanged(ItemEvent e) {
    if(ic.cBox1.isSelected()){
    ic.textPane.setText("TRUE");
    }

    if(ic.cBox2.isSelected()){
    ic.textPane.setText("FALSE");
    }

    }

    public void stateChanged(ChangeEvent e) {
    JTabbedPane pane = (JTabbedPane)e.getSource();
    int sel = pane.getSelectedIndex();
    String ss = pane.getTitleAt(sel);
    ic.textPane.setText(ss);
    }
    }



    //InputClass.java

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Font;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextPane;

    public class InputClass extends JFrame{

    JTabbedPane pane;
    JTextPane textPane;
    JPanel draw,drag,measure;
    JCheckBox cBox1,cBox2;
    OutputClass oc;

    public InputClass(OutputClass obj){

    this.oc = obj;
    this.setLayout(new BorderLayout());
    draw = new JPanel();
    cBox1 = new JCheckBox("TRUE");
    cBox1.addItemListener(oc);
    cBox2 = new JCheckBox("FALSE");
    cBox2.addItemListener(oc);
    draw.add(cBox1);
    draw.add(cBox2);


    drag = new JPanel();
    measure = new JPanel();

    pane = new JTabbedPane();
    pane.add("DRAW",draw);
    pane.add("DRAG",drag);
    pane.add("MEASURE",measure);
    add(pane,BorderLayout.CENTER);

    textPane = new JTextPane();
    //textPane.addChangeListener(oc); //************************************************** ***********
    textPane.setForeground(Color.darkGray);
    Font fn=new Font("Arial",Font.BOLD,12);
    textPane.setFont(fn);
    textPane.setText("At first you select draw mode then draw item.\n Observ the canvas....");
    textPane.setEditable(false);
    add(textPane,BorderLayout.SOUTH);
    }

    }

Similar Threads

  1. JTextPane/Custom JPanel problem
    By adwart in forum AWT / Swing
    Replies: 7
    Last Post: 08-01-2011, 02:59 AM
  2. JTextPane Unicode/UTF-8 problem?
    By LeonLanford in forum AWT / Swing
    Replies: 15
    Last Post: 08-16-2010, 02:36 PM
  3. problem in JTextPane
    By jperson in forum New To Java
    Replies: 4
    Last Post: 07-07-2010, 04:57 PM
  4. JTextPane focus problem
    By LeonLanford in forum AWT / Swing
    Replies: 1
    Last Post: 06-22-2010, 06:10 AM
  5. Problem in adding new JTextPane at Runtime
    By png in forum AWT / Swing
    Replies: 12
    Last Post: 12-14-2009, 12:14 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •