Draw a shape and add it to cells in a JTabel. Help Please

Hi all
I have written some code that draws a shape using Graphics2D.
What I am after being able to do is create this shape then place it in a cell of a JTable.
One Other thing is I need to create different color shapes for each row in the table.
is this posable ??
Any help would be appreciated
Craig
import java.awt.*;
import javax.swing.*;
public class RectangleDemo2D extends JFrame {
  private Color color1 = new Color(255, 3, 3);// Color
  private Color color1a = new Color(255, 3, 3, 155); // Color with Alpha
  private Color color2 = new Color(255, 255, 255, 155); //Color White
  int x = 150;
  int y = 150;
  int w = 12;
  int h = 12;
  int arc = 6;
  GradientPaint gradient = new GradientPaint(5, 0, color1, 5, 90, color2, false);
  final static BasicStroke stroke = new BasicStroke(1.0f);
  public void paint( Graphics   g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setPaint(gradient);
    g2.fillRoundRect(x, y, w, h, arc, arc);
    g2.setPaint(color1a);
    g2.setStroke(stroke);
    g2.drawRoundRect(x, y, w, h, arc, arc);
    //ImageIcon ico = new ImageIcon("check.png"); // This adds a check image
   // g2.drawImage(ico.getImage(), x, y - 3, this);
  public static void main(String s[]) {
    RectangleDemo2D demo = new RectangleDemo2D();
    demo.setBackground(Color.white);
    demo.pack();
    demo.setSize(new Dimension(300, 300));
    demo.show();
}

Hi,
You can check out a similar thread where the poster has opted to use imageicons instead of shapes. That thread is here.
http://forums.java.net/jive/thread.jspa?threadID=15074&tstart=0.
As for creating different color shapes for different cells of the jtable, it is definitely possible once you have a custom renderer for your jtable. Just read up on how to create custom table cell renderer.
cheers,
vidyut
http://www.bonanzasoft.com

Similar Messages

  • Can you draw a shape and add it to an application?

    Hi,
    I am totally new to Flex and Flash, action script and all
    (started Wednesday). I am not sure what I'm doing wrong here, if
    anyone could help me Id really appreciate it.
    var max:Shape=new Shape();
    max.graphics.beginFill(0x000000);
    max.graphics.lineStyle(1, 0x000000);
    max.graphics.drawRect(0, 0, 100, 10);
    max.graphics.endFill();
    stats.addChild(max);
    Now stats is a canvas which is a child of my application
    object. The application object is the root of it all.
    I also tried using the "Rectangle" class but that did not
    work either.
    Thanks to anyone who can point me in the right direction
    :)

    Thanks, ill try that next time i need to use a shape.
    Yesterday i decided to stretch a 1x1 image to make it a rectangle
    :p Worked like a charm.

  • Draw a symbol and add text in UIImageView.

    I want to Draw a symbol and add text in UIImageView. when move it should move together. When it would get opened next time, it should be editable. pls needful for me

    Hi,
    You can check out a similar thread where the poster has opted to use imageicons instead of shapes. That thread is here.
    http://forums.java.net/jive/thread.jspa?threadID=15074&tstart=0.
    As for creating different color shapes for different cells of the jtable, it is definitely possible once you have a custom renderer for your jtable. Just read up on how to create custom table cell renderer.
    cheers,
    vidyut
    http://www.bonanzasoft.com

  • How to draw a shape and have x,y axis

    i have to draw a shape and have x.y axis i want use java but i have no ideas could you help me ?thank you !

    i have to draw a shape and have x.y axis i want use java but i have no ideas could you help me ?thank you !

  • I would like to find a program to draw lines, shapes and words for my iMac.

    If anyone can help me find a program or App for my iMac that lets me draw lines, shapes and letters.
         Thank You
         Sandy

