Color renderer not working......

Hello...
I am displaying color in a table column... But instead of showing the color it is printing the color object like java.awt.Color[r=122,g=134,b=167]. What could be wrong....
I am using AbstractTableModel and using fireTableRowsInserted and Updated method to add row to the table. I table row is a string of Objects. Please help... I am running out of time. I have a demo of my work as soon as I am done, so help please . I am adding the code below.
Object[] dataRecord = new Object[5];
dataRecord[0] = (Object)instStateClr;
dataRecord[1] = InstId;
dataRecord[2] = StartTime;
dataRecord[3] = EndTime;
dataRecord[4] = CorrValue;
instactTabModel.updateInstActSumm(dataRecord);
This is a string of Object of which the first location contains a color object.
The color renderer used is as follows...
instActyTable.setDefaultRenderer(Color.class,
new ColorRenderer(true));
The abstract table model is as given below...
* InstActSummTableModel.java
* Created on June 23, 2006, 10:05 AM
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
package action.vector.bam;
import java.awt.Color;
import javax.swing.table.AbstractTableModel;
import java.util.Vector;
* @author serjith
public class InstActSummTableModel extends AbstractTableModel {
protected static int IA_NUM_COLUMNS = 5;
protected static int IA_START_NUM_ROWS = 0;
protected int iIA_nextEmptyRow = 0;
protected int iIAnumRows = 0;
static final public String szInst_Status_Col ="";
static final public String szInst_ID = "Instance ID";
static final public String szInst_Start_Time = "Start Time";
static final public String szInst_End_Time = "End Time";
static final public String szInst_Correlation_Det = "Correlations...";
protected Vector instActdata = null;
/** Creates a new instance of InstActSummTableModel */
public InstActSummTableModel() {
instActdata = new Vector();
public String getColumnName(int column) {
     switch (column) {
     case 0:
     return szInst_Status_Col;
     case 1:
     return szInst_ID;
     case 2:
     return szInst_Start_Time;
     case 3:
     return szInst_End_Time;
case 4:
return szInst_Correlation_Det;
     return "";
public synchronized int getColumnCount() {
return IA_NUM_COLUMNS;
public synchronized int getRowCount() {
if (iIAnumRows < IA_START_NUM_ROWS) {
return IA_START_NUM_ROWS;
} else {
return iIAnumRows;
public synchronized Object getValueAt(int row, int column) {
     try {
Object[] IA_w = (Object[])instActdata.elementAt(row);
switch (column) {
case 0:
return IA_w[0];
case 1:
return IA_w[1];
case 2:
return IA_w[2];
case 3:
return IA_w[3];
case 4:
return IA_w[4];
     } catch (Exception e) {
     return "";
public synchronized void clear() {
     int oldNumRows = iIAnumRows;
iIAnumRows = IA_START_NUM_ROWS;
     instActdata.removeAllElements();
iIA_nextEmptyRow = 0;
     if (oldNumRows > IA_START_NUM_ROWS) {
     fireTableRowsDeleted(IA_START_NUM_ROWS, oldNumRows - 1);
     fireTableRowsUpdated(0, IA_START_NUM_ROWS - 1);
public synchronized void updateInstActSumm(Object[] InstActRecord){
String InstActRec_ID = (String)InstActRecord[1]; //find the Name
Object[] p = null;
int index = -1;
boolean found = false;
     boolean addedRow = false;
int i = 0;
int vecsize = instActdata.size();
if (vecsize == 0){ System.out.println( " The data vector is null");}
else{
System.out.println(" The data vector is not null "+vecsize);
for (int l=0;l<vecsize;l++){
Object[] q = (Object[])instActdata.elementAt(l);
for(int m=0;m<q.length;m++){
System.out.println("Vector Content "+ q[m]+" at position "+l);
System.out.println("numRows "+iIAnumRows);
System.out.println("nextEmptyRow "+iIA_nextEmptyRow);
System.out.println("index "+index);
System.out.println("data.size() "+instActdata.size());
while (!found && (i < iIA_nextEmptyRow)) {
p = (Object[])instActdata.elementAt(i);
System.out.println("value of p[1] -- "+(String)p[1]);
System.out.println("value of PTypeName is -- "+InstActRec_ID);
String pofOne = (String)p[1];
if ( InstActRec_ID.equals(pofOne)==true) {
found = true;
index = i;
} else {
i++;
if (found) { //update old player
     instActdata.setElementAt(InstActRecord, index);
System.out.println("Updating the old player");
} else { //add new player
     if (iIAnumRows <= iIA_nextEmptyRow) {
          //add a row
iIAnumRows++;
          addedRow = true;
index = iIA_nextEmptyRow;
     instActdata.addElement(InstActRecord);
System.out.println("Entering a new player");
iIA_nextEmptyRow++;
     //Notify listeners that the data changed.
     if (addedRow) {
     fireTableRowsInserted(index,index);
     } else {
     fireTableRowsUpdated(index, index);
System.out.println("//////////////////Start in the end//////////////////////////////");
for (int l=1;l<instActdata.size();l++){
Object[] q = (Object[])instActdata.elementAt(l);
for(int m=1;m<q.length;m++){
System.out.println("Vector Content "+ (String)q[m] );
System.out.println("numRows "+iIAnumRows);
System.out.println("nextEmptyRow "+iIA_nextEmptyRow);
System.out.println("index "+index);
System.out.println("data.size() "+instActdata.size());
System.out.println("///////////////////END////////////////////////////////////////////");
Reply Please........

Any sample codes are available...scroll back to the top of the page
look to the left
"Search Forums"
enter:
getColumnClass
click the button
enough reading for a month

Similar Messages

  • Hello! I'm using Aperture with Efex plugins and notice, what when I saving result in plugin and go back to aperture, preview mode is going to grey color and not working until I reboot Aperture. Did you saw this problem?

    Hello! I'm using Aperture with Efex plugins and notice, what when I saving result in plugin and go back to aperture, preview mode is going to grey color and not working until I reboot Aperture. What is intresting - in full screen mode everything works fine. Did you saw this problem?

    It seems there's a workaround here:
    https://discussions.apple.com/thread/5566037?tstart=0

  • Pick color feature not working properly -- how do I reset?

    Pick color feature not working properly -- how do I reset?

    You need to contact Adobe for you billing problem this is a user four not adobe customer support.
    For your Photoshop Problems this user community may be helpful. 
    Supply pertinent information for quicker answers
    The more information you supply about your situation, the better equipped other community members will be to answer. Consider including the following in your question:
    Adobe product and version number
    Operating system and version number
    The full text of any error message(s)
    What you were doing when the problem occurred
    Screenshots of the problem
    Computer hardware, such as CPU; GPU; amount of RAM; etc.

  • "Select Color Range" not working. "Warning: No pixels were selected" returned when attempting to use. Using Photoshop CS6 on a Mac running OS X Yosemite

    "Select Color Range" not working. "Warning: No pixels were selected" returned when attempting to use. Using Photoshop CS6 on a Mac running OS X Yosemite

    Here are three screenshots in succession from trying to perform the color selection:
    Dropbox - Screenshot 2015-02-12 14.57.40.png
    Dropbox - Screenshot 2015-02-12 15.00.14(2).png
    Dropbox - Screenshot 2015-02-12 15.01.00.png

  • Final Cut 6 and Color does not work

    Hello,
    I bought FInal Cut Pro Studio 2 and i receive the suite today and instal only apps ( no contents and loops )without problem
    Tried to open FCP6 and Color but not working.
    i launch FCP 6 or Color,2 jumps on dock and then quit.
    can be memory problem.( i have 768RAM on my imac G5 64VRAM)
    any pacth to resolv this problem?
    ps* SountrackPro 2,DVDStudio Pro,Motion3,LiveType,CinemaTools and Compressor woks fine in the same computer
    Computer configuration
    IMac G5 1.6 with 64VRAM and 768RAM
    thx in advance

    Ok,forgot Color,but and about final cut 6 ? why does not work?
    max resolution 1440x900.
    i was looking the systen requirements on fcp page
    Minimum Requirements to Install All Final Cut Studio Applications
    Final Cut Pro 6
    Macintosh 1.25GHz or faster PowerPC G4, PowerPC G5 = OK
    1GB of RAM = NO,my iMac have 768RAM
    1024-by-768 resolution or higher OK
    Mac OS X v10.4.9 or later OK
    QuickTime 7.1.6 or later OK
    A DVD drive for installation OK
    Can i deduce that problem is because i don't have RAM enought?
    THX

  • Color Shading Map Renderer not working

    Hi,
    Has anybody got the Color Shading rendering working in NW2004s? And if so how?
    I am able to display Bars using note 1016072, but the Color Shading does not work.
    We are on SP11, backend and frontend.
    Thanks,
    József.

    The problem was caused by an old IGS version and got solved by installing a new IGS patch!

  • Secondary color correction not working in Premiere CC

    Greetings,
    I'm unable to build secondary color correction masks in Three Way Color Corrector, RGB Curves etc in the current version of Premiere CC.
    In any of these plugins, when I check "show mask" I get the usual white slate filling the frame. But when I use the color picker to make a selection the whole frame stays white. It appears that I'm making selections but it's not building the mask for some reason. When making an extreme color change I can see that the mask is not building as it affects the whole frame.
    This started after upgrading to CC. I've recently updated to the most up to date version (yesterday) and am still having the same problem.
    Premiere CC 2014.1 Release
    8.1.0 (81) Build
    Macbook Pro Retina, 15" Late 2013
    2Gh Intel Core i7
    8Gb
    Intel Iris Pro 1536Mb
    Yosemite Version 10.10
    *note-my Colleague is not having this problem, he's working on the same OS and same CC build but he has an Imac. So I'm guessing this problem is unique to my hardware config.
    Anybody else have this problem or know of a fix?

    I have the same Problem new MAC OS Premier Pro CC or Premier Pro CS6 both have an issue with the Title Tool. If you open the title tool and try to make color changes or change size of the font it sticks at the default color and default font. SOmetimes the title tool will work and then when I exit it's back to the default first type location, default font and default color. Sometimes it will not even let me exit the Title Tool.
    Please help I have Projects I'm working on Deadlines and I pay a monthly Fee for Software that works and it's not working.
    Model Name:          Mac Pro
      Model Identifier:          MacPro5,1
      Processor Name:          6-Core Intel Xeon
      Processor Speed:          2.4 GHz
      Number of Processors:          2
      Total Number of Cores:          12
      L2 Cache (per Core):          256 KB
      L3 Cache (per Processor):          12 MB
      Memory:          16 GB
    Software  OS X 10.9 (13A603)
    Graphics  ATI Radeon HD 5770 1024 MB

  • IGrid - SAP MII 12.1.8 SP 05 (build 36) - rendering not working properly.

    Hi,
    In the 12.1.8 SP 05, when the iGrid cell values set through the java script, the rendering part is not working.
    For example,
    The data set returned by iCommand has 25 rows.
    Java script sets the values in the iGrid from each row.
    The application was working well with 12.1.8 SP02. The same application is not working properly now.
    the error from the java script show this as java.lang.NullPointerException.
    For the same set of data, this error is occurring sometimes at the third row, sometimes in the middle and sometimes in the end.
    The java console is quite consistent. The same error occurs multiple times.
    I have given the error in the end.
    After the grid loaded, the script tries to set the cell values. some time only a single line has values and some time 4 to 5  lines has values for the same data set. The lines are not shown to the user. When he moves away from that page and comes back all the 25 lines are seen, mostly without values.
    Is anyone working with 12.1.8 SP05 patch? The Xacute Query string output size is 64K in the SP02. In SP04 and SP05 this issue is fixed. This needs to be implemented. But in SP 03, IGrid functionality is refactored.
    The SAP notes number: Note 1566572 - MII 12.1 SP08 Patch03 says,
    Re-factored iGrid to improve datatype handling
    Notes number for SP04:  Note 1581779 - MII 12.1 SP08 Patch04
    Notes number for SP05: Note 1586551 - MII 12.1 SP08 Patch05
    If you have upgraded into the latest version of 12.1, are you facing the similar problem?
    The java Console error:
    Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
         at com.sap.xmii.applet.grid.renderers.MultiLineRenderer.setValue(MultiLineRenderer.java:60)
         at com.sap.lhcommon.gui.table.TableMultiLineCellRenderer.getTableCellRendererComponent(TableMultiLineCellRenderer.java:129)
         at javax.swing.JTable.prepareRenderer(Unknown Source)
         at com.sap.lhcommon.gui.table.BaseTable.prepareRenderer(BaseTable.java:560)
         at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
         at javax.swing.plaf.ComponentUI.update(Unknown Source)
         at javax.swing.JComponent.paintComponent(Unknown Source)
         at com.sap.xmii.applet.grid.base.types.BaseGrid.paintComponent(BaseGrid.java:947)
         at javax.swing.JComponent.paint(Unknown Source)
         at javax.swing.JComponent.paintChildren(Unknown Source)
         at javax.swing.JComponent.paint(Unknown Source)
         at javax.swing.JViewport.paint(Unknown Source)
         at javax.swing.JComponent.paintChildren(Unknown Source)
         at javax.swing.JComponent.paint(Unknown Source)
         at javax.swing.JComponent.paintToOffscreen(Unknown Source)
         at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
         at javax.swing.RepaintManager.paint(Unknown Source)
         at javax.swing.JComponent._paintImmediately(Unknown Source)
         at javax.swing.JComponent.paintImmediately(Unknown Source)
         at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
         at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
         at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Thanks and Regards,
    Kishore kumar P S

    Hi Jamie,
    SAP has proposed a solution not to check the word wrap in the Grid.
    The iCommand data call was happening with Creation event of iGrid.
    Now changed to FirstUpdateEvent. This works fine.
    Thanks and Regards,
    Kishore kumar P S
    problem resolved
    Edited by: kishore kumar on Jul 12, 2011 3:33 PM

  • Why are my scopes and rendering not working?

    I have trashed preferences and I still can not get rendering to work (background or manually) or the scopes.
    Any ideas?
    Thanks,
    Joel

    Are you still running 10.8, or did you upgrade? What version FCPX?
    Russ

  • Visual editor JSF rendering not working

    Hi,
    I'm trialing the 10.1.0.3EA version of JDeveloper and I can't seem to get the JSF rendering working in the visual editor. I thought that perhaps I'd changed some settings or something so I completely uninstalled and then reinstalled JDeveloper. After the install I created a new application using the default web tech. scope, created default business components from the order and order_items tables in the oe schema, opened the JSF navigation, added a page and tried to drag and drop a read only table onto the page. Instead of the rendering I am getting a hierarchical view of tags with just the tag names, i'm not even getting any of the binding information shown, other than in the property inspector. I'v checked to make sure that the JSP tag libraries in the project settings all have "Execute tags in JSP Visual Editor" checked and in the preferences I have made sure that "Show JSP Tag Names Only" is unchecked. Does this functionality not work by default from the install or am I missing something?
    Any help would be appreciated!
    Thanks,
    Lee Proctor.

    Of course, use the value attribute of the component and set it to EL representing the desired property.

  • Color controls not working correctly

    Why do swatches suddenly not show in the conrol panel? When the object and document are brand new it works, then randomly goes into the stuck mode where if I click on the fill box I get a choice of only no fill or resgistration. I can work around this using the colors panel or color picker, but often the color picker goes haywire too. At that point the file is corrupted and there's no going back. Restarting the program and computer do not help. What's going on?

    As I recall, I had been working with 3 separate images, 2 originally grayscale and 1 RGB, that I had live traced (as above, without placing the image in a new ai file). One of the grayscale images let me use the color picker to change fill color, bu not consistenly, and the other one would let me type in values and changed colors on the picker, but only showed shades of gray in the fill box and in the image. The RGB file wouldn't let me change the fill color using swatches, but I don't remember what I tried with the picker.
    I think I'm going to chalk it all up to my original mistake of not placing the image in a new file, and subsequently trying everything I could think of to work around the original problem.

  • Direct rendering not working after upgrade to Xorg 7.0

    I have aATI radeon 9200 card and although its supposed to be supported in the new xorg, direct rendering doesnt work. I have made the neccesary changes in xorg.conf. I deleted the ati drivers load "dri" and "glx" installed all the needed modules.
    Does xorg 7.0 work with the propritery ATI drivers? My system is generally slow too and not as responsive as before.
    Can some one with a working DRI post their xorg.conf. My PC is a compaq presario.
    thnx

    Did you remove the ATI drivers and install libgl-dri? Without libgl-dri, either you have software GL with libgl-mesa, or some ATI OpenGL lib that runs in fallback mode.

  • Photoshop color field not working in color picker

    My color field is not working properly in my color picker. How do you fix this?
    WRONG (what my color picking is doing) :
    CORRECT (how it should work) :

    The catchall first step in correction is to reset the tool which, in this case, is the Eyedropper.
    With the Eyedropper chosen, right click here:
    If that doesn't solve the problem, a logical next step would be to reset your Preferences.
    To reset Preferences:
    If Photoshop is already open on your screen, close it (Quit). Then hold down Shift+Ctrl+Alt (Win) / Shift+Command+Option (Mac) on your keyboard and start Photoshop.
    A dialog box will pop up asking if you want to delete the existing Preferences file (the "Settings"). Click Yes in the dialog box. The existing Preferences file will be scrapped and a new one will be created.

  • Color Libraries not working anymore

    Hi,
    I was creating an .acb (adobe color book) file to access my company's colors from the color picker's color libraries section and everything was going well. It was all working, I've been using it for some time, and then I decided to change the name of my library in the coding.
    After that the color libraries stopped working. Not only my color library, but the color library function in Photoshop. Now when I try to access the color libraries section from the color picker, it simply closes the color picker. It doesn't give me any error message. Photoshop doesn't crash or anything, it's only that I can't access the color libraries section.
    I tried removing my .acb file from the \Adobe Photoshop CS2\Presets\Color Books folder, but it didn't solve the problem. The color libraries still won't open.
    Anyone knows a solution to this problem. It's kind of urgent since I need that color library file working for a tool I'm developping for my company.
    Would there be someplace in Photoshop that I could reset Photoshop's color libraries to start from scratch and go back to my old version of the .acb file that was working perfectly, before I changed it's name?
    Right now I'm using Photoshop CS2, I should be switching to Photoshop CS3 soon, but I'd like to have a solution to make sure the same problem doesn't happen on CS3.
    Thanks.

    Hi OldBob,
    Thanks for your reply. Actually, I haven't had to try your solutions because for some reason the problem is fixed now. All I did was modify again the code name of my color books to something else and put them back in the color books folder and it got back to life. It still doesn't explain why the problem wasn't fixed when I deleted them from the folder, so I guess if it happens again I'll try your solutions to see if it helps.
    Thanks!

  • SetBackground(Color.WHITE) not working

    I am trying to set background color to white, but it's not working. Can anyone find out the problem?
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.font.FontRenderContext;
    import java.awt.font.LineMetrics;
    import java.awt.font.TextLayout;
    import java.awt.geom.*;
    public class Lab3ex2 {
         * @param args ignored
         public static void main(String[] args) throws IOException {
              // Station[] stations = new Station[100];
              // int n = 0;
              ArrayList<Station> stations = new ArrayList<Station>();
              ArrayList xPos = new ArrayList();
              ArrayList yPos = new ArrayList();
              final String fname = "C://Positions-v2.csv";
              BufferedReader br = new BufferedReader(new FileReader(fname));
              String stationName, item, line;
              line = br.readLine(); // first line skipped
              line = br.readLine(); // 2nd
              while (line != null) {
                   StringTokenizer stoke = new StringTokenizer(line, ",");
                   stationName = stoke.nextToken().trim();
                   item = stoke.nextToken();
                   float x = Float.parseFloat(item);
                   item = stoke.nextToken();
                   float y = Float.parseFloat(item);
                   item = stoke.nextToken();
                   String justification = item;
                   // stations[n] = new Station(stationName, x, y);
                   // n++;
                   stations.add(new Station(stationName, x, y, justification));
                   xPos.add(x);
                   yPos.add(y);
                   line = br.readLine(); // line 3,4,...
              for (Station station : stations) {
                   System.out.println(station);
                   //System.out.printf("%20s %6.1f,%6.1f)%n",station.name, station.x, station.y);
              System.out.print("Press enter...");
              System.in.read();
              JFrame f = new JFrame("Lab3ex2");
              f.add(new MyPanel(stations, xPos, yPos));
              f.setSize(500,400);
              f.setVisible(true);
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // to avoid needing ^C
    class Station {
         public String name;
         public float x;
         public float y;
         public String justification;
         public Station(String name, float x, float y, String justification) {
              this.name = name;
              this.x = x;
              this.y = y;
              this.justification = justification;
         public String toString() {
              // todo: format x and y
              return name + " (" + x + "," + y + ")";
    class MyPanel extends JPanel {
         private ArrayList<Station> stations;
         private float xMax, yMax;
         private ArrayList xPos;
         private ArrayList yPos;
         public void paintComponent(Graphics g) {
              Graphics2D g2 = (Graphics2D)g;
              Dimension dim = getSize();
              float xScale, yScale, scale, x, y, radius = 1.0f, diam;
              String justification = null;
              diam = 2.0f*radius;
              Shape s;
              xScale = dim.width/xMax;
              yScale = dim.height/yMax;
              scale = Math.min(xScale, yScale);
              g2.scale(scale, scale);
              g2.setStroke(new BasicStroke(1.0f/scale)); // thin lines
              g2.setFont(new Font("SanSerif", Font.PLAIN, (int)(11.2f/scale))); // always 12 approx
              int total = 0;
              for (Station st : stations) {
                   if(st.name.length()>total)
                        total = st.name.length();
              for (Station st : stations) {
                   x = st.x - radius;
                   y = st.y - radius;
                   justification = st.justification;
                   s = new Ellipse2D.Float(x, y, 2.0f*radius, 2.0f*radius);
                   g2.draw(s);
                   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
                   if(justification.equals("R"))
                        g2.drawString(st.name, (x-st.name.length())-2, (y+diam));
                   else
                        g2.drawString(st.name, (x+diam+radius), (y+diam));
    GeneralPath theShape = new GeneralPath();
         theShape.moveTo((float)(Float)xPos.get(0), (float)(Float)yPos.get(0));
    for(int i=0; i<15; i++)
         theShape.lineTo((float)(Float)xPos.get(i), (float)(Float)yPos.get(i));
    g2.draw(theShape);
    this.setBackground(Color.WHITE);
         public MyPanel(ArrayList<Station> stations, ArrayList xPos, ArrayList yPos) {
              this.stations = stations;
              this.xPos = xPos;
              this.yPos = yPos;
              xMax = -99999.0f;
              yMax = -99999.0f;
              for (Station st : stations) {
                   if (st.x > xMax) xMax = st.x;
                   if (st.y > yMax) yMax = st.y;
    }

    import java.io.*;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.font.FontRenderContext;
    import java.awt.font.LineMetrics;
    import java.awt.font.TextLayout;
    import java.awt.geom.*;
    * Advanced Java Lab 3 ex 2: reading and drawing Met station data
    * @author rallen
    public class Lab3ex2 {
          * @param args
          *            ignored
         public static void main(String[] args) throws IOException {
              // Station[] stations = new Station[100];
              // int n = 0;
              ArrayList<Station> stations = new ArrayList<Station>();
              ArrayList xPos = new ArrayList();
              ArrayList yPos = new ArrayList();
              final String fname = "C://Positions-v2.csv";
              BufferedReader br = new BufferedReader(new FileReader(fname));
              String stationName, item, line;
              line = br.readLine(); // first line skipped
              line = br.readLine(); // 2nd
              while (line != null) {
                   StringTokenizer stoke = new StringTokenizer(line, ",");
                   stationName = stoke.nextToken().trim();
                   item = stoke.nextToken();
                   float x = Float.parseFloat(item);
                   item = stoke.nextToken();
                   float y = Float.parseFloat(item);
                   item = stoke.nextToken();
                   String justification = item;
                   // stations[n] = new Station(stationName, x, y);
                   // n++;
                   stations.add(new Station(stationName, x, y, justification));
                   xPos.add(x);
                   yPos.add(y);
                   line = br.readLine(); // line 3,4,...
              for (Station station : stations) {
                   System.out.println(station);
                   // System.out.printf("%20s %6.1f,%6.1f)%n",station.name, station.x,
                   // station.y);
              System.out.print("Press enter...");
              System.in.read();
              JFrame f = new JFrame("Lab3ex2");
              f.add(new MyPanel(stations, xPos, yPos));
              f.setSize(500, 400);
              f.setVisible(true);
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // to avoid needing ^C
    class Station {
         public String name;
         public float x;
         public float y;
         public String justification;
         public Station(String name, float x, float y, String justification) {
              this.name = name;
              this.x = x;
              this.y = y;
              this.justification = justification;
         public String toString() {
              // todo: format x and y
              return name + " (" + x + "," + y + ")";
    class MyPanel extends JPanel {
         private ArrayList<Station> stations;
         private float xMax, yMax;
         private ArrayList xPos;
         private ArrayList yPos;
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              this.setLayout(new FlowLayout());
              Graphics2D g2 = (Graphics2D) g;
              Dimension dim = getSize();
              float xScale, yScale, scale, x, y, radius = 1.0f, diam;
              String justification = null;
              diam = 2.0f * radius;
              Shape s;
              xScale = dim.width / xMax;
              yScale = dim.height / yMax;
              scale = Math.min(xScale, yScale);
              g2.scale(scale, scale);
              g2.setStroke(new BasicStroke(1.0f / scale)); // thin lines
              g2.setFont(new Font("SanSerif", Font.PLAIN, (int) (11.2f / scale))); // always
                                                                                                        // 12
                                                                                                        // approx
              int total = 0;
              for (Station st : stations) {
                   if (st.name.length() > total)
                        total = st.name.length();
              for (Station st : stations) {
                   x = st.x - radius;
                   y = st.y - radius;
                   justification = st.justification;
                   s = new Ellipse2D.Float(x, y, 2.0f * radius, 2.0f * radius);
                   g2.draw(s);
                   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
                   if (justification.equals("R")) {
                        g2.drawString(st.name, (x - st.name.length()) - 2, (y + diam));
                   } else {
                        g2.drawString(st.name, (x + diam + radius), (y + diam));
              GeneralPath theShape = new GeneralPath();
              theShape.moveTo((float) (Float) xPos.get(0), (float) (Float) yPos
                        .get(0));
              for (int i = 0; i < 15; i++) {
                   theShape.lineTo((float) (Float) xPos.get(i), (float) (Float) yPos
                             .get(i));
              g2.draw(theShape);
              setOpaque(true);
         public MyPanel(ArrayList<Station> stations, ArrayList xPos, ArrayList yPos) {
              this.stations = stations;
              this.xPos = xPos;
              this.yPos = yPos;
              xMax = -99999.0f;
              yMax = -99999.0f;
              for (Station st : stations) {
                   if (st.x > xMax)
                        xMax = st.x;
                   if (st.y > yMax)
                        yMax = st.y;
              this.setBackground(Color.WHITE);
              this.setVisible(true);
    }Edited by: swapnil_raverkar on Sep 21, 2008 5:10 AM

Maybe you are looking for

  • How to compare 2 dates in SQL Server 2000 DB using Java?

    How do you compare 2 dates in SQL Server 2000 DB using Java? Let's say we have two fields: Date Reported and Target Finish Date. Date Reported is 09-10-2004 09:55:55: PM Target Finish Date is 09-12-2004 11:59:59: PM What i want to happen is i want to

  • My macbook pro I7 does not have 802.11n compability

    Hello you all. My macbok pro I7 was bought since 8 months ago and is this: Macbook Pro Information   Nombre del modelo: MacBook Pro   Identificador del modelo: MacBookPro9,2   Nombre del procesador: Intel Core i7   Velocidad del procesador: 2,9 GHz  

  • HT4479 biling information

    I don't have bank account !!!!!! Always the Messege apear to me (( This Apple ID has not yet been used in the iTunes store )) But i dont have bank account !!!!! i need to download free Apps from applestore

  • Burn keynote prensentation onto DVD to play on DVD player

    I have created a slide show in Keynote and I want to burn it onto a DVD to play in a DVD player. I exported to quicktime and created a version there. It has a .m4v extension when completed. Then I burned that to the DVD disc. It won't play in a DVD p

  • Vim key mapping question, Xterm question

    Since i type Dvorak, I wish to have a mapping to allow me to move between windows in vim with Ctrl-W d/h/t/n instead of Ctrl-W h/j/k/l  . I have looked in the vim help files, and online, but can't find how to do it. I tried eg. :noremap <c-w>d<c-w> <