JTable fails to close a color chooser Editor dialog box

The JTable oracle tutorial shows an example of an editor to pick a color:
http://download.Oracle.com/javase/tutorial/uiswing/components/table.HTML#editor
In this example, clicking on a "Favorite color" cell displays a modal dialog box displays a color picker. To close this dialog box without selecting a color, we can for example click on the Cancel dialog button or press the ESC key.
But I would like to be able to close the dialog box by simply clicking on another table cell. Y at - it a trick to implement this? (Actually I want this feature for a date picker dialog, but the problem should be the same as for the color picker.)

See you soon,.
André

Or use a shortcut menu. Adapted from the example (probably has a lot to improve):

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.table.*;

public class ColorTable {

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

      @Override
      public void run() {
        new ColorTable().makeUI();
      }
    });
  }

  public void makeUI() {
    Color[][] data = {
      {Color.RED, Color.ORANGE},
      {Color.GREEN, Color.YELLOW},
      {Color.BLUE, Color.MAGENTA}
    };
    String[] headings = {"First", "Second"};
    JTable table = new JTable(data, headings);
    table.setDefaultRenderer(Object.class, new ColorTableCellRenderer());
    table.setDefaultEditor(Object.class, new ColorTableCellEditor());

    JFrame frame = new JFrame("Color JTable");
    frame.add(new JScrollPane(table));

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(600, 600);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

class ColorTableCellRenderer extends DefaultTableCellRenderer {

  @Override
  public Component getTableCellRendererComponent(JTable table, Object value,
          boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value,
            isSelected, hasFocus, row, column);
    setText(null);
    setBackground((Color) value);
    return this;
  }
}

class ColorTableCellEditor extends AbstractCellEditor implements TableCellEditor,
        ActionListener, ChangeListener {

  private Color value;
  private JButton button = new JButton();
  private JColorChooser colorChooser = new JColorChooser();
  private JPopupMenu popupMenu = new JPopupMenu();
  private JTable table;
  private int row;
  private int column;

  public ColorTableCellEditor() {
    button.setUI(new BasicButtonUI());
    button.addActionListener(this);
    colorChooser.getSelectionModel().addChangeListener(this);
    popupMenu.setLayout(new BorderLayout());
    popupMenu.setPreferredSize(colorChooser.getPreferredSize());
    popupMenu.add(colorChooser);
  }

  @Override
  public void actionPerformed(ActionEvent e) {
    colorChooser.setColor(value);
    Rectangle cellRect = table.getCellRect(row, column, false);
    popupMenu.show(table, cellRect.x, cellRect.y);
  }

  @Override
  public void stateChanged(ChangeEvent e) {
    value = colorChooser.getColor();
    table.setValueAt(value, row, column);
    popupMenu.setVisible(false);
    stopCellEditing();
  }

  @Override
  public Object getCellEditorValue() {
    return value;
  }

  @Override
  public Component getTableCellEditorComponent(JTable table, Object value,
          boolean isSelected, int row, int column) {
    this.table = table;
    this.row = row;
    this.column = column;

    this.value = (Color) value;
    button.setBackground(this.value);
    return button;
  }
}

DB

Tags: Java

