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

Similar Messages

  • Select problem in the JTextArea

    Hi
    I have a problem on the select(), I am trying to select multiple lines of text in the JTextArea, but select(int start, int end) can only select single line, int end will be cut to the length of the line instead of going to the next line. Can anyone give me any advice?
    Thanks in advance

    DefaultHighlighter highlighter = (DefaultHighlighter)textArea.getHighlighter();
    highlighter.setDrawsLayeredHighlights(false);

  • Selecting Text in a JTextArea

    Hi, I have this problem with the JTextArea Caret positioning behaviour.
    I wanna select some text when I click (click, no dragging included) on a line. I use setcaretposition in the beggining of the line and movecaretposition in the end of the line.
    Nothing happens!!
    If I click the mouse and drag it a little bit then it works fine selecting the text showing the right colors and everything.
    I tried with the addhighlight method in the higlighter instance of JTextArea but it doesn't really select it, just changes it color.
    What do I have to do so that I can select text without having to drag when I click??
    Thaks a lot

    This shows you how to do it using a right click:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    public class TextAreaTest extends JFrame
         JTextArea textArea;
         JScrollPane scrollPane;
         public TextAreaTest()
              textArea = new JTextArea( "one two\nthree four", 10, 30 )
                   //  the tab character is not inserted into the text area
                   public boolean isManagingFocus()
                        return false;
              textArea.setLineWrap( true );
              textArea.setSize( textArea.getPreferredSize() );
              textArea.setSelectionColor( Color.red );
              textArea.setSelectedTextColor( Color.green );
              try
                   System.out.println( textArea.modelToView( 4 ) );
                   System.out.println( Utilities.getRowStart(textArea, 4) );
              catch (Exception e) {}
              textArea.addMouseListener( new MouseAdapter()
                   public void mouseClicked(MouseEvent e)
                        if ( SwingUtilities.isRightMouseButton(e) )
                             try
                                  int offset = textArea.viewToModel( e.getPoint() );
                                  System.out.println( textArea.modelToView( offset ) );
                                  int start = Utilities.getWordStart(textArea, offset);
                                  int end = Utilities.getWordEnd(textArea, offset);
                                  String word = textArea.getDocument().getText(start, end-start);
                                  System.out.println( "Selected word: " + word );
                                  int rowStart = Utilities.getRowStart(textArea, offset);
                                  int rowEnd = Utilities.getRowEnd(textArea, offset);
                                  System.out.println( "Row start offset: " + rowStart );
                                  System.out.println( "Row end   offset: " + rowEnd );
                                  textArea.select(rowStart, rowEnd);
                             catch (Exception e2) {}
              textArea.addCaretListener( new CaretListener()
                   public void caretUpdate(CaretEvent e)
                        int caretPosition = textArea.getCaretPosition();
                        Element root = textArea.getDocument().getDefaultRootElement();
                        int row = root.getElementIndex( caretPosition );
                        int column = caretPosition - root.getElement( row ).getStartOffset();
                        System.out.println( "Row   : " + ( row + 1 ) );
                        System.out.println( "Column: " + ( column + 1 ) );
              textArea.addKeyListener( new KeyAdapter()
                   public void keyPressed(KeyEvent e)
                        System.out.println( textArea.getDocument().getDefaultRootElement().getElementCount() );
              scrollPane = new JScrollPane( textArea );
              getContentPane().add( scrollPane );
              getContentPane().add( new JTextField(10),BorderLayout.SOUTH );
    //          textArea.getInputMap().put( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "" );
         public static void main(String[] args)
              TextAreaTest frame = new TextAreaTest();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }

  • Selection Problem with JTable

    Hello,
    i have a selection problem with JTable. I want to allow only single cell selection and additionally limit the selection to the first column.
    I preffered the style from MS Outlook Express where you can select the email accounts to edit.
    It is a table like this:
    Account name  |   Type  |   ...
    --------------|---------|---------------------
    Hotmail       |   POP3  |
    GMX           |   IMAP  |The selection should be only avaibable at 'Hotmail' or 'GMX' - not at 'POP3', 'IMAP' or as complete row selection.
    Please help me!
    Thanks.
    Warlock

    Maybe this will helpimport java.awt.*;
    import javax.swing.*;
    public class Test3 extends JFrame {
      public Test3() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        String[] head = {"One", "Two"};
        String[][] data = {{"R1-C1", "R1-C2"}, {"R2-C1", "R2-C2"}};
        JTable jt = new JTable(data, head);
        jt.getColumnModel().setSelectionModel(new MyTableSelectionModel());
        content.add(new JScrollPane(jt), BorderLayout.CENTER);
        jt.setCellSelectionEnabled(true);
        jt.setRowSelectionAllowed(false);
        jt.setColumnSelectionAllowed(false);
        setSize(300, 300);
        setVisible(true);
      public static void main(String[] arghs) { new Test3(); }
    class MyTableSelectionModel extends DefaultListSelectionModel {
      public void setSelectionInterval(int index0, int index1) {
        super.setSelectionInterval(0, 0);
    }

  • Select Problem For 'Back Menus' - Zen V P

    Just got the Zen V Plus and tried to set the time/date. Followed the 'guide' and after the time/date screen pressed the 'back button'. Got the Set Alarm/Date/Time (etc) menu but when I selected an option (moved joystick down to desired option then pressed the joystick) the time/date display came up and I was NOT ABLE to set the date. Same thing occurred trying to set the date (tried it several times and it worked once .... then attempted again - several times (4) but it only worked once). Turns out I have the same problem with any option in ANY 'back' menu. Suggestion?
    Do I have a defecti've unit (can't be the 'operator' who is defecti've! haha)? Should I return it and try another?
    Actually not that interested in playing music .... it's more for playing .wma(DRM) book files.

    Latest ... updated my firmware (to ZENVPlus_PCFW_P4S_L2___0.exe) and it fixed the select problem for SET DATE/TIME etc however
    the SELECT procedure doesn't always work for 'back button' menus. Example: tried to set a bookmark... following procedure in 'guide', pressed 'back button' and held it, from 'NOW PLAYING' screen - works 2 out of 5 times. Most of the time, pressing and holding takes you back to the previous menu - not to the 'back' (or in this case the SET BOOKMARK) menu. Sounds like something for the next version of firmware ... the code doesn't always set an internal timer correctly (am a programmer of 30 years ... part of that time pgmmng firmware).

  • Print selection problem

    when i select a page to be print from my pc the page select in

    Hello. I feel your pain and frustration with the print selection problem in safari, especially in Snow Leopard. I have spent hours trawling help pages and forums etc. BUT YEE HAA (sorry got a bit excited, but it really was hours) I found the answer. So here goes.
    Click on Safari
    Scroll down to services then slide to right
    Scroll down to services preferences and click
    Scroll down to the Text section
    If you Tick the Text box it will choose all options for you. Or if you don't want all options in the Text list, then untick Text box and tick options you do want.
    BUT for your print selection problem make sure you tick NEW TEXT EDIT WINDOW CONTAINING SELECTION.
    Then when you want to select something in a web page you want to print (including pictures etc) then highlight it, then Right click. And low and behold, in the list is NEW TEXT EDIT WINDOW CONTAINING SELECTION. Click that, Then press cmd+p and your printing.
    I really hope that helps with your problem
    I can now go to sleep.

  • At Line selection problem

    hi,
    iam stuck up with AT LINE-SELECTION problem ie i designed a screen where they need month list on clicking F4. i got the month list using month_names_get in the screen but while clicking the relevant month no.it's not entering into the required parameter. i have attached the codings,
    MODULE MONTH_DIS OUTPUT.
      SUPPRESS DIALOG.
      LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
      SET PF-STATUS SPACE.
      NEW-PAGE NO-TITLE.
      WRITE:/ 'SELECT MONTH' COLOR COL_HEADING.
      ULINE.
      DATA: T_MNTH LIKE T247 OCCURS 12 WITH HEADER LINE.
      refresh t_mnth.
      CALL FUNCTION 'MONTH_NAMES_GET'
       EXPORTING
         LANGUAGE                    = SY-LANGU
    IMPORTING
      RETURN_CODE                 =
        TABLES
          MONTH_NAMES                 = T_MNTH
       EXCEPTIONS
         MONTH_NAMES_NOT_FOUND       = 1
         OTHERS                      = 2
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      loop at t_mnth.
        write:/ t_mnth-mnr, t_mnth-ltx.
      endloop.
      CLEAR T_MNTH-MNR.
    ENDMODULE.                 " MONTH_DIS  OUTPUT
    AT LINE-SELECTION.
      p_period = t_mnth-mnr.
      CHECK NOT p_period IS INITIAL.
      LEAVE TO SCREEN 0.
    here in the AT LINE-SELECTION, the selected month is not coming to the required parameter.
    pls help me in this issue,
    Thanks in advance,
    Premnath.

    You need to set a "Hide" after the write... I suggest you also set your own dialog PF-STATUS too so you can have just a PF2 "pick" button and a Cancel button ( this will look better to the user).
    loop at t_mnth.
      write:/ t_mnth-mnr, t_mnth-ltx.
      hide: t_mnth.  "needs this
    endloop.
    clear: t_mnth.

  • Weird BGP path selection problem

    Hi, all,
    I am seeing a weird BGP path selection problem on 4948 switch running cat4500-entservicesk9-mz.122-46.SG.bin code, this switch has two uplinks to the same ISP's different edge router, one circuit is primary the other one is strict backup, only default route is accepted from ISP. I am setting both local preference and weight to the default route advertised over backup link, however neither one is taking effect, BGP still thinks the backup link is better, what could be wrong?
    rtr#sh ip bgp 0.0.0.0/0
    BGP routing table entry for 0.0.0.0/0, version 105
    Paths: (3 available, best #2, table Default-IP-Routing-Table, not advertised to EBGP peer)
      Not advertised to any peer
      17675, (received & used)
        203.169.8.37 from 203.169.8.37 (61.211.160.150)
          Origin IGP, localpref 100, valid, external
          Community: 65001:0 no-export
      17675
        203.169.8.45 from 203.169.8.45 (61.211.160.151)
          Origin IGP, localpref 90, weight 90, valid, external, best <====
          Community: 65001:0 no-export
      17675, (received-only)
        203.169.8.45 from 203.169.8.45 (61.211.160.151)
          Origin IGP, localpref 100, valid, external
          Community: 65001:0 no-export
    Thanks

    Hi,
    On cisco routers , weight is having highest preference to decide best path. By default for received route, weight is 0 but you are setting weight 90 to backup path and that is why it is getting preferred (higher is better). Please remove weight and let local preference be 90 (lesser than route on primary path)
    --Pls dont forget to rate helpful posts--
    Regards,
    Akash

  • AV sync problems when rendering Quicktime in PE 8

    I have a simple problem when rendering to Quicktime format fromPremere Elements 8: The AV sync goes out of whack.
    I have tried rendering:
    (a). To MPEG - output is fine.
    (b). To WMV - output is fine.
    (c). MOV - av sync errors
    I am assembling about five clips. The first clip plays fine. The AV sync problems starts at the second clip - the audio is a good 3 seconds or so ahead of the video.
    Everything is fine in the editing window.
    I am running in Windows 7.  To make sure it is not the player, I have played the quicktime output in Windows Media and itunes and the same problem is in both.
    Has anyone seen this issue?
    Thanks.

    Hi Steve,
    Sorry for the confusion. It a sensible suggestion to identify the input formats and output formats and I would most appreciate your inputs to this issue because I admit that I am really struggling here to get a workflow going.
    Input  formats:
    1. MJPEG 1280x720P at 24 frames per second (from a Panasonic Lumix Camera)
    2. WMV 1280x720P at 24 frames per second from output of other programs (which only support wmv output at High def output)
    3. MPEG2 1280x720P at 24 frames per second (and sometimes 25 frames per second) from other sources
    Target output formats are:
    1. Blu-Ray
    2. MP4 container format @ 1280x720P for playing on my Apple TV
    3. DVD  (ordinary plain PAL DVD at 720x576P at 25 frames per second)
    My goal is have Pre Elements 8 Project settings in High Def and then to simply target all three outputs from one project so that I do not have to redo all of the projects with different project settings.
    Workflow is in two stages:
    Step 1 is to create one project for each Chapter and save to disk:  The inputs are from all three input formats that I identified above (High Def - MJPEG, WMV, and MPEG2). I would like to edit, mix the audio, and then save each chapter to disk. The format in which I save this is preferably some kind of high def format that can be edited easily at a later time.
    Step 2 is to create the Project that is used to assemble each chapter for final output: This is the project where I put in Chapter marks, create menus, etc.  The target outputs from this chapter are  Blu Ray (high def), AppleTV (high def), and PAL DVD (Standard def).
    In all cases, I set up my Project Settings as HDV-AVI for internal rendering because all inputs are high def and most target outputs are high def.
    Issues that I am dealing with:
    1. I cannot figure out the best export format to go from Step 1 to Step 2.  HDV-AVI doesn't seem to be available as an export format. Basically, I am looking for an export format that puts the least strain on resources when they are read in for Step 2 and retains the highest quality.
    2. Most of my inputs are 24 frames per second but the internal rendering for Pre Elements 8 seems to be 25 frames per second.  Frame rate conversion can be quite tricky and can put significant strain on resources, but it is not clear if this is straining Pre Elements 8 or not. It does seem to be. I am happy to convert my files into a format that puts the least strain on Pre Elements 8 internal rendering and yet produces the best output.
    Note: If you ask - why do I do this in two steps?  It is because I am always putting a strain on system resources when operating in high def. Unless I am careful, I get a message that Pre Element is "low on resources" followed by a crash shortly thereafter.  I have Win7 32 bit, 4 GB RAM, no other programs running, all drivers updated with the most recent version (yes - even the NVIDIA driver) so there really isn't anything else that I can do in this area.
    So I am looking for suggestions in the following areas:
    1. An alternative workflow that produces the three high def outputs with the three high def inputs defined above that doesn't cause Pre Elements to continually go low on resources and crash.
          OR
    2. A recommendation for a high def format that puts minimal strain on Pre Element resources?
    Thanks!

  • Problems with rendering quality in Premiere Elements 9

    Hello, I've made a few videos with PE 9 now, and I get very poor quality rendering despite trying several different settings. I saw on a help thread earlier that I needed to try changing to HD when creating the new file from the beginning. I did that, but it only made my PE 9 run more slowly, and the rendering quality was not improved. I also read somewhere that using .MOV files as a source can cause problems with rendering; is that true? I hope not! I use a Lumix bridge camera for my videos, and the video quality is very good. And when I'm working with these videos within PE 9 the quality is great. It's only when exporting to various file types that the quality suddenly becomes poor. For the most part I have made compilation videos of gymnasts, and when their legs move they are often so lined or pixelated that they become invisible. Here is an example of a short gym video I made yesterday: http://www.youtube.com/watch?v=-0s7tUBcSZk. The last girl jumping gives the best example of this invisible leg problem.
    You can see the original source films here: http://www.youtube.com/watch?v=zmUMi9oN8dQ
    http://www.youtube.com/watch?v=OEzcJZjhxiI
    and http://www.youtube.com/watch?v=I53twqPQMV4
    The sequences I took in my compilation video start at about 20 seconds in the source videos.
    Youtube does reduce the quality of the videos slightly, but in any case you can definitely see a difference in quality between the source videos and the PE 9 rendered compilation video.
    I'm quite disappointed because I made a longer compilation video set to music (which was a lot of work), and it looks so much nicer on PE 9 than on any of the rendered formats, but of course I can't share the PE 9 version!
    Thanks very much for your help.
    Chleste

    Thanks Steve. I'm not sure what resolution I'm shooting in, actually. However, the thing is that when I make these compilations, I like to go back to source videos I've made in the past sometimes. Sometimes these videos come from a Canon camera, and sometimes they even come from my Samsung mobile telephone. I like being able to creatively combine historic moments, and these moments might have been recorded without any intention at the time of making a compilation video. Is it not possible to combine several kinds of video sources?
    I'm uploading an example of a compilation with mixed source videos from various kinds of cameras. It's 710 Megs so it will take a while, but when it's finished you will be able to see it at http://youtu.be/CslpULRe4LU.
    I opened up the file for the compilation of the four girls on the beam (video posted in original message), and I do indeed see those red lines in the timeline. Is there anything I can do now about that, or do I have to start the project all over?
    I'm confused about the processor requirements. Even if I can see my video perfectly in PE 9, the actual export process will be affected if my system is not up to par? If so, that's a bit disappointing! I'm not sure what my processor details are, but I will find out and let you know.
    Many thanks.

  • Certificate selection problem in Safari

    Hi ,
    I have certifcates A,B,C,D for the same site , whenever i use the Mozilla it is asking which one to select , but somehow i dont know why Safari is asking the same option.
    It is forcing me to accept Certifcate A to that paricular site. How to solve this problem in safari.
    Regards
    Vikranth

    Hello. I feel your pain and frustration with the print selection problem in safari, especially in Snow Leopard. I have spent hours trawling help pages and forums etc. BUT YEE HAA (sorry got a bit excited, but it really was hours) I found the answer. So here goes.
    Click on Safari
    Scroll down to services then slide to right
    Scroll down to services preferences and click
    Scroll down to the Text section
    If you Tick the Text box it will choose all options for you. Or if you don't want all options in the Text list, then untick Text box and tick options you do want.
    BUT for your print selection problem make sure you tick NEW TEXT EDIT WINDOW CONTAINING SELECTION.
    Then when you want to select something in a web page you want to print (including pictures etc) then highlight it, then Right click. And low and behold, in the list is NEW TEXT EDIT WINDOW CONTAINING SELECTION. Click that, Then press cmd+p and your printing.
    I really hope that helps with your problem
    I can now go to sleep.

  • Problem in updating jtextarea

    My requirement is, client has to sent string messages and server has to receive these messages and display it in jtextarea. In my code sending and receiving are done properly, but the problem is the jtextarea is not updated, it goes blank.
    I have attached the client and server files, can anyone solve my problem?
    Thanks in advance.
    //server file
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.text.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MessageCenter extends javax.swing.JFrame {
        public MessageCenter() {
            initComponents();
        private void initComponents() {
            jLabel1 = new JLabel();
            jScrollPane1 = new JScrollPane();
            jTextArea1 = new JTextArea();
            jPanel1 = new JPanel();
            jLabel5 = new JLabel();
            jLabel3 = new JLabel();
            jButton1 = new JButton();
            jButton2 = new JButton();
            jLabel2 = new JLabel();
            jLabel4 = new JLabel();
            menuBar = new JMenuBar();
            fileMenu = new JMenu();
            Start = new JMenuItem();
            jSeparator1 = new JSeparator();
            Stop = new JMenuItem();
            jSeparator2 = new JSeparator();
            Exit = new JMenuItem();
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setTitle("Message Center");
            setMaximizedBounds(new java.awt.Rectangle(0, 0, 560, 700));
            setBounds(0,0,600,700);
            setName("");
            jLabel1.setBackground(new java.awt.Color(255, 255, 255));
            jLabel1.setFont(new java.awt.Font("Georgia", 1, 24));
            jLabel1.setForeground(new java.awt.Color(34, 44, 106));
            jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
            jLabel1.setText("Message Center");
            jLabel1.setIconTextGap(0);
            getContentPane().add(jLabel1, java.awt.BorderLayout.NORTH);
            jTextArea1.setColumns(20);
            jTextArea1.setFont(new java.awt.Font("Book Antiqua", 0, 12));
            jTextArea1.setLineWrap(true);
            jTextArea1.setRows(25);
            jTextArea1.setBorder(null);
            jScrollPane1.setViewportView(jTextArea1);
            getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
            jPanel1.setLayout(new java.awt.GridLayout(1, 6, 10, 5));
            jPanel1.add(jLabel5);
            jPanel1.add(jLabel3);
            jButton1.setText("Start");
            jPanel1.add(jButton1);
            jButton2.setText("Stop");
            jPanel1.add(jButton2);
            jPanel1.add(jLabel2);
            jPanel1.add(jLabel4);
            getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
            fileMenu.setText("File");
            Start.setText("Start");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    System.out.println("hello");
                    StartActionPerformed(evt);
            fileMenu.add(Start);
            fileMenu.add(jSeparator1);
            Stop.setText("Stop");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    StopActionPerformed(evt);
            fileMenu.add(Stop);
            fileMenu.add(jSeparator2);
            Exit.setText("Exit");
            fileMenu.add(Exit);
            menuBar.add(fileMenu);
            setJMenuBar(menuBar);
            pack();
    private void StartActionPerformed(java.awt.event.ActionEvent evt)  {
              try{
                        Server t=new Server(jTextArea1);
                        t.listenSocket();
              catch(Exception e)
              e.printStackTrace();
        private void StopActionPerformed(java.awt.event.ActionEvent evt) {
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new MessageCenter().setVisible(true);
        private JMenuItem Exit;
        private JMenuItem Start;
        private JMenuItem Stop;
        private JMenu fileMenu;
        private JButton jButton1;
        private JButton jButton2;
        private JLabel jLabel1;
        private JLabel jLabel2;
        private JLabel jLabel3;
        private JLabel jLabel4;
        private JLabel jLabel5;
        private JPanel jPanel1;
        private JScrollPane jScrollPane1;
        private JSeparator jSeparator1;
        private JSeparator jSeparator2;
        public JTextArea jTextArea1;
        private JMenuBar menuBar;
    class ClientThread implements Runnable {
      private Socket client;
      JTextArea jt;
      ClientThread(Socket client,JTextArea jt) {
       this.client = client;
       this.jt=jt;
      public void run(){
        try{
               //DataInputStream dis= new DataInputStream(client.getInputStream());
                DataInputStream dis= new DataInputStream(new BufferedInputStream(client.getInputStream()));
               System.out.println("client connected");
               //BufferedReader dis = new BufferedReader(new InputStreamReader(s.getInputStream()));
                   String msg=null;
                   byte msg1[]=new byte[200];
                while(true)
                   try{
                   if(dis.available()>0)
                   dis.readFully(msg1,0,dis.available());
                 //  System.out.println("Msg is ==> "+new String(msg1));
                   new PrinterThread(jt,new String(msg1)).start();
                   msg1=new byte[200];
                   Thread.sleep(1000);
                      }catch (Exception e) {
                         System.out.println("Exception  ");
             } catch (IOException e) {
                         System.out.println("Exception occurred");
    class Server {
              JTextArea jt;
              public Server(JTextArea jt)
                   this.jt=jt;
              public void listenSocket() throws Exception
              ServerSocket ss=null;
              try{
              ss=new ServerSocket(8000);
              System.out.println("Server started");
             catch (IOException e) {
                         System.out.println("Exception");
                         System.exit(-1);
             while(true){
               ClientThread w;
               try{
            w = new ClientThread(ss.accept(),jt);
            Thread t = new Thread(w);
            t.start();
                catch (IOException e) {
            System.out.println("Accept failed: 8000");
           public static void main(String args[])throws Exception {
              /*Server t=new Server();
              t.listenSocket();*/
         class PrinterThread extends Thread
                public PrinterThread(JTextArea jt1,String msg)
                 jTextArea1 = jt1;
                 this.msg=msg;
                 System.out.println("PrinterThread constructor ");
                public void run()
                 try
                    Date today;
                    SimpleDateFormat formatter;
                    String output;
                     String pattern="dd.MM.yyyy '@' H:mm";
                    formatter = new SimpleDateFormat(pattern);
                    today = new Date();
                    output = formatter.format(today);
                        System.out.println(" "+output+"  "+msg+" \n");
                          jTextArea1.append(" "+output+"  "+msg+" \n");
                          jTextArea1.updateUI();
                             jTextArea1.revalidate();
    //                      JOptionPane.showMessageDialog(null,"hi");
                          //System.out.println("Get text "+jTextArea1.getText());
                 catch (Exception exception) {}
                private JComboBox combo;
                private JTextArea jTextArea1;
                String msg=null;
    //client.java
    import java.net.*;
    import java.io.*;
    import java.io.File;
    public class client {
           public static void main(String args[]) {
                   try {
                           Socket ss=new Socket(InetAddress.getLocalHost(),8000);
                           DataOutputStream dos=new DataOutputStream(ss.getOutputStream());
                           for(int i=1;i<100;i++){
                              if((i%2)==0)
                            dos.writeBytes("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,3233");
                              else
                            dos.writeBytes("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42");
                           Thread.sleep(5000);
                   catch(Exception e) {
                   e.printStackTrace();
                   System.out.println(" ");
    }

    You need to run your Server in a separate Thread.
    Right now its running in the GUI Event Thread.I created new thread for my server, now it's updating jtextarea.
    Thank you very much.

  • How can we get the selected line number from JTextArea ?

    how can we get the selected line number from JTextArea ? and want to insert line/string given line number into JTextArea??? is it possible ?

    Praitheesh wrote:
    how can we get the selected line number from JTextArea ?
    textArea.getLineOfOffset(textArea.getCaretPosition());
    and want to insert line/string given line number into JTextArea??? is it possible ?
    int lineToInsertAt = 5; // Whatever you want.
    int offs = textArea.getLineStartOffset(lineToInsertAt);
    textArea.insert("Text to insert", offs);

  • Can't set selected text in a JTextArea (bizarre)!

    I've go this method here to select text in a JTextArea is doesn't work.
    Any ideas?? I haven't posted ALL the code because there is quite a lot of it in a number of classes.
    public void selection(int i)
              String meth = methods.get(i).toString();
              String tex = tc.getText();
              int pos = tex.indexOf(meth);
              if (pos != -1) {
                   myTextComponent.setSelectionStart(pos);                myTextComponent.setSelectionEndpos+meth.length));                
         }

    Selected text is only shown when the text component has focus. Assuming you are clicking on a button to invoke your code you would need to reset focus on the text field:
    myTextComponent.requestFocus();

  • Problem while rendering report generated with iText API

    Hi!
    I am stuck with problem of rendering report generated through iText API.
    What exactly happens is, I have to put an image (.jpg) on my report, when I am generating HTML file using iText API, the image size is normal i.e., as it is taken.
    But when I render it to take print through printer, the size of image is getting short i.e., it prints like an Icon on Paper. What can I do to get the proper image size on paper also?
    The code is as follows, which I have used to render
    public class HTMLPrintRenderer implements Printable {
        ReportAbs objReport;
        JEditorPane editorPane;
        String fileName;
        final int STARTING_PAGESET_NUMBER=0;
        int currentPageSetNumber=STARTING_PAGESET_NUMBER;
        /** Creates a new instance of HTMLPrintRenderer */
        public HTMLPrintRenderer(ReportAbs  objReport) throws Exception{
            this.objReport=objReport;
            this.fileName=ReportsUtility.getReportLocation()+ objReport.getReportFileName();
            if(objReport.isLayoutLandscape()){
                SCALE =600.0/1000;//600.0/850;
            else{
                SCALE =600.0/850;
            init();
        private void init()throws Exception{
            setDocument(STARTING_PAGESET_NUMBER);
        public void setDocument(int pageSetNumber) throws Exception{
            editorPane=new JEditorPane();
            ((AbstractDocument)editorPane.getDocument()).setAsynchronousLoadPriority(-1);
            editorPane.setText("text/html");
            editorPane.setPage("file:"+fileName+"."+pageSetNumber);
            currentPageSetNumber=pageSetNumber;
        int pageCountInPageSet=0;// counter to track number of pages in each pageSet
        int currentPage=-1;
        double pageStartY=0,pageEndY=0;
        final double SCALE;// =600.0/1000;//600.0/850;
        final int HEADER_HEIGHT=30;//50;
        final int FOOTER_HEIGHT=70;
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
            Graphics2D graphics2D;
            graphics2D = (Graphics2D) graphics;
            initEditorPane(editorPane,pageFormat);
            ReportPrinterUtility.printPageAttributes(pageFormat);
            /// print custom here... page numbers and page headers may be printed here
            /// meant only for HEADRS and FOOTERS
            ///                 caution... DO NOT ALTER GRAPHICS OBJECT ATTRIBUTES
            /// @author Manoj       
            //TRANSLATE..............must also be reverse translated
            double x=pageFormat.getImageableX();
            double y=pageFormat.getImageableY();
            graphics2D.translate(x,y);
            paintCustomPage(graphics2D,pageFormat);
            //REVERSETRANSLATE
            graphics2D.translate(-x,-y);
            graphics2D.scale(SCALE,SCALE);
            //  V set clipping area
            int headerHeight=HEADER_HEIGHT;
                graphics2D.setClip((int)(pageFormat.getImageableX()/SCALE),
                (int) ((pageFormat.getImageableY()+headerHeight)/SCALE),
                (int) (pageFormat.getImageableWidth()/SCALE),
                (int) ((pageFormat.getImageableHeight()-FOOTER_HEIGHT)/SCALE));
            //  VI set pageStart on editorPane
            if (pageIndex > currentPage) {
                currentPage = pageIndex;
                pageStartY += pageEndY;
                pageEndY = graphics2D.getClipBounds().getHeight();
                pageCountInPageSet++;
            //  VII
            graphics2D.translate(graphics2D.getClipBounds().getX(),
            graphics2D.getClipBounds().getY());
            //  VIII prepare clipping area
            Rectangle allocation = new Rectangle(0,
            (int) -pageStartY,
            (int) (editorPane.getMinimumSize().getWidth()),
            (int) (editorPane.getPreferredSize().getHeight()));
            View rootView=editorPane.getUI().getRootView(editorPane);
            if (printView(graphics2D,allocation,rootView)) {//page exists          
                System.out.println("page exists"+pageCountInPageSet);
                return Printable.PAGE_EXISTS;
            else {// page does not exist
                System.out.println("resetting page parameters");
                pageStartY = 0;
                pageEndY = 0;
                currentPage = -1;
                if(!setupNextPage()){///more pages exist TODO:
                    return Printable.NO_SUCH_PAGE;
                else{//no more pages exist
                    //                call next page
                    pageCountInPageSet=0;//reset to first page in pageSet
                    resetGraphics(graphics2D,pageFormat);
                    return print(graphics2D,pageFormat,pageIndex);
    private void resetGraphics(Graphics2D graphics2D,PageFormat pFormat){
            graphics2D.clearRect(0,0,
            (int)(pFormat.getImageableWidth()/SCALE),
            (int)(pFormat.getImageableHeight()/SCALE));
            graphics2D.translate(-graphics2D.getClipBounds().getX(),
            -graphics2D.getClipBounds().getY());
            graphics2D.scale(1/SCALE, 1/SCALE);
        }

    Hi!
    I am stuck with problem of rendering report generated through iText API.
    What exactly happens is, I have to put an image (.jpg) on my report, when I am generating HTML file using iText API, the image size is normal i.e., as it is taken.
    But when I render it to take print through printer, the size of image is getting short i.e., it prints like an Icon on Paper. What can I do to get the proper image size on paper also?
    The code is as follows, which I have used to render
    public class HTMLPrintRenderer implements Printable {
        ReportAbs objReport;
        JEditorPane editorPane;
        String fileName;
        final int STARTING_PAGESET_NUMBER=0;
        int currentPageSetNumber=STARTING_PAGESET_NUMBER;
        /** Creates a new instance of HTMLPrintRenderer */
        public HTMLPrintRenderer(ReportAbs  objReport) throws Exception{
            this.objReport=objReport;
            this.fileName=ReportsUtility.getReportLocation()+ objReport.getReportFileName();
            if(objReport.isLayoutLandscape()){
                SCALE =600.0/1000;//600.0/850;
            else{
                SCALE =600.0/850;
            init();
        private void init()throws Exception{
            setDocument(STARTING_PAGESET_NUMBER);
        public void setDocument(int pageSetNumber) throws Exception{
            editorPane=new JEditorPane();
            ((AbstractDocument)editorPane.getDocument()).setAsynchronousLoadPriority(-1);
            editorPane.setText("text/html");
            editorPane.setPage("file:"+fileName+"."+pageSetNumber);
            currentPageSetNumber=pageSetNumber;
        int pageCountInPageSet=0;// counter to track number of pages in each pageSet
        int currentPage=-1;
        double pageStartY=0,pageEndY=0;
        final double SCALE;// =600.0/1000;//600.0/850;
        final int HEADER_HEIGHT=30;//50;
        final int FOOTER_HEIGHT=70;
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
            Graphics2D graphics2D;
            graphics2D = (Graphics2D) graphics;
            initEditorPane(editorPane,pageFormat);
            ReportPrinterUtility.printPageAttributes(pageFormat);
            /// print custom here... page numbers and page headers may be printed here
            /// meant only for HEADRS and FOOTERS
            ///                 caution... DO NOT ALTER GRAPHICS OBJECT ATTRIBUTES
            /// @author Manoj       
            //TRANSLATE..............must also be reverse translated
            double x=pageFormat.getImageableX();
            double y=pageFormat.getImageableY();
            graphics2D.translate(x,y);
            paintCustomPage(graphics2D,pageFormat);
            //REVERSETRANSLATE
            graphics2D.translate(-x,-y);
            graphics2D.scale(SCALE,SCALE);
            //  V set clipping area
            int headerHeight=HEADER_HEIGHT;
                graphics2D.setClip((int)(pageFormat.getImageableX()/SCALE),
                (int) ((pageFormat.getImageableY()+headerHeight)/SCALE),
                (int) (pageFormat.getImageableWidth()/SCALE),
                (int) ((pageFormat.getImageableHeight()-FOOTER_HEIGHT)/SCALE));
            //  VI set pageStart on editorPane
            if (pageIndex > currentPage) {
                currentPage = pageIndex;
                pageStartY += pageEndY;
                pageEndY = graphics2D.getClipBounds().getHeight();
                pageCountInPageSet++;
            //  VII
            graphics2D.translate(graphics2D.getClipBounds().getX(),
            graphics2D.getClipBounds().getY());
            //  VIII prepare clipping area
            Rectangle allocation = new Rectangle(0,
            (int) -pageStartY,
            (int) (editorPane.getMinimumSize().getWidth()),
            (int) (editorPane.getPreferredSize().getHeight()));
            View rootView=editorPane.getUI().getRootView(editorPane);
            if (printView(graphics2D,allocation,rootView)) {//page exists          
                System.out.println("page exists"+pageCountInPageSet);
                return Printable.PAGE_EXISTS;
            else {// page does not exist
                System.out.println("resetting page parameters");
                pageStartY = 0;
                pageEndY = 0;
                currentPage = -1;
                if(!setupNextPage()){///more pages exist TODO:
                    return Printable.NO_SUCH_PAGE;
                else{//no more pages exist
                    //                call next page
                    pageCountInPageSet=0;//reset to first page in pageSet
                    resetGraphics(graphics2D,pageFormat);
                    return print(graphics2D,pageFormat,pageIndex);
    private void resetGraphics(Graphics2D graphics2D,PageFormat pFormat){
            graphics2D.clearRect(0,0,
            (int)(pFormat.getImageableWidth()/SCALE),
            (int)(pFormat.getImageableHeight()/SCALE));
            graphics2D.translate(-graphics2D.getClipBounds().getX(),
            -graphics2D.getClipBounds().getY());
            graphics2D.scale(1/SCALE, 1/SCALE);
        }

Maybe you are looking for

  • Audigy 2 ZS Platinum Pro/Sound card quest

    Hi all, Since the I/O box on the Platinum Pro series has no rca out connection, does anybody know if I can use the lines out on the card at the same time the I/O is plugged into it's Thanks, Dale

  • DVD conversion on Mac

    I use Handbrake to convert my DVDs for use on my iPod but it has a bug with certain audio tracks having anomalies. What other programs do people use? iBook G4; 1.2 GHz, 768 MB   Mac OS X (10.4.2)  

  • CRC Error on installing 10.2.0.1 on Linux

    I've downloaded the 10.2.0.1 full Grid version for Linux and tried to install it on Oracle's Enterprise Linux.... I keep getting a CRC error on disk 2....has anyone else seen this ? Thanks Bernard

  • Where is tutorials

    Do you have tutorial sections about JDeveloper and Java Server Faces like Sun have at http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/index.jsp. I think that JDeveloper is better, but we need more tutorials about how to use

  • Lightroom 5.6 don't see Canon 7d raw files

    I use a Canon 7D. I've got Lightroom 5.6. When I try to import files from the 7D to LR, I can see only movies and JPG files but not the raw file (CR2). What can I do? Thanks