JTextArea problem

Why does the following code not print "Test" in the JTextArea?
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JComponent;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class ImportServer extends JPanel implements ActionListener {
     protected JTextField textField;
     protected JTextArea textArea;
     private final static String newline = "\n";
     public ImportServer() {
          super(new GridBagLayout());
          textField = new JTextField(20);
          textField.addActionListener(this);
          textArea = new JTextArea(5, 20);
          textArea.setEditable(false);
          JScrollPane scrollPane = new JScrollPane(textArea,
          JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
          JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
          //Add Components to this panel.
          GridBagConstraints c = new GridBagConstraints();
          c.gridwidth = GridBagConstraints.REMAINDER;
          c.fill = GridBagConstraints.HORIZONTAL;
          add(textField, c);
          c.fill = GridBagConstraints.BOTH;
          c.weightx = 1.0;
          c.weighty = 1.0;
          add(scrollPane, c);
     public void actionPerformed(ActionEvent evt) {
          String text = textField.getText();
          textArea.append(text + newline);
          textField.selectAll();
          //Make sure the new text is visible, even if there
          //was a selection in the text area.
          textArea.setCaretPosition(textArea.getDocument().getLength());
     * Create the GUI and show it. For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     private void createAndShowGUI() {
          //Make sure we have nice window decorations.
          JFrame.setDefaultLookAndFeelDecorated(false);
          //Create and set up the window.
          JFrame frame = new JFrame("Cbhk.net Import Server");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          //Create and set up the content pane.
          JComponent newContentPane = new ImportServer();
          newContentPane.setOpaque(true); //content panes must be opaque
          frame.setContentPane(newContentPane);
          //Display the window.
          frame.pack();
          frame.setSize(800,600);
          frame.setVisible(true);
     private void runImports() {
          textArea.append("Test\n");
          textArea.setCaretPosition(textArea.getDocument().getLength());
          textArea.repaint();
          textArea.validate();
          System.out.println(textArea.getText());
     public static void main(String[] args) {
          ImportServer server = new ImportServer();
          server.createAndShowGUI();
          server.runImports();

in main, you create an instance of the ImportServer. In createAndShowGUI, you do it again. You are not working with the same instance as the one you see. Your text is appended to the textarea created in main, but you are looking at the one created in createAndShowGUI.
Instead of creating a new ImportServer in the createAndShowGUI method, use 'this'.
here is the updated version of createAndShowGUI:
private void createAndShowGUI() {
     //Make sure we have nice window decorations.
     JFrame.setDefaultLookAndFeelDecorated(false);
     //Create and set up the window.
     JFrame frame = new JFrame("Cbhk.net Import Server");
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     //Create and set up the content pane.
     this.setOpaque(true); //content panes must be opaque
     frame.setContentPane(this);
     //Display the window.
     frame.pack();
     frame.setSize(800,600);
     frame.setVisible(true);

Similar Messages

  • Set Font to the JTextArea Problem

    Hi all, i've got a problem in setting the font for my JTextArea.
    Here is my piece of code.
    Display.append(Message.getText());
    Display.setFont(selected_font));
    Display is JTextArea, Message is String.
    The problem is i whenever i do this, everytime i change the Font of the Message, the whole messages in the Display font also change.
    What i want is, when i change the font of certain message, that certain message font ( instead of all message) also change in the Display.
    I know the problem is because of the Display.setFont(), it set the font for the whole content inside the Display. Any help to fulfill what i want?

    I'm not sure a JTextArea is appropriate for what you're doing. As its API documentation begins by saying "A JTextArea is a multi-line area that displays plain text. "
    You can set the font used by this component: but the point is that it uses a single font.
    Perhaps you are looking for a JEditorPane (including JTextPane). Check out Sun's tutorial for code examples etc: http://java.sun.com/docs/books/tutorial/uiswing/components/text.html

  • InputVerifier for JTextArea problem

    Hello,
    I am having a problem with using an InputVerifier to check a max character limit on a JTextArea. It seems that occasionally after the verify of the JTextArea fails, I lose the next character I type into it! Here is the code, followed by a description of how to reproduce the problem. Note this code is copied from the Java 1.4.2 API documentation of the InputVerifier class, with the first JTextField changed to a JTextArea and the verify method modified:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    import javax.swing.InputVerifier;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    public class TestJTextArea  extends JFrame {
        public TestJTextArea () {
           JTextArea ta = new JTextArea ("");
           ta.setPreferredSize(new Dimension(100, 50));
           getContentPane().add (ta, BorderLayout.NORTH);
           ta.setInputVerifier(new PassVerifier());
           JTextField tf2 = new JTextField ("TextField2");
           getContentPane().add (tf2, BorderLayout.SOUTH);
           WindowListener l = new WindowAdapter() {
               public void windowClosing(WindowEvent e) {
                   System.exit(0);
           addWindowListener(l);
        class PassVerifier extends InputVerifier {
            public boolean verify(JComponent input) {
                JTextArea jText = (JTextArea)input;
                boolean retValue = jText.getText().length() < 5;
                if (!retValue) {
                    System.out.println("MAX CHARS");
                return retValue;
        public static void main(String[] args) {
            Frame f = new TestJTextArea ();
           f.pack();
           f.setVisible(true);
    }A way to reproduce the problem is type in the TextArea: "123455", then Ctrl+Tab and the verify will fail. Then backspace twice to delete the "55" and Ctrl+Tab to move to the TextField. Then Tab again to go back to the TextArea and type any charachter over than 5. About 80% of the time, the character that you type will be lost and not appear in the TextArea. It doesn't always happen, but if you try it a few times it will come up. Also, occasionally the backspace keystroke is also lost in the TextArea. Note this only happens when I use Tab. I am not able to reproduce it by using the mouse to change focus.
    I have searched for a bug report on this, but have found nothing. Am I doing something wrong? I am simply using the sample code from the InputVerifier JavaDoc, but with a JTextArea... This is on a WinXP Pro machine with Java Std. Ed. 1.4.2.
    Thank you for your help.
    Angel

    JTextField jtf = (JTextField)comboBox.getEditor().getEditorComponent();
    jtf.setInputVerifier(new YourInputVerifier());

  • JScrollPane w/ JTextArea problems

    I've written a simple terminal for a project I'm working on, with a JTextField for inputs and a JTextArea to display outputs. The JTextArea uses a JScrollPane to let it scroll vertically, and wraps text to avoid horizontal scrolling.
    My problem is this: when I append text to the text area, the scroll pane sometimes scrolls to the bottom, sometimes scrolls part-way, and sometimes doesn't move at all. Ideally, I'd like to have the scroll pane always pushed to the bottom. Does anyone know what causes this kind of behaviour? What input causes the bar to scroll, and what input doesn't?
    thanks,
    Andrew

    I don't know what causes the kind if behaviour you described, but this is how you get the scrollPane to scroll to the bottom:
    int bottom = scrollPane.getVerticalScrollBar().getMaximum();
    scrollPane.getVerticalScrollBar().setValue(bottom);

  • JTextArea problem: mouseClicked event irregular

    My application allows user to add several CalcArea objects (a subclass of JPanel) in a big JPanel. Highlight of ClassArea class is given below.
    Strangely, I find that once in a while, mouseClicked event is not fired. It is very critical for my user to select a particular CalcArea and modify/update the currently selected CalcArea. It is very much annoying to find that the mouseClicked event occurs irregularly. Please advise me how I can make sure mouseClicked event occurs when user clicks on the desired CalcArea. Thanks.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.math.*;
    import javax.swing.border.*;
    import java.awt.print.*;
    public class CalcArea extends JPanel implements MouseListener, FocusListener
       JTextArea ta;
       DrawPanel dp; //subclass of JPanel
       static int iCount=0;
       static int selectedMemberID=-1;
       int memberID;     //unique ID (0-based)
       //constructor
       public CalcArea(String strID....)
       }  //constructor ends
       public void mousePressed(MouseEvent e)
       } //method mousePressed ends
       public void mouseClicked(MouseEvent e)  //***Problem here
         selectedMemberID= memberID;
         System.out.print("mseClicked***");
       public void mouseReleased(MouseEvent e) {}
       public void mouseEntered(MouseEvent e) {}
       public void mouseExited(MouseEvent e) {}

    Is there any way to solve it? I don't really understand what you are trying to accomplish, but maybe somthing like the following will help:
    e.getComponent().getGraphics();
    e.getComponent().getParent().getGraphics();

  • Scrollable JTextArea problem. Tried the techniques of previous posts.

    Hi guys,
    I know this is a very common post on this forum. I have tried the solutions mentioned in previos posts, but somehow I am unable to make a JTextArea Scrollable.
    I have written the following code :
              TAlab1 = new JTextArea(temp);
              TAlab1.setBounds(50, 130, 530, 50);
              TAlab1.setBorder(BorderFactory.createEtchedBorder() );
              TAlab1.setLineWrap(true);
              TAlab1.setEditable(false);
              jsp = new JScrollPane(TAlab1);
              p.add(jsp); // where p is JPanelHere, if I add jsp, then the JTextArea is not visible. If I add TAlab1, then I get a JTextArea, but which is not scrollable.
    I would appreciate any of your assistance.
    Regards
    kbhatia

    Calling setBounds can get you in trouble. Hardcoding values is almost always a bad idea. Here's a short demo of adding a JTextArea to a JScrollPane;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ScrollTest extends JFrame{
        private String longString = "This is just a long string to be added over and over again to textarea\n";
        int times = 0;
        private JTextArea textArea;
        public ScrollTest() {
            buildGUI();
        private void buildGUI(){
            JPanel mainPanel = (JPanel) getContentPane();
            mainPanel.setLayout(new BorderLayout());
            JPanel centerPanel = buildCenterPanel();
            mainPanel.add(centerPanel, BorderLayout.CENTER);
            JPanel buttonPanel = buildButtonPanel();
            mainPanel.add(buttonPanel, BorderLayout.SOUTH);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
            setLocationRelativeTo(null);
            setVisible(true);
        private JPanel buildButtonPanel() {
            JPanel retPanel = new JPanel();
            JButton addButton  = new JButton("Add Text");
            addButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    addText();
            retPanel.add(addButton);
            return retPanel;
        private void addText() {
            textArea.append(times+ " "+longString);
            times +=1;
        private JPanel buildCenterPanel() {
            JPanel retPanel = new JPanel(new GridLayout(1,0, 5,5));
            textArea = new JTextArea(5,10);
            textArea.setWrapStyleWord(true);
            textArea.setLineWrap(true);
            textArea.setEditable(false);
            textArea.setEnabled(false);
            JScrollPane jsp = new JScrollPane(textArea);
            retPanel.add(jsp);
            return retPanel;
        public static void main(String[] args) {
            new ScrollTest();
    }Cheers
    DB

  • Scrolling JTextArea Problems

    Hi,
    I have created a simulator based on Pattis's Karel the Robot, in Swing, which has two "logging" JTextArea's. During execution of a main method that runs the simulator the logs append new entries, and the scroll pane that they are contained within changes the viewport position so that the last entry is always shown. The caret is also adjusted so that it is located at the last appended or selected entry. However during execution I often get Null Pointer Exceptions or Array Index out Of Bounds exceptions (non-fatal) relating to the PlainView class in the JDK - and they always seem related to the refresh of dirty components. I am sure it is related to the constant scrolling of the JTextArea's but I may be wrong about that ....I was just wondering if you have any suggestions on what I can do about this or what may be the possible source.
    Thanks
    Master Sifo-Dyas

    It seems that I have found an answer in the archived Swing forum (how did I not see it before?).
    It seems that after appending a message I should use the line:
    textArea.setCaretPosition(textArea.getText().length());
    to move the caret to the end of the text, which updates the scrolling automatically.
    I tried it and it seems to work.

  • Actionlistener in swing won't let me play with my variables!

    I am sort of new to java, having done some scripting before, but not much programming experiance. OOP was, until I learned java, something I didn't use that much. All this static and public stuff was hard at first, but I finally think I understand it all.
    I am still learning java, and for one of my projects, I am trying to make a small quiz game to learn swing. I am having problems. My button actionlistener complains about my variables, and I have tried many things, like wrapping them in a container and moving them, but I cannot make it compile. Any help would be appriciated. Thanks in advance!
    //The program is a quiz thingy.
    //the error is down in the GUI section, where I make the button respond to commands
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;//for later use, download files to read off net
    import java.io.*;
    import java.math.*;
    import java.util.Random;
    public class Main {
    public static void main(String args[]) { 
      File file = new File("problems.txt");
      int probcount=5;
      int answercount=0;
      boolean onproblem = true;
      String[] Problems={"","","","","","","","","","","",""};//I find if I don't init, I get nullpointer errors
      String[] Answers={"","","","","","","","","","","",""};//sorry for the oddness
      String[] thetext=new String[100];
      int i=0;
      int t=0;
      if ( !file.exists(  ) || !file.canRead(  ) ) {
                    System.out.println( "Can't read " + file );
                    return;
                    try {
                        FileReader fr = new FileReader ( file );
                        BufferedReader in = new BufferedReader( fr );
                        String line;
                        while ((line = in.readLine(  )) != null ){
                            thetext=line;
    i++;
    catch ( FileNotFoundException e ) {
    System.out.println( "File Disappeared" );
    catch ( IOException e ) {
    System.out.println( "Error During File Reading" );
    boolean writetoprob = true;
    for(int y=0;y<i;y++)
    System.out.println(thetext[y]);
    for(int y=0;y<i;y++){
    if(thetext[y].equals("-")){
    if(writetoprob==true)
    writetoprob=false;
    else{
    writetoprob=true;
    t++;
    else{
    if(writetoprob==true)
    Problems[t]=Problems[t].concat("\n").concat(thetext[y]);
    else
    Answers[t]=Answers[t].concat("\n").concat(thetext[y]);
    System.out.println(Problems[0]);
    System.out.println(Problems[1]);
    //TODO:Randomize problems and display them, then answers when button clicked
    boolean answerbutton=true;
    int probindex=0;
    Random rnums = new Random();
    probindex=rnums.nextInt()%(t+1);
    if(probindex<0)
    probindex=-probindex;
    System.out.println(probindex);
    System.out.println(Problems[probindex]);
    JButton action = new JButton("Click for Answer!");
    JTextArea tp = new JTextArea(Problems[probindex]);
    JFrame jf = new JFrame();
    boolean onanswer = false;
    action.addActionListener( new ActionListener( ) {
    public void actionPerformed(ActionEvent theaction) {
    System.out.println(answerbutton);
    if(answerbutton==false){
    answerbutton=true;
    probindex=rnums.nextInt()%(t+1);
    if(probindex<0)
    probindex=-probindex;
    tp.setText(Problems[probindex]);
    else{
    answerbutton=false;
    tp.setText(Answers[probindex]);
    Container content = jf.getContentPane( );
    content.setLayout(new FlowLayout( ));
    content.add(tp);
    content.add(action);
    jf.pack();
    jf.setVisible(true);

    init:
    deps-jar:
    Compiling 1 source file to C:\Documents and Settings\Patrick\FirstCup\build\classes
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:91: local variable answerbutton is accessed from within inner class; needs to be declared final
    System.out.println(answerbutton);
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:92: local variable answerbutton is accessed from within inner class; needs to be declared final
    if(answerbutton==false){
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:93: local variable answerbutton is accessed from within inner class; needs to be declared final
    answerbutton=true;
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:94: local variable probindex is accessed from within inner class; needs to be declared final
    probindex=rnums.nextInt()%(t+1);
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:94: local variable rnums is accessed from within inner class; needs to be declared final
    probindex=rnums.nextInt()%(t+1);
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:94: local variable t is accessed from within inner class; needs to be declared final
    probindex=rnums.nextInt()%(t+1);
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:95: local variable probindex is accessed from within inner class; needs to be declared final
    if(probindex<0)
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:96: local variable probindex is accessed from within inner class; needs to be declared final
    probindex=-probindex;
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:96: local variable probindex is accessed from within inner class; needs to be declared final
    probindex=-probindex;
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:97: local variable Problems is accessed from within inner class; needs to be declared final
    tp.setText(Problems[probindex]);
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:97: local variable probindex is accessed from within inner class; needs to be declared final
    tp.setText(Problems[probindex]);
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:97: local variable tp is accessed from within inner class; needs to be declared final
    tp.setText(Problems[probindex]);
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:100: local variable answerbutton is accessed from within inner class; needs to be declared final
    answerbutton=false;
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:101: local variable Answers is accessed from within inner class; needs to be declared final
    tp.setText(Answers[probindex]);
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:101: local variable probindex is accessed from within inner class; needs to be declared final
    tp.setText(Answers[probindex]);
    C:\Documents and Settings\Patrick\FirstCup\src\firstcup\Main.java:101: local variable tp is accessed from within inner class; needs to be declared final
    tp.setText(Answers[probindex]);
    16 errors
    BUILD FAILED (total time: 3 seconds)

  • Setting size JScrollPane inside a JSplitPane

    Hi,
    In my program I want to have two panels, one above the other. The first panel will contain a row of objects that will be dynamically generated. These objects will have an unchangeable height, which I only know after construction. The second panel, below the first panel, will contain a column of objects, which will also be dynamically generated. These objects will take up almost the screen width.
    The following code explains what I am trying to accomplish here.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class JSplitPaneProblem extends JPanel
    implements ActionListener {
         static Color background;
         static String [] csdEngineers = { "jdoe1", "jdoe2", "jdoe3", "jdoe4", "jdoe5",
              "jdoet", "amacadam" };
         static String [] engineers = { "Choose one", "jdoe1", "jdoe2", "jdoe3", "jdoe4", "jdoe5",
              "jdoet", "amacadam" };
         static int width;
         static int height;
         static int remainingWidth;
         static int insets;
         static int labelWidth;
         static JScrollPane problemPane;
         static JPanel problemPanel;
         static int BIGNUMBER = 1;
         public JSplitPaneProblem () {
              setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
              //Get the image to use.
              ImageIcon trafficLight = createImageIcon("trafficlight.gif");
              JLabel trafficLightLabel = new JLabel (trafficLight);
              if (trafficLight != null) {
                   width = trafficLight.getIconWidth();
                   height = trafficLight.getIconHeight();
              else {
                   width = 100;
                   height = 300;
              trafficLightLabel.setPreferredSize(new Dimension (width, height + 50));
              //Set up the scroll pane.
              JScrollPane trafficLightPane = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
              JPanel trafficLightPanel = new JPanel();
              trafficLightPanel.setLayout(new BoxLayout(trafficLightPanel, BoxLayout.LINE_AXIS));
              for (int i=0; i < BIGNUMBER; i++) {
                   trafficLight = createImageIcon("trafficlight.gif");
                   trafficLightLabel = new JLabel (trafficLight);
                   trafficLightPanel.add(trafficLightLabel);
              trafficLightPane.setViewportView(trafficLightPanel);
              trafficLightPane.setPreferredSize(new Dimension(width, height));
              trafficLightPane.setMinimumSize(new Dimension(width, height));
              Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
              width = dimension.width;
              height = 36;
              insets = 4; // Number of pixels to left and/or right of a component
              labelWidth = 40;
              setBounds (0, 0, dimension.width, dimension.height);
              // Set up the problem panel.
              JScrollPane problemPane = new JScrollPane (ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
              problemPanel = new JPanel();
              // And a new problem pane, to which the problem panel is added
              problemPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
              problemPane.setViewportView(problemPanel);
              // Set up the JSlitPane
              JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,trafficLightPane,problemPane);
              splitPane.setOneTouchExpandable(true);
              add(splitPane);
          * The screen is divided in two equal sized halves, a left and a right side. Each
          * half is divided into 3 parts. remainingWidth is used to calculate the remaining
          * width inside a half.
         public static JPanel addProblem (String organisation, String problem) {
              JPanel panel = new JPanel (); // JPanel has FlowLayout as default layout
              panel.setPreferredSize(new Dimension (width, height));
              // First half, containing serverId, customer name, and problem title
              // serverId
              JTextArea serverId = new JTextArea ("99999");
              Font usedFont = new Font ("SanSerif", Font.PLAIN, 12);
              serverId.setFont(usedFont);
              serverId.setPreferredSize(new Dimension(labelWidth, height));
              serverId.setBackground(background);
              panel.add(serverId);
              // Organisation name. Gets 1/3 of remaining width
              remainingWidth = (width/2 - (int)serverId.getPreferredSize().getWidth())/3 - insets;
              JTextArea organisationArea = new JTextArea (organisation);
              organisationArea.setPreferredSize(new Dimension (remainingWidth, height));
              organisationArea.setAlignmentX(SwingConstants.LEFT);
              organisationArea.setBackground(background);
              organisationArea.setLineWrap(true);
              organisationArea.setWrapStyleWord(true);
              organisationArea.setEditable(false);
              panel.add(organisationArea);
              // Problem title
              JTextArea problemArea = new JTextArea (problem);
              problemArea.setPreferredSize(new Dimension (remainingWidth*2, height));
              problemArea.setBackground(background);
              problemArea.setLineWrap(true);
              problemArea.setWrapStyleWord(true);
              problemArea.setEditable(false);
              panel.add(problemArea);
              // Second half, containing severity, CSD and Engineer
              // Severity
              JTextArea severity = new JTextArea ("WARN");
              severity.setFont(usedFont);
              severity.setBackground(background);
              severity.setPreferredSize(new Dimension(labelWidth, height));
              panel.add(severity);
              // CSD
              JLabel csdField = new JLabel("CSD:");
              csdField.setFont(usedFont);
              JComboBox csdList = new JComboBox(csdEngineers);
              csdList.setFont(usedFont);
              csdList.setSelectedIndex(6);
              // csdList.addActionListener(this);
              panel.add(csdField);
              panel.add(csdList);
              // Solver, another ComboBox
              JLabel engineerField = new JLabel("Solver:");
              engineerField.setFont(usedFont);
              JComboBox engineerList = new JComboBox(engineers);
              engineerList.setFont(usedFont);
              engineerList.setSelectedIndex(0);
              // engineerList.addActionListener(this);
              panel.add(engineerField);
              panel.add(engineerList);
              // Empty panel to be added after this panel
              JPanel emptyPanel = new JPanel();
              emptyPanel.setPreferredSize(new Dimension (width, 15));
              return panel;
          * ActionListener
          * @param args
         public void actionPerformed(ActionEvent event) {
              System.out.println ("Burp");
         private static ImageIcon createImageIcon(String path) {
              java.net.URL imgURL = JSplitPaneProblem.class.getResource(path);
              if (imgURL != null) {
                   return new ImageIcon(imgURL);
              } else {
                   System.err.println("Couldn't find file: " + path);
                   return null;
         private static void createAndShowGUI() {
              //Create and set up the window.
              JFrame frame = new JFrame("JSlitPaneProblem");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Set the size of the window so in covers the whole screen
              Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
              frame.setBounds (0, 0, dimension.width, dimension.height);
              //Create and set up the content pane.
              JComponent newContentPane = new JSplitPaneProblem();
              newContentPane.setOpaque(true); //content panes must be opaque
              frame.setContentPane(newContentPane);
              //Display the window.
              //frame.pack();
              frame.setVisible(true);
              // Add panels
              problemPanel.setPreferredSize(new Dimension(dimension.width, dimension.height - height));
              for (int j=0; j < BIGNUMBER; j++) {
                   problemPanel.add(addProblem("Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch Computer Shop",
                   "expected string or buffer, but that is not everyting, as this problem description is extremely long. And as I am chatty, I add some more length"));
                   JPanel emptyPanel = new JPanel();
                   emptyPanel.setPreferredSize(new Dimension (width, 15));
                   problemPanel.add(addProblem("My Company", "I have no problem"));
         public static void main(String[] args) {
              //Schedule a job for the event-dispatching thread:
              //creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();
    }If you want to try it out with the trafficlight.gif mentioned in the code, get it from
    http://www.hermod.nl/images/trafficlight.gif
    The problem I have with the current code is that in the following line
    trafficLightLabel.setPreferredSize(new Dimension (width, height + 15));I try to set the size of the top panel, but the program disregards what I instruct it to do.
    When BIGNUMBER = 1, you will see that part of the bottom of the image is not shown.
    Can you help me?
    Abel
    Edited by: Abel on Feb 27, 2008 2:20 PM
    Added
    static int BIGNUMBER = 1; and where it is used. If you want to play with the program, change BIGNUMBER to for instance 10

    Found it. Add
    splitPane.resetToPreferredSizes();as last instruction in createAndShowGUI().

  • Laying out items in a JPanel

    Hi,
    I'm working on a program which needs to display "problems" on a screen. At the moment I'm working on drawing a problem. This problem will later on be incorporated in my program.
    Looking at the result of displaying two problems, do you know a way to get the top site of the buttons aligned with the top side of the text?
    TIA,
    Abel
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.Toolkit;
    import javax.swing.*;
    import javax.swing.border.Border;
    public class FlowLayoutProblem {
         static JFrame frame;
         Color background;
         int width;
         int height;
         int remainingWidth;
         int insets;
         int labelWidth;
         public FlowLayoutProblem() {
              frame = new JFrame ("FlowLayoutProblem");
              Container pane = frame.getContentPane();
              background = frame.getBackground();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
              Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
              width = dimension.width;
              height = 36;
              insets = 4; // Number of pixels to left and/or right of a component
              labelWidth = 40;
              frame.setBounds (0, 0, width, 10 * height);
          * The screen is divided in two equal sized halves, a left and a right side. Each
          * half is divided into 3 parts. remainingWidth is used to calculate the remaining
          * width inside a half.
         public void addProblem (String organisation, String problem) {
              // frame.setPreferredSize(new Dimension (width, height));
              JPanel panel = new JPanel (); // JPanel has FlowLayout as default layout
              panel.setPreferredSize(new Dimension (width, height));
              // First half, containing serverId, customer name, and problem title
              JTextArea serverId = new JTextArea ("99999");
              Font usedFont = new Font ("SanSerif", Font.PLAIN, 12);
              serverId.setFont(usedFont);
              serverId.setPreferredSize(new Dimension(labelWidth, height));
              serverId.setBackground(background);
              panel.add(serverId);
              // Organisation name. Gets 1/3 of remaining width
              remainingWidth = (width/2 - (int)serverId.getPreferredSize().getWidth())/3 - insets;
              JTextArea organisationArea = new JTextArea (organisation);
              organisationArea.setPreferredSize(new Dimension (remainingWidth, height));
              organisationArea.setAlignmentX(SwingConstants.LEFT);
              organisationArea.setBackground(background);
              organisationArea.setLineWrap(true);
              organisationArea.setWrapStyleWord(true);
              organisationArea.setEditable(false);
              panel.add(organisationArea);
              // Problem title
              JTextArea problemArea = new JTextArea (problem);
              problemArea.setPreferredSize(new Dimension (remainingWidth*2, height));
              problemArea.setBackground(background);
              problemArea.setLineWrap(true);
              problemArea.setWrapStyleWord(true);
              problemArea.setEditable(false);
              panel.add(problemArea);
              // Second half, containing severity, CSD and Engineer
              // Severity
              JTextArea severity = new JTextArea ("WARN");
              severity.setFont(usedFont);
              severity.setBackground(background);
              severity.setPreferredSize(new Dimension(labelWidth, height));
              panel.add(severity);
              // CSD
              JButton csdButton = new JButton ("Set CSD");
              csdButton.setPreferredSize(new Dimension (80, 26));
              JTextField csdField = new JTextField();
              csdField.setPreferredSize(new Dimension (150, 25));
              csdField.setEditable(false);
              csdField.setBorder(BorderFactory.createEmptyBorder());
              JPanel csdPanel = new JPanel();
              remainingWidth = (width/2 - ((int)severity.getPreferredSize().getWidth()))/2;
              csdPanel.setPreferredSize(new Dimension ((150+80+10), height));
              csdPanel.add(csdButton);
              csdPanel.add(csdField);
              panel.add(csdPanel);
              // Solver
              JButton solverButton = new JButton ("Solver");
              solverButton.setPreferredSize(new Dimension (80, 26));
              JTextField solverField = new JTextField();
              solverField.setPreferredSize(new Dimension (150, 25));
              solverField.setEditable(false);
              solverField.setBorder(BorderFactory.createEmptyBorder());
              JPanel solverPanel = new JPanel();
              solverPanel.setPreferredSize(new Dimension ((150+80+10), height));
              solverPanel.add(solverButton);
              solverPanel.add(solverField);
              panel.add(solverPanel);
              // Empty panel to be added after this panel
              JPanel emptyPanel = new JPanel();
              emptyPanel.setPreferredSize(new Dimension (width, 15));
              frame.add(panel);
              frame.add(emptyPanel);
         public static void main(String[] args) {
              FlowLayoutProblem myProblem = new FlowLayoutProblem();
              myProblem.addProblem("Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch Computer Shop",rainbow",
              "expected string or buffer, but that is not everyting, as this problem description is extremely long. And as I am chatty, I add some more length");
              myProblem.addProblem("My Company", "I have no problem");
              frame.pack();
              frame.setVisible(true) ;
    }

    Vertical alignment is not supported by FlowLayout. You need to use a BoxLayout:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class BoxLayoutFlow extends JFrame
         public BoxLayoutFlow()
              Box box = Box.createVerticalBox();
              getContentPane().add(box);
              box.add( addRow(box, false) );
              box.add( addRow(box, true) );
         public JComponent addRow(Box box, boolean align)
    //          JPanel panel = new JPanel();
              Box panel = Box.createHorizontalBox();
              panel.setBorder( new LineBorder(Color.RED) );
              JTextArea textArea = new JTextArea(3, 10);
              textArea.setMaximumSize( textArea.getPreferredSize() );
              JButton button = new JButton("Some Text");
              button.setMaximumSize( button.getPreferredSize() );
              JTextField textField = new JTextField(10);
              textField.setMaximumSize( textField.getPreferredSize() );
              if (align)
                   textArea.setAlignmentY(0.0f);
                   button.setAlignmentY(0.0f);
                   textField.setAlignmentY(0.0f);
              panel.add( textArea );
              panel.add( button );
              panel.add( textField );
              return panel;
         public static void main(String[] args)
              BoxLayoutFlow frame = new BoxLayoutFlow();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

  • JSplitPane: Panel from bottom component comes back in top component

    Hi,
    In the next program I have added a small Panel (called smallPanel) to a Panel containing what I call a problem. The smallPanel is meant as a place holder for a checkbox that in my program is to be added when needed. So either the smallPanel is added, or a checkbox.
    The smalLPanel is added to a panel in the bottomPanel. The bottomPanel is together with a topPanel added to a JSplitPane. What I found out is that if you scroll the bottomPanel downwards, the smallPanel shines through in the topPanel. My question is, is this a bug?
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class JSplitPaneProblem extends Canvas implements ActionListener
        static Color background;
        static String[] csdEngineers = {"jdoe1", "jdoe2", "jdoe3", "jdoe4", "jdoe5", "jdoet", "amacadam"};
        static String[] engineers = {"Choose one", "jdoe1", "jdoe2", "jdoe3", "jdoe4", "jdoe5", "jdoet", "amacadam"};
        static int width;
        static int height;
        static int remainingWidth;
        static int insets;
        static int labelWidth;
        static JScrollPane problemPane;
        static JPanel bottomPanel;
        static Panel smallPanel;
        static final int FAKE_CHECKBOX_SIZE = 10;
        static JSplitPane splitPane;
        static int BIGNUMBER = 100;
        public JSplitPaneProblem(JFrame frame)
            // Get the image to use.
            ImageIcon trafficLight = createImageIcon("any.gif");
            JLabel trafficLightLabel = new JLabel(trafficLight);
            if (trafficLight != null)
                width = trafficLight.getIconWidth();
                height = trafficLight.getIconHeight();
            else
                width = 100;
                height = 300;
            JPanel topPanel = new JPanel();
            JScrollPane trafficLightPane = new JScrollPane (ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            trafficLightPane.setViewportView(topPanel);
            topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.LINE_AXIS));
            for (int i = 0; i < BIGNUMBER; i++)
                trafficLight = createImageIcon("any.gif");
                trafficLightLabel = new JLabel(trafficLight);
                topPanel.add(trafficLightLabel);
            Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
            width = dimension.width;
            trafficLightPane.setPreferredSize(new Dimension(width, height));
            trafficLightPane.setMinimumSize(new Dimension(width, height+10)); // <-- Die doet ut
            height = 36;
            insets = 4; // Number of pixels to left and/or right of a component
            labelWidth = 40;
              frame.setBounds (0, 0, dimension.width, dimension.height);
            // And a new problem pane, to which the problem panel is added
            bottomPanel = new JPanel();
            bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
            JScrollPane problemPane = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            problemPane.setViewportView(bottomPanel);
            // Set up the JSlitPane
            splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, trafficLightPane, problemPane);
            splitPane.setOneTouchExpandable(true);
            splitPane.resetToPreferredSizes();
            frame.add(splitPane);
         * The screen is divided in two equal sized halves, a left and a right side. Each half is divided into 3 parts.
         * remainingWidth is used to calculate the remaining width inside a half.
        public static JPanel addProblem(String organisation, String problem, int i)
            JPanel panel = new JPanel(); // JPanel has FlowLayout as default layout
            panel.setPreferredSize(new Dimension(width, height));
            // First half, containing serverId, customer name, and problem title
            // serverId
            JTextArea serverId = new JTextArea();
            if (i < 10)
                serverId.setText("9999" + i);
            else
                serverId.setText("999" + i);
            Font usedFont = new Font("SanSerif", Font.PLAIN, 12);
            serverId.setFont(usedFont);
            serverId.setPreferredSize(new Dimension(labelWidth, height));
            serverId.setBackground(background);
            panel.add(serverId);
            // Organisation name. Gets 1/3 of remaining width
            remainingWidth = (width / 2 - (int) serverId.getPreferredSize().getWidth()) / 3 - insets;
            JTextArea organisationArea = new JTextArea(organisation);
            organisationArea.setPreferredSize(new Dimension(remainingWidth, height));
            organisationArea.setAlignmentX(SwingConstants.LEFT);
            organisationArea.setBackground(background);
            organisationArea.setLineWrap(true);
            organisationArea.setWrapStyleWord(true);
            organisationArea.setEditable(false);
            panel.add(organisationArea);
            // Problem title
            JTextArea problemArea = new JTextArea(problem);
            problemArea.setPreferredSize(new Dimension(remainingWidth * 2, height));
            problemArea.setBackground(background);
            problemArea.setLineWrap(true);
            problemArea.setWrapStyleWord(true);
            problemArea.setEditable(false);
            panel.add(problemArea);
            // Second half, containing severity, CSD and Engineer
            // Severity
            JTextArea severity = new JTextArea("WARN");
            severity.setFont(usedFont);
            severity.setBackground(background);
            severity.setPreferredSize(new Dimension(labelWidth, height));
            panel.add(severity);
            // CSD
            JLabel csdField = new JLabel("CSD:");
            csdField.setFont(usedFont);
            JComboBox csdList = new JComboBox(csdEngineers);
            csdList.setFont(usedFont);
            csdList.setSelectedIndex(6);
            //csdList.addActionListener(this);
            panel.add(csdField);
            panel.add(csdList);
    // Add "invisible" panel, used instead of checkbox (which is not added in this example)
            smallPanel = new Panel();
            smallPanel.setPreferredSize(new Dimension (FAKE_CHECKBOX_SIZE,
                        FAKE_CHECKBOX_SIZE));
            panel.add(smallPanel);
            // Solver, another ComboBox
            JLabel engineerField = new JLabel("Solver:");
            engineerField.setFont(usedFont);
            JComboBox engineerList = new JComboBox(engineers);
            engineerList.setFont(usedFont);
            engineerList.setSelectedIndex(0);
            //engineerList.addActionListener(this);
            panel.add(engineerField);
            panel.add(engineerList);
            // Empty panel to be added after this panel
            JPanel emptyPanel = new JPanel();
            emptyPanel.setPreferredSize(new Dimension(width, 15));
            return panel;
         * ActionListener
         * @param args
        public void actionPerformed(ActionEvent event)
            System.out.println("Burp");
        private static ImageIcon createImageIcon(String path)
            java.net.URL imgURL = JSplitPaneProblem.class.getResource(path);
            if (imgURL != null)
                return new ImageIcon(imgURL);
            else
                System.err.println("Couldn't find file: " + path);
                return null;
        private static void createAndShowGUI()
             Vector myVector = new Vector();
            // Create and set up the window.
            JFrame frame = new JFrame("JSlitPaneProblem");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            // Set the size of the window so in covers the whole screen
            Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
            frame.setBounds(0, 0, dimension.width, dimension.height);
            // Create and set up the content pane.
            JSplitPaneProblem newContentPane = new JSplitPaneProblem(frame);       
            // Add panels to vector
            bottomPanel.setPreferredSize(new Dimension(dimension.width, dimension.height - height));
            for (int i = 0; i < BIGNUMBER; i++)
                myVector
                    .add(addProblem(
                        "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch Computer Shop",
                        "expected string or buffer, but that is not everyting, as this problem description is extremely long. And as I am chatty, I add some more length",
                        i));
                myVector.add(addProblem("My Company", "I have no problem", i));
            System.out.println ("adding problems to bottomPanel for the first time");
            for (int j = 0; j < 2 * BIGNUMBER; j++) {
                 bottomPanel.add((JPanel)myVector.get(j));
            bottomPanel.removeAll();
            bottomPanel.revalidate();
            System.out.println ("adding problems to bottomPanel for the second time");
            for (int j = 0; j < 2 * BIGNUMBER; j++) {
                 bottomPanel.add((JPanel)myVector.get(j));
            frame.setVisible(true);
            frame.pack();
        public static void main(String[] args)
            javax.swing.SwingUtilities.invokeLater(new Runnable()
                public void run()
                    createAndShowGUI();
    }If you need an image to try out this problem, you can find it here.
    Abel
    Edited by: Abel on 22-apr-2008 11:41
    When you don't see anything in the topPanel, scroll it a bit to the right, and the bottomPanel upwards.

    Use a JPanel, not a Panel, so you don't mix heavyweight and lightweight components.

  • Problem with JTextArea or is it my code, Help!!!

    Hi,
    I am going crazy. I am sending a message to a JTextArea and I get some very wierd things happening? I really need help because this is driving me crazy. Please see the following code to see my annotations for the problems. Has anyone else experienced problems with this component?
    Thanks,
    Steve
    // THIS IS THE CLASS THAT HANDLES ALL OF THE WORK
    public class UpdateDataFields implements ActionListener {     // 400
         JTextArea msg;
         JPanel frameForCardPane;
         CardLayout cardPane;
         TestQuestionPanel fromRadio;
         public UpdateDataFields( JTextArea msgout ) {     // 100
              msg = msgout;
          }       // 100
         public void actionPerformed(ActionEvent evt) {     // 200
              String command = evt.getActionCommand();
              String reset = "Test of reset.";
              try{
                   if (command.equals("TestMe")){     // 300
                        msg.append("\nSuccessful");
                        Interface.changeCards();
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
              try{
                   if (command.equals("ButtonA")){     // 300
    // WHEN I CALL BOTH OF THE FOLLOWING METHODS THE DISPLAY WORKS
    // BUT THE CHANGECARDS METHOD DOES NOT WORK.  WHEN I COMMENT OUT
    // THE CALL TO THE DISPLAYMESSAGE METHOD THEN THE CHANGECARDS WORKS
    // FINE.  PLEASE THE INTERFACE CLASS NEXT.
                        Interface.changeCards();
                        Interface.displayMessage("test of xyz");
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
         }     // 200
    }     // 400
    // END OF UPDATEDATAFIELS  END END END
    public class Interface extends JFrame {     // 300
         static JPanel frameForCardPane;
         static CardLayout cardPane;
         static JTextArea msgout;
         TestQuestionPanel radio;
         Interface () {     // 100
              super("This is a JFrame");
            setSize(800, 400);  // width, height
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // set-up card layout
              cardPane = new CardLayout();
              frameForCardPane = new JPanel();     // for CardLayout
              frameForCardPane.setLayout(cardPane);     // set the layout to cardPane = CardLayout
              TestQuestionPanel cardOne = new TestQuestionPanel("ABC", "DEF", msgout, radio);
              TestQuestionPanel cardTwo = new TestQuestionPanel("GHI", "JKL", msgout, radio);
              frameForCardPane.add(cardOne, "first");
              frameForCardPane.add(cardTwo, "second");
              // end set-up card layout
              // set-up main pane
              // declare components
              msgout = new JTextArea( 8, 40 );
              ButtonPanel commandButtons = new ButtonPanel(msgout);
              JPanel pane = new JPanel();
              pane.setLayout(new GridLayout(2, 4, 5, 15));             pane.setBorder(BorderFactory.createEmptyBorder(30, 20, 10, 30));
              pane.add(frameForCardPane);
                 pane.add( new JScrollPane(msgout));
                 pane.add(commandButtons);
              msgout.append("Successful");
              setContentPane(pane);
              setVisible(true);
         }     // 100
    // HERE ARE THE METHODS THAT SHOULD HANDLE THE UPDATING
         static void changeCards() {     // 200
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
         }     // 200
         static void displayMessage(String test) {     // 200
                   String reset = "Test of reset.";
                   String passMessage = test;
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
                   msgout.append("\n"+ test);
         }     // 200
    }     // 300

    Hi,
    I instantiate it in this class. Does that change your opinion or the advice you gave me? Please help!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class CardLayoutQuestionsv2 {
        public static void main(String[] arguments) {
            JFrame frame = new Interface();
            frame.show();
    }

  • Selection problem in rendered JtextArea.

    I create a jtable by rendering one column using jTextarea. While selecting the row, color of selection not geting to the rendered Jtextarea. How can i solve this problem.
    please help me

    Do you include code in your getTableCellRendererComponent method to change
    the color depending on if the row is selected or not? You'll need something like
         if ( isSelected ) {
              setForeground( table.getSelectionForeground() );
              setBackground( table.getSelectionBackground() );
         } else {
              setForeground( table.getForeground() );
              setBackground( table.getBackground() );
         }: jay

  • Selection problem in JTextArea

    hi all
    i have a TextArea in which i have some coded charecters in a group of ten charactes i treet these ten characters as a single character ,so when i delete or insert these charactes all these charactes r deleted and no other character r inserted in between , i do it with the caretListener,
    But the problem which i face is on the selection i want to select these characters as when we select some part of the URL then it is selected completely.
    help in the prob.

    this might work
    paste some text into the textArea (ensure it contains a sequence "12345")
    click anywhere in area of 12345
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    class Testing extends JFrame
      String specialChars = "12345";
      boolean settingCaret = false;
      public Testing()
        setSize(200,200);
        setLocation(300,200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        final JTextArea ta = new JTextArea(10,10);
        JScrollPane sp = new JScrollPane(ta);
        sp.setPreferredSize(new Dimension(175,150));
        JPanel jp = new JPanel();
        jp.add(sp);
        getContentPane().add(jp);
        pack();
        ta.addCaretListener(new CaretListener(){
          public void caretUpdate(CaretEvent ce){
            if(settingCaret == false)
              int startPos = ta.getText().indexOf(specialChars);
              if(startPos > -1)
                if(ta.getCaretPosition() >= startPos && ta.getCaretPosition() <= startPos+specialChars.length())
                  settingCaret = true;
                  ta.setSelectionStart(startPos);
                  ta.setSelectionEnd(startPos+specialChars.length());
                settingCaret = false;
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • Problem with Function Key in multiple JTextArea's

    Hi all,
    I have an unusual problem that I'm hoping someone has run into before. I'm working on a chatroom with multiple JTextArea's. I'm filter incoming keystrokes to run the appropriate method. I want to use function keys to perform various functions. I know it will, theoretically work because my test program worked fine in my test apllet with 1 JTextArea. All the other keyevent's work fine but the eventlistener acts like it doesn't detect any (function) event at all. I'm hoping that someone has run into this before.
    Thanks.
    Chris

    Here's a code snipet:
    String dummy;
    int keyVal = e.getKeyCode();
    switch (keyVal) {
    case KeyEvent.VK_F1:
    But what concerns me is that my debugger doesn't respond to any function key. I can't even debug because the debuger can't see what I'm doing. I've tried listening for function keys in the parent panel but with the same result. This is going to be a bear to solve.
    Thanks.
    Chris

Maybe you are looking for

  • Mavericks 10.9.4 Issues

    I have a Mid 2010 MacBook Pro with a 2.4 ghz intel core 2 duo processor, 4 GB of memory, and a 250 GB hard drive.  Although my computer is getting older I was not having any problems with it until I downloaded the Mavericks 10.9.4 software package re

  • How to create the Business System both sender and receiver in SAP XI / PI

    Dear All kindly let me know how to create the Business System both sender and receiver in SAP XI / PI Regards Blue

  • ABAP Code Inspector

    Is there a way to confine the checks performed by Code Inspector to my program only? My program invokes much SAP-supplied code in the form of includes.  And the code inspector covers this code as well.  I am interested in seeing the results for my co

  • Saved pages documents won't open

    I have suddenly developed an issue with my "Pages" documents that have been saved. I am not able to open "any" of them. All but one is grayed out and will not open. This is something that just recently, as in the last few days,  has happened. I had s

  • Mcod installation pre-requisites

    Dear All, I am about to install MCOD system. ECC6.0 is already installed on the host, Now It is needed to install CRM 5.0 on to the same host and same database oracle. Could you please let me know what are the pre-requisites we take before i start th