    http://www.sketchup.com/
    Try this it is a free download and it is a great program. I almost feel guilty not paying anything:)

  • Hi I'm a total novice, as you will see. But Iam trying to use template of an employee schedule but when I try to add extra columns it does not add the preset formula with it, so it works out total hours and total pay?   If any one can help please.

    Hi I'm a total novice, as you will see. But Iam trying to use template of an employee schedule but when I try to add extra columns it does not add the preset formula with it, so it works out total hours and total pay?   If any one can help please before I throw it through the window!

    Grum12 wrote:
    Hi I'm a total novice, as you will see. But Iam trying to use template of an employee schedule but when I try to add extra columns it does not add the preset formula with it, so it works out total hours and total pay?   If any one can help please before I throw it through the window!
    Hi Grum,
    If the formulas aren't filling to the new column, you must have changed something in the template since you first opened it. Numbers is rather fussy about filling row content in columns as they are added. Only rows with the same expression in every Body Column will fill when a column is added. Just as an experiment, start a new Employee Schedule document from the Template Chooser and then add a column by clicking the Add Column handle in the upper right corner of the table. If that works, as it should, then think about what might have changed in your working document to disconnect that feature. Maybe we can figure it out together.
    Jerry

  • I have trouble syncing my exchange calendar and contacts on my mac. Can anyone help please?

    I have trouble syncing my exchange calendar and contacts on my mac. They will initially load up but will not sync back and forth and stay up to date. Can anyone help please?

    I forgot to add my iPhone and iPad work seamlessly with these two topics but my iMac and my Macbook Air don't.

  • Hi, problem occurs when I'm clicking a button or a new url on the current site. For instance, when i clicked that "Ask This" button on this web site, It redirects me to the default homepage. I cant go back and I'm losing the previous web site HELP PLEASE!

    Hi, problem occurs when I'm clicking a button or a new url on the current site. For instance, when i clicked that "Ask This" button on this web site, It redirects me to the default homepage. I cant go back and I'm losing the previous web site HELP PLEASE!

    Try the Firefox SafeMode. <br />
    ''A troubleshooting mode, which disables most Add-ons.'' <br />
    ''(If you're not using it, switch to the Default Theme.)''
    # You can open the Firefox 4.0 SafeMode by holding the '''Shft''' key when you use the Firefox desktop or Start menu shortcut.
    # Or use the Help menu item, click on '''Restart with Add-ons Disabled...''' while Firefox is running. <br />
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before using the Firefox shortcut (without the Shft key) to open it again.''
    If it is good in the Firefox SafeMode, your problem is probably caused by an extension, and you need to figure out which one. <br />
    http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes

  • My Mac Book Pro was really slow at everything and would kick me out of my photos every time i got on them. now it won't even allow me to log on. i put my password in and the screen will flash white and go back to the login page. HELP please...

    My Mac Book Pro was really slow at everything and would kick me out of my photos every time i got on them. now it won't even allow me to log on. i put my password in and the screen will flash white and go back to the login page. HELP please...

    There is nothing wrong with your Dell, it will work fine with any MacbookPro. I have been using Dell displays for over 12 years with many different Mac models. I have two 21" Ultra Sharp displays working side by side to design a Keynote presentation right now.
    The issue your having is with the way Keynote  takes control of the video output to both displays, it sends the presentation signal to one and the presenter display to the other, this is set up in;
    Keynote preferences > Presenter display.
    If you want to show a wesite or another app on  either display,  use application switcher:
    press the the  command key on the keyboard, then the tab key; a row of applications will show what applications are running, choose which one you want to show. Use command  > tab to return to Keynote.

  • I accientally synced my iPhone to 2 different computers. Now my older apps are on one computer and new apps are on another.  Every time I try to sync all apps on one computer it takes the other apps of and just syncs what is on that computer - Help please

    I accientally synced my iPhone to 2 different computers. Now my older apps are on one computer and new apps are on another.  Every time I try to sync all apps on one computer it takes the other apps of and just syncs what is on that computer - Help please
    I cannot for the life of me figure this out.

    What you need to do is connect your phone to iTunes but do not click sync.  Go to File at the top and click transfer purchases from phone, that'll put all your apps into iTunes.  When it's done transferring, locate your phone on the sidebar and click it.  Then find the apps option above the picture of your iphone, you can select which apps you want or don't want on your phone.  After selecting your apps then you can sync.  Once you do this you should never have your problem anymore.

  • I just updated my Iphone 3G and now it won´t work anymore. It wouldn´t even boot. It was just working for 3 sek. after the installation and now it shut itself down. Any help, please?

    I just updated my Iphone 3G and now it won´t work anymore. It wouldn´t even boot. It was just working for 3 sek. after the installation and now it shut itself down. Any help, please? Thankyou

    I suspect you have a 2G iPod. Those can only go to iOS 4.2.1.
    Identifying iPod models
    iPod touch (3rd generation)
    iPod touch (3rd generation) features a 3.5-inch (diagonal) widescreen multi-touch display and 32 GB or 64 GB flash drive. You can browse the web with Safari and watch YouTube videos with Wi-Fi. You can also search, preview, and buy songs from the iTunes Wi-Fi Music Store on iPod touch.
    The iPod touch (3rd generation) can be distinguished from iPod touch (2nd generation) by looking at the back of the device. In the text below the engraving, look for the model number. iPod touch (2nd generation) is model A1288, and iPod touch (3rd generation) is model A1318.
    You also said: "It also will not let me download any music onto it." What happens when you try to sync music to the iPod?

  • I buy extension from adobe online, i installed it correctly but then the extension menu was greyed out and i can't click it. Some help please.

    I buy extension from adobe online, i installed it correctly but then the extension menu was greyed out and i can't click it. Some help please.

    hello ptbruce, you probably only selected to open (not save) the video which will download it into windows temporary folder where it gets deleted again after it has been used. <br>you could try to right-click the entry in the firefox download manager and copy the link of the source file and try if you can download it through this url again. otherwise you'll have to contact the vendor of the video to find a solution...

  • My iPhone 4s was playing music now won't on my sony dream machine how do I fix. "This device is not supported by this I-phone".  I have turned  off phone unplugged sony and did the pin reset on bottom.     Help please I need my tunes

    My iPhone 4s was playing music now won't on my sony dream machine how do I fix. "This device is not supported by this I-phone".  I have turned  off phone unplugged sony and did the pin reset on bottom.     Help please I need my tunes

    Try plugging it up to your computer and launching iTunes and either resetting it to factory settings or resetting to last sync. Hopefully it just noticing it's plugged up to iTunes will fix it. This happened to my friend once and all she had to do was plug it into her computer and that fixed it.

  • Hi, I was wondering if someone could help me, I recently restored my itouch 4th Gen and was then told to upgrade to itunes 10.6 now everytime I try and install itunes I get the following message, help please!

    Hi, I was wondering if someone could help me, I recently restored my itouch 4th Gen and was then told to upgrade to itunes 10.6 now everytime I try and install itunes I get the following message, help please!
    Error writing to file: C:\Program\Files\iTunes.Resources\de.Iproj\SortPrefixes.plist.   Verify that you have access to that directory.

    Error writing to file: C:\Program\Files\iTunes.Resources\de.Iproj\SortPrefixes.plist.   Verify that you have access to that directory.
    That one's consistent with disk/file damage. The first thing I'd try with that is running a disk check (chkdsk) over your C drive.
    Vista instructions in the following document: Check your hard disk for errors
    Select both Automatically fix file system errors and Scan for and attempt recovery of bad sectors, or use chkdsk /r (depending on which way you decide to go about doing this). You'll almost certainly have to schedule the chkdsk to run on startup. The scan should take quite a while ... if it quits after a few minutes or seconds, something's interfering with the scan.
    Does the chkdsk find/repair any damage? If so, can you get an install to go through properly afterwards?

  • Frustratingly, since I upgraded to Yosemite 10.10, I too am having the worst problems with WiFi dropping out. I've never had this problem before on my iMac 27-inch mid 2011 model. Turning WiFi off and then back on again sometimes works. Help please.

    Frustratingly, since I upgraded to Yosemite 10.10, I too am having the worst problems with WiFi dropping out. I've never had this problem before on my iMac 27-inch mid 2011 model. Turning WiFi off and then back on again sometimes works. Help please. I've already tried a lot of your suggested fixes, but without success. Why hasn't Apple Fixed this?

    Please test after taking each of the following steps that you haven't already tried. Stop when the problem is resolved. Back up all data before making any changes.
    Step 1
    Take the applicable steps in this support article. The Wireless Diagnostics program generates a large file of information about your system, which would be used by Apple Engineering in case of a support incident. Don't post the contents here.
    Step 2
    Disconnect all USB 3 devices. If you don't know which are USB 3, disconnect all USB devices except keyboard and mouse.
    Step 3
    If you're not using a wireless keyboard or trackpad, disable Bluetooth by selecting Turn Bluetooth Off from the menu with the Bluetooth icon. If you don't have that menu, open the Bluetooth preference pane in System Preferences and check the box marked Show Bluetooth in menu bar. Test. If you find that Wi-Fi works better with Bluetooth disabled, you should use the 5 GHz Wi-Fi band. Your router may not support it; in that case, you need a new router.
    Step 4
    Open the Energy Saver pane in System Preferences and unlock the settings, if necessary. Select the Power Adapter  tab, if there is one. Uncheck the box marked
              Wake for Wi-Fi network access
    if it's checked.
    Step 5
    Open the Network pane in System Preferences and make a note of your settings in the Wi-Fi service. It may be helpful to take screenshots of the various tabs in the preference pane. If the preference pane is locked, unlock it by clicking the padlock icon and entering your administrator password. Delete Wi-Fi from the service list on the left by selecting it and clicking the minus-sign button at the bottom. Then recreate the service by clicking the plus-sign button and following the prompts.
    Step 6
    In the Wi-Fi settings, select
              Advanced... ▹ TCP/IP ▹ Configure IPv6: Link-local
    Click OK and then Apply.
    Step 7
    Reset the System Management Controller.
    Step 8
    Reset the PRAM.
    Step 9
    Launch the Keychain Access application. Search for and delete all AirPort network password items that refer to the network. Make a note of the password first.
    Step 10
    Make a "Genius" appointment at an Apple Store, or go to another authorized service center.

Maybe you are looking for

  • Try to install iTunes on Vista 64 bit on a clean install but it refuses to install

    I download the 64 bit version for install on my PC, but during install i noticed it was being installed to Program files (x86) which confused me. so I changed it to Program files in the setup preferences and proceeded to install. It gets half way thr

  • IPad Pop3 email deleting from mail server even though set to NEVER

    Hello. We are experiencing a most strange behaviour with our e-mail.  We use a web host and access e-mail through POP3. Two of our users are experiencing similar problems, and this is how their lives are setup: 1) Outlook 2010, set to remove e-mail f

  • How do I change the cellular data carrier on my ipad?

    When purchasing my iPad I signed up for Verizon to be the wireless carrier and I would like to change to AT&T.  How can I make the change?

  • Connect by prior query

    Issue with the below query. The query is not getting filtered for the condition hier_typ_c in('BS') with the connect by prior query. query is fetching all the hier_type_c in the table like 'BS', 'CO', 'EC' etc.... Just wondering how do i restrict the

  • Difference between values in 2 rows in SQL query

    I have to find the difference between inventory onhand in the same store in week1 and week2. I tried to do it in one "select" query something like : SELECT store_id, ( suppose to be function that calculates difference) FROM my_table WHERE week=week1