Similar Questions

  • Impossible to close or to access the dialog box

    within a Web site "forms", the dialog box is open, but I don't see the buttons "ok/Cancel". nothing happens when I click on the button (cancel or ok) and I cannot close firefox. use "quite the force" to solve the

    Hi imlostinspace.
    Looks like you may need to add a cookie for this site. This article describes how to do this:

    Solve connection problems on Web sites that require a user name and password

    Hope that helps.

  • Changing color of the white dialog box inside in Windows 8

    How can I change the interior color by default dialog boxes in Windows 8? No need to change the brightness or re - calibrate the screen.  I do not want to change the color of the borders comes from Windows.  Already the versions (XP etc) I was able to change the default tabs white for a shade of pink that have helped me manage my dyslexia.  I want to do it on my new laptop and have been unable to negotiate through the options panel to locate the correct function to do this.  Can someone advise?

    Kind regards
    Simon Coningsby

    If you want to change the color of your borders of window or the taskbar, do a right-click on the desktop, go to customize. Choose a custom color and then choose your color, use the color mixer to get the tint and brightness you want.

  • How to remove the Save dialog box before you close the form?

    Hi all

    I've created a form that will open a data connection to a button click.

    I get the error on failure and the code to close my form of app.execMenuItem ("Close");

    but a save dialog box appears before I can close.

    (maybe because I did something on the opening form),

    It is able to remove it? Or simply impossible?

    Best rgds.

    Hmmm,

    What happens if you add?

    Event.Target.Dirty = false;

    app.execMenuItem ("Close");

  • I have a problem with my samsung R60plus. Whenever I am in stop, he fails to close and sometimes it restarts when it didn't close. A blue screen appears

    I have a problem with my samsung R60plus. Whenever I am in stop, he fails to close and sometimes it restarts when it didn't close. A blue screen appers and this are some of the info it shows. Problem signature: problem event name: BlueScreen the system Version: 6.0.6002.2.2.0.768.3 locale ID: 2057 of additional information about the problem: BCCode: 9f BCP1: 00000003 BCP2: 852F46B0 BCP3: 862089E0 BCP4: 85531008 OS Version: 6_0_6002 Service Pack: 2_0 product: 768_1 files that help describe the problem: C:\Windows\Minidump\Mini111211-02.dmp C:\Users\EMMANUEL C\AppData\Local\Temp\WER-36555854-0.sysdata.xml C:\Users\EMMANUEL C\AppData\Local\Temp\WERBC76.tmp.version. How can I fix this annoying problem

    Hello

    ·         You did changes to the computer very recently before that this problem occurred?

    Try the steps in the following methods and check the status of the issue.

    Method 1:

    Blue screen errors can be caused by either a software or hardware problem. This article contains steps that you can take to try to resolve the problems of software only. If you can't solve the problem by following these steps, you may experience a hardware problem. In this case, you must contact your computer manufacturer or a computer hardware technician for help with hardware issues.

    How to fix bluescreen (STOP) errors that cause Windows Vista to shut down or restart unexpectedly

    http://support.Microsoft.com/kb/958233

     

    Method 2:

    Follow the form of measures troubleshooting article and check if that helps.

    "Stop 0x9F" error or "Stop 0xFE" on a Windows Vista-based or Windows 7 computer that uses certain USB AMD EHCI host controllers.

    http://support.Microsoft.com/kb/982091

  • Go back to the old color choose window

    Hi all

    I pressed a wrong button somehow and changed my pallatte color-picking on another that I have not particulaly care for (see images). is it possible to go back to the old color choose pallatte?

    Old Color Picker (what I use):

    Old Color Picker.jpg

    New color picker (that I don't want to use):

    New Color Picker.jpg

    I'm sure there is a button that will allow me to do, but I can't seem to find it.

    Thank you

    Luke

    Go to the part of the A color picker choose on this page.

  • MS "Color dialog box" popping up instead of 'Adobe color picker' inside PES 10.

    For the purposes of this question, I am providing definitions of terms used herein.

    -Toolbox: the 2 columns of tools on the left side of the Editor screen.

    -Color of foreground & background color: the color filled the boxes at the bottom of the Toolbox.

    -Color dialog box: it's the pop-up window which is marked up with the 'color '. It shows 48 squares of different color (6 rows of 8 columns); they are labeled "basic colors: Just below the "basic colors: ' table is another 16 empty squares (2 rows of 8 columns) to be filled with colors to set. There is a "define custom colors > >" button clicked opens a color picker with HSB RGB stacked under the screen of color field. See this link from Microsoft "Color dialog box", http://msdn.microsoft.com/en-us/library/windows/desktop/ms646375(v=vs.85).aspx

    -Adobe Color Picker: The box for interactive dialogue with the screen color field to the left and the HSB RGB numbers stacked on the right side. See this link

    http://www.Google.com/imgres?hl=en & his = X & TBO = d & biw = 1280 & BIH = 574 & TBM = isch & tbnid = tebKhtFUqFIH ZM: & imgrefurl = http://www.pxleyes.com/video-tutorial/photoshop-elements/6376/Using-the-Colo r - Picker.html & docid = SXta3Vhu1fWfPM & imgurl = http://www.pxleyes.com/images/tutorials/video/4a ab56a881273.jpg & w = 200 & h = 200 & ei =-VfFUIWmBMipqQGO8YAw & zoom = 1 & hc = hazard & vpx = 530 & vpy = 143 & hard 595 8 = & hovh = 160 & hovw = 160 & tx = 67 & Ty = 87 & sig = 118317379113194278791 & page = 1 & tbnh = 142 & tbnw = 142 & start = 0 & Pedn = 20 & ved = 1 t: 429, i: 96 r: 3, s: 0

    The problem:

    PES 10, when using the eyedropper tool or by clicking on the foreground color or background color, Microsoft Microsoft "Color dialog box" appears instead of the dialog box "Adobe color picker. It started a month ago. I use Windows 7.

    Help, please. I want the "Adobe Color Picker" to appear (as it was) within 10 of PSE. How can I fix this problem?

    Thank you.

    Edit > Preferences > general, and then choose the Adobe color picker menu it there:

  • How to close a dialog box?

    Hello

    I displays a dialog with a Yes and no

    UiApplication.getUiApplication().invokeAndWait( new Runnable() {
    
        public void run() {
           int response = Dialog.ask( Dialog.D_YES_NO, "Do you want to continue?" );
    
            // waits here for user interaction
    
            if ( response == Dialog.YES ) {
                // do the task         } else {
                // cancel the task         }
           }
       } );
    

    The application must move forward with the task after 5 seconds if the user does not choose an option. I got this by creating a task of the timer as the dialog box is displayed, and when the timer expires I continue with the task.

    The problem is that the dialog box, although that is no longer displayed, still waiting for user interaction. Is there a way to get the dialog box to complete or is there something else I can use that timeout?

    And others who could do the job.  I like this, because it is self-contained.

    I'm not sure that the code is self-explanatory, please ask if something is not clear.

    Note that I have NOT tested, but I'm doing something similar, so I suspect it should work.  If you have any problems, I'll test and repair (if I can).

    UiApplication.getUiApplication().invokeAndWait( new Runnable() {
        public void run() {
           final Dialog d = new Dialog("Do you want to continue?",
                                       new String [] { "Yes", "No" },
                                       new int [] { Dialog.YES, Dialog.NO },
                                       Dialog.YES,
                                       Bitmap.getPredefinedBitmap(Bitmap.QUESTION));
           Thread timerThread = new Thread() {
               public void run() {
                   while ( !d.isDisplayed() ) {
                       try {
                           sleep(1000);
                       } catch (Exception e) {
                       }
                   }
                   // Above might be needed to make sure we won't start 5 sec wait
                   // until the Dialog is actually displayed
                   try {
                       sleep(5000);
                   } catch (Exception e) {
                   }
                   if ( d.isDisplayed() ) {
                       // Dialog has not been automatically dismissed
                       // Automatically select YES
                       d.select(Dialog.YES);
                   }
                }
            };
            timerThread.start();
            d.doModal();
            // Dialog will be forced close after 5 seconds by timerThread
            int response = d.getSelectedValue();
            if ( response == Dialog.YES ) {
                // do the task         } else {
                // cancel the task         }
           }
       }
    );
    
  • Pipette in the curve adjustment dialog box average pixels, so the color balance is watered.

    Hi all.

    When you use the pipette to set the points black and white pixels of an image in the dialog box curve setting, I found that it seems not middle of the neighbouring pixels or provide a way to select a value "monochrome".  Thus, the color balance is still impaired and is thrown way if you happen to choose a noisy pixel (for example).

    I expect that there is an option to set the size of the sampling for the pipette area, but I don't see one.  I have considered making the monochrome image, defining curves, save them as a preset, and then reload the image color and apply the preset (if she does not leave me); but this seems heavy and hokey.  What is the usual procedure to adjust the tone curve of the image without changing its color balance?

    Thanks for any idea.

    When you select an eyedropper in the curves adjustment dialog box, you went to the eyedropper tool.

    You then set the sample in the Options bar.

    In the curves adjustment layer, any pipette also has sample settings in the Options bar.

  • How do you define the background color for a text box

    In older versions, that I was able to set the background color in a text box, I want to do the same in this newer version and I can not find where I would choose this option

    Hi alanb.

    Please type your text in the text box, now in the right pane of comments you will see your text, right click & Select "Properties".

    In the properties box, select the fill color to fill in the color in the text box.

    I would like to know if it works.

    Kind regards

    Nicos

  • can not get the color option in the dialog box print in snow leopard w/epson

    I upgraded to snow leopard and then updated

    my printer epson 595 driver. but when I go to print, the print dialog box print settings has no color option. It is grayed - out any of my old settings or type of paper I use.  called Epson and they had opened something in preview.  I have the color option, they say it's a prob of pshop.  any ideas?

    no color prob.jpg

    Well, for a 'proper' color workflow, when you choose Photoshop to manage colors (and select the correct destination profile) you are supposed to choose without color management in the Epson driver. (which is now indicated by the parameter of color being disabled... I guess) there are a number of sites that go through the steps of printing from Photoshop for an Epson, but I don't know if they have this covered new behavior.

    http://www.gballard.NET/NCA.html

    http://www.russellbrown.com/tips_tech.html

    http://www.computer-darkroom.com/ps12_colour/ps12_1.htm

  • Thunderbird is not save my password even if I continue to check the Save password box. Fails to retrieve mail when I check the box.

    Recently, I've migrated my profile of Thunderbird to a new computer. Everything works great, except that Thunderbird doesn't remember my password for the account. I am the only user on the machine, and I check only one account, so I don't want to set up a master password... I want just the program to remember my password for the e-mail account. I get the question 'Do you want to save your password?', every time I run the program... but if I check the box to do this, mail is not retrieved. (No error message, just nothing happens.) If I get the password without the box, the mail is retrieved. Even with the sending - I wonder for the time of password the first by session I have send a message. If I check the box 'Save password' send fails. If I do not check the box, sending passes.

    This has been a consistent behavior for about a month now. I'm not just randomly in the password incorrectly. It happens that way every time.

    That is what it is? Y at - it a fix for this? I want to just Thunderbird to remember my password.

    Try this:

    Make folders and hidden files visible

    In thunderbird

    • Help > troubleshooting information
    • Click on the view file"" button.

    a new window opens showing profile_name folder.

    • Close Thunderbird now - this is important
    • Scroll down - find and delete this file: key3db
    • Close this window - upper-right X

    Restart Thunderbird.

    At the password prompt, enter the password and select the "Manager password use to remember the password" check box and click OK.

    Note: If you use a product like CCleaner, then it's probably compensation info session and password. In this case, you will need to make an exception for files of thunderbird in CCleaner to stop cleaning Thunderbird.

    Please report on the results.

  • How to make a dialog box for a user to choose a file to disk

    Hello

    Is it possible to make a dialog box for a user of photoshop, choose a txt, process of my javascript file?

    I have a txt file with all the names and locations of the psd files, I want to treat by photoshop. I have e.g. 100 out of a folder with 250 images.

    If anyone has a shot "sample code" how to select a file - I will be happy.

    / T

    Here is an example of selection of a text file...

    var dlg=
    "dialog{text:'Script Interface',bounds:[100,100,500,220],"+
    "testFile:EditText{bounds:[10,40,310,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
    "Browse:Button{bounds:[320,40,390,61] , text:'<<' },"+
    "statictext0:StaticText{bounds:[10,10,240,27] , text:'Please select Text File' ,properties:{scrolling:undefined,multiline:undefined}},"+
    "Process:Button{bounds:[10,80,190,101] , text:'Process' },"+
    "button2:Button{bounds:[210,80,390,101] , text:'Cancel' }};"
    var win = new Window(dlg,'test');
    win.center();
    win.testFile.enabled=false;
    win.Browse.onClick = function() {
     selectedFile = File.openDialog("Please select TEXT file.","TEXT File:*.txt");
      if(selectedFile != null) win.testFile.text =  decodeURI(selectedFile.fsName);
    }
    win.Process.onClick = function() {
     if(win.testFile.text == '') {
      alert("No text file has been selected!");
      return;
      }
     win.close(1);
     selectedFile.execute();
    }
    win.show();
    
  • Even in Safe Mode, minimize, restore and close is missing, even if the functions remain, and a dialog box now appears at the opening of the FF.

    Since I installed the latest update of Firefox, reduce it, restore, and close are missing visually, even if their functions are always present.

    I also started to have one of these dialog boxes asking whether or not I'd like to allow a program to make changes to my PC when I open Firefox.

    I could fix this apparently either by way of turn disable the compatibility mode setting, or by rebooting completely.

    Then, Firefox logo disappeared from the icon for a while, being replaced by the default Windows system image which is displayed under the icon of unspecified files.

    I do not know whether or not the uninstalling and reinstalling Flash Player and restart had something to do with this corrected, but at some point, she is back to normal.

  • I can't upgrade my Macromedia Flash software. The dialog box keeps telling me that I need to close Firefox and Firefox is not open.

    I'm trying to upgrade my software Macromedia Flash and I can't perform the upgrade because the dialog box tells me to close Firefox. I close Firefox and the process keeps telling me that it cannot perform the upgrade until I close Firefox Firefox is closed! Don't know what I can do.

    If you have already downloaded Flash Installer, restart your computer, and then try to run the installer of Flash. then try launching firefox and upgrade to Firefox 11. Does it work? Usually problems like this are caused by a bad extension, so if it works, we can diagnose your extensions.

Maybe you are looking for

  • Nightly 31.0a1 partially relies on a composer?

    Good so let's all start.I'm using Arch Linux and I'm using the latest version of xorg, amd catalyst, Openbox Server (not a) and 31.0a1 every night and just recently I noticed that I couldn't find my downloads menu, among other things, by clicking on

  • hp scanjet 3800 no power

    I write in the right section?  I'm not sure. The site is really complicated and not easy to deal with. I have my scanjet hp model 3800, it used to work until suddenly collapsed for unknown reasons. my attempts: I connect it to a power source (I tried

  • When I rotate a picture it disappears

    Please can someone help? When I rotate a picture in my pictures, it disappears.  It does not appear in the Recycle Bin.  Where is he?  How can I stop what is going on, he only began to disappear photos recently!  can we recover the missing photos?

  • Auto fill in the toolbar

    I need to know how to get the auto-complete in the toolbar on my system or where to go to get it.

  • Brought back to the factory lost Ms one note

    Recently, I came across a player called Q on my computer and it couldn't access the drive, I followed some advice on an online form, nothing will do. One post suggested I back up my computer and bring back the computer as long as the plant. I hesitat