Can't understand how TableCellRenderer is meant to work

I've not done much Swing work and I'm trying to understand how a customer TableCellRenderer is meant to work. I know I've made a stupid mistake here somewhere but I can't find any specific docs on what I'm try to do.
Basically I have a column in my JTable which holds my own Counter object. I want to render the cell so that the current value of the counter is displayed, along with 2 little buttons that allow the user to increment/decrement the counter value.
The code is below, I seem to have 3 problems:
1) One click on the button seems to increment the counter several times (inserting some log statements it seems that the MouseListener is being added several times?)
2) The value on the counter doesn't seem to get refreshed/repainted once the button is clicked, only some time later (e.g. when I click on a different cell in the JTable)
3) The +/- buttons dont "depress" when they are clicked.
Any help much appreciated!
public Component getTableCellRendererComponent(
JTable table, Object lagInput,
boolean isSelected, boolean hasFocus,
int row, int column) {
removeAll();
final Counter counter = (Counter)counter;
final JButton increment = new JButton("+");
increment.setMargin(new Insets(1,1,1,1));
increment.setPreferredSize(new Dimension(15,15));
final JButton decrement = new JButton("-");
decrement.setMargin(new Insets(1,1,1,1));
decrement.setPreferredSize(new Dimension(15,15));
final JTable finalTable = table;
final int finalColumn = column;
table.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e) {
Rectangle panelBounds = finalTable.getTableHeader().getHeaderRect(finalColumn);
Rectangle buttonBounds = increment.getBounds();
buttonBounds.translate(panelBounds.x, panelBounds.y);
if (buttonBounds.contains(e.getX(), e.getY())){
counter.increment();
Rectangle buttonBoundsDec = decrement.getBounds();
buttonBoundsDec.translate(panelBounds.x, panelBounds.y);
if (buttonBoundsDec.contains(e.getX(), e.getY())){
counter.decrement();
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.gridheight = 2;
c.gridx = 0;
c.gridy = 0;
add(counter);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridheight = 1;
c.gridx = 0;
c.gridy = 1;
add(increment);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridheight = 1;
c.gridx = 1;
c.gridy = 1;
add(decrement);
return this;
}

If that's all there is to the Counter class, it seems to me that what you really want is a JTable of JSpinners.import java.awt.Component;
import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
public class SpinnerTable {
   void makeUI() {
      Integer[][] data = new Integer[10][5];
      String[] colNames = new String[data[0].length];
      for (int i = 0; i < data[0].length; i++) {
         colNames[i] = "Column " + i;
         for (int j = 0; j < data.length; j++) {
            data[j] = 0;
JTable table = new JTable(data, colNames) {
@Override
public Class getColumnClass(int column) {
return Integer.class;
table.setDefaultEditor(Integer.class, new TableCellSpinner(table));
table.setDefaultRenderer(Integer.class, new TableCellSpinner(table));
table.setRowHeight(new JSpinner().getPreferredSize().height + table.
getIntercellSpacing().height);
JScrollPane scrollPane = new JScrollPane(table);
JFrame frame = new JFrame("SpinnerRendererTable");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.add(scrollPane);
frame.setVisible(true);
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SpinnerTable().makeUI();
class TableCellSpinner extends AbstractCellEditor
implements TableCellRenderer, TableCellEditor {
JTable table;
JSpinner spinner = new JSpinner();
JTextField editor = ((JSpinner.DefaultEditor) spinner.getEditor()).
getTextField();
TableCellSpinner(JTable table) {
this.table = table;
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
spinner.setValue((Integer) value);
if (isSelected) {
editor.setBackground(table.getSelectionBackground());
} else {
editor.setBackground(table.getBackground());
if (hasFocus) {
spinner.setBorder(BorderFactory.createLineBorder(table.getGridColor()));
} else {
spinner.setBorder(null);
return spinner;
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
spinner.setValue((Integer) value);
spinner.setBorder(BorderFactory.createLineBorder(table.getGridColor()));
return spinner;
public Object getCellEditorValue() {
return spinner.getValue();
}Check that out carefully in case I've missed anything.
db
edit Added the code for the isSelected border
Edited by: Darryl.Burke

Similar Messages

  • Can't understand how this group by clause works

    The Schema is as below: (http://www.psoug.org/reference/rollup.html)
    CREATE TABLE grp_rep (
    person_id NUMBER(3),
    division VARCHAR2(3),
    commission NUMBER(5));
    INSERT INTO grp_rep VALUES (1,'SAM',1000);
    INSERT INTO grp_rep VALUES (2,'EUR',1200);
    INSERT INTO grp_rep VALUES (1,'EUR',1450);
    INSERT INTO grp_rep VALUES (1,'EUR',700);
    INSERT INTO grp_rep VALUES (2,'SEA',1000);
    INSERT INTO grp_rep VALUES (2,'SEA',2000);
    INSERT INTO grp_rep VALUES (1,'EUR',800);
    COMMIT;
    Query1:
    SELECT person_id, division, SUM(commission)
    FROM grp_rep
    GROUP BY person_id, ROLLUP (person_id, division);
    Query2:
    SELECT person_id, division, SUM(commission)
    FROM grp_rep
    GROUP BY division, ROLLUP (person_id, division);
    The results of query1 are okay. It has results from rollup and group by person_id.
    But, in Query2 results of rollup are missing and results of group by division is there.
    Anyone can explain how the group by clause works when there are multiple columns involving CUBE, ROLLUP and simple column names?
    Regards.

    Thank you shoblock!
    but, What i m really looking for is,
    How group by clause works when i add regular column along with RollUp in group by clause?
    I have understood simple group by clause like
    ...group by column1,column2,column3....
    n I also know simple rollup clauses like
    ...group by rollup(column1,column2,column3,...)
    But my Problem is how does this work:
    ...group by column2,rollup(column1,column2,...)
    ...group by column1,rollup(column1,column2,...)
    See below Results:
    Query1:
    SELECT person_id, division, SUM(commission)
    FROM grp_rep
    GROUP BY person_id,ROLLUP ( person_id, division );
    Result:
    PERSON_ID DIVISION SUM(COMMISSION)
         1      EUR      2950
         1     SAM      1000
         2      EUR      1200
         2      SEA      3000
         1           3950
         2           4200
         1           3950
         2           4200
    SELECT person_id, division, SUM(commission)
    FROM grp_rep
    GROUP BY division,ROLLUP ( person_id, division );
    Query2:
    SELECT person_id, division, SUM(commission)
    FROM grp_rep
    GROUP BY division,ROLLUP ( person_id, division );
    Result:
    PERSON_ID DIVISION SUM(COMMISSION)
    1 EUR 2950
    2 EUR 1200
         1 SAM      1000
    2 SEA 3000
    1 EUR 2950
    2 EUR 1200
    1 SAM 1000
    2 SEA 3000
    EUR 4150
    SAM 1000
    SEA 3000
    guys, help me make understand above results!
    Regards.

  • I really can't understand how this recursive works??

    Hi all,
    I have got a recursive function that checks for palendrome string. But it is confusing. I know that a string is palenromme if it is empty or has a char or first char and last one are same and middle is palindromme too.
    but can't understand how this function works.
    class Palindromme
         boolean palindrom(String s)
              if (s.length() <= 1 || s.equals(null) || s=="") //this is the stopping point
                   return true;
              else
              {                    //recursive definition
                   return ( s.charAt(0) == s.charAt(s.length()-1) ) && palindrom(s.substring(1,s.length()-1));
    specially i don't know how palindrom(s.substring(1,s.length()-1)); is working cause it has to be increased for each loop.
    abdul
    PS: actually i don't know how recursion works from Data structure point of view

    Hi,
    ok your palindrome is : "otto"
    return ( s.charAt(0) == s.charAt(s.length()-1) ) && palindrom(s.substring(1,s.length()-1));
                  o                     o                                   tt
    so first part is true                                        
    in the second part palindrom is called again but with the remaining tt
    so second time :
    return ( s.charAt(0) == s.charAt(s.length()-1) ) && palindrom(s.substring(1,s.length()-1));
                   t                     t                                 ""
    Third time:
    if (s.length() <= 1 || s.equals(null) || s=="") //this is the stopping point
    return true;after all for otto the recusion is:
    return ( s.charAt(0) == s.charAt(s.length()-1) ) && s.charAt(1) == s.charAt(s.length()-2) ) && nothing left of otto);
    Phil

  • How much does this cost? & I still can't understand how this work

    How much does this cost? & I still can't understand how this work

    Hello mkopti,
    ePrint is a free feature include on most of our wireless printers that are e-all-in-one enabled. It allows you to register your printer on HP's website http://www.eprintcenter.com and create an account. Once an account has been created you can enable the web services feature, after connecting to a valid network with internet access, which will print off a registration code you can use to add the printer to your account and customize an email address for the printer. This allows you to print to the printer from virtually anywhere simply by sending an email to the printers email address and when it is received it will print.
    Most of these printers are also Airprint enabled meaning you can print locally from the same network on the iPad, iPod, and iPhone (version 4.3.2 and higher) by using the built in "Print" command in the idevices.
    If you have any other questions or need clarification feel free to reply to this post and I will try to answer any questions you have.
    If I have solved your issue, please feel free to provide kudos and make sure you mark this thread as solution provided!
    Although I work for HP, my posts and replies are my own opinion and not those of HP.

  • I can't understand how to edit titles on the spine of books. Could anyone help me? Thanks.

    I can't understand how to edit titles on the spine of books. Could anyone help me? Thanks.

    the trouble is that on the spine of the book the title is cut off and I don't know how avoid it.
    I don't think you can, Fred. Pick a shorter title. And add the additional information by adding a subtitle on your title page. You can always add a second text box, using the "edit layout" panel.
    Regards
    Léonie

  • Things have really changed.  I can't understand how Apple could release the Lion OS as buggy as it is ?  It's like reliving the nightmare of my PC days and the Microsoft crap !  Do I have to wipe the hardrive before reinstalling Snow Leopard ?  Comments..

    Things have really changed.  I can't understand how Apple could release the Lion OS as buggy as it is ?  It's like reliving the nightmare of my PC days and the Microsoft crap !  Do I have to wipe the hardrive before reinstalling Snow Leopard ?  The amazing thing is that when I installed Snow Leopard not a hitch, ever !    My trust in Apple is gone and believe me I will think twice before doing anymore OS upgrades, **** I can go back to the PC for a lot less money.

    Adios baby! Enjoy that PC!

  • My ipad mini is totally drain and after plug it to regain the power its not working anymore.can somebody knows how to make my ipad work again

    my ipad mini is totally drain and after plug it to regain the power its not working anymore.can somebody knows how to make my ipad work again

    Reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

  • Can't understand how Finder handles photos!

    I would like to understand how finder handles photos because I switched from windows recently and can't understand some things.
    First example, renaming lots of photos (without using iPhoto). I already have a automator action for renaming files, but if I have lots of photos with the numbers wrong, I wanted to organize the photos by date created and then rename them and get them in order. The problem is finder renames the files but with some order he chooses, and not the one I wanted. I know this happens because I select all the photos and he decides this way, but how can I do this my way!?
    The second question is kinda related. If I open lots of photos in finder (using command+a and command+o), why do the photos that are open in preview are opened in an order finder chooses, even if I arrange my photos in different orders (kind, name, date, etc)?
    I'm finding handling files in finder a little too much work to do, it was supposed to be a simple thing, just renaming or opening photos, because despite all his many weaknesses, windows worked kinda well with files, like pictures...

    Part of it depends on what criterion you have chosen to arrange the files in the Finder window: Name, Date Modified, Date Created, Size, Kind, Label. If by Name, I think the ones with numbers are ordered before letters.

  • [SOLVED] Can't understand how `install` command works

    Hi there:
    I'm trying to make a PKGBUILD for pgModeler, which comes pre-compiled, so I think what I should do is to move the application directory completely to /opt/pgmodeler and make a symbolic link from /usr/bin to the /opt/pgmodeler/start-pgmodeler.sh script. So, i just wrote this:
    pkgname=pgmodeler
    pkgver=0.4.1
    pkgrel=1
    pkgdesc="An open source tool for modeling PostgreSQL databases"
    arch=('x86_64')
    url="http://pgmodeler.com.br"
    license=('GPL3')
    source=("http://www.pgmodeler.com.br/releases/$pkgname-$pkgver-linux64.tar.gz" "pgmodeler.desktop")
    md5sums=('574887c35bc9e0a1bc65f8d4494200bb' '1f3ebda62e941ea7ea17cfb609cc392e')
    depends=(libpqxx)
    package() {
    install -Dm644 "$srcdir/$pkgname-$pkgver-linux64" "$pkgdir/opt/$pkgname"
    install -Dm644 "$srcdir/$pkgname.desktop" "$pkgdir/usr/share/applications/$pkgname.desktop"
    install -Dm644 "$srcdir/$pkgname-$pkgver-linux64/pgmodeler_logo.png" "$pkgdir/usr/share/pixmaps/$pkgname.png"
    chmod 755 "$pkgdir/opt/$pkgname/start-pgmodeler.sh"
    ln -s "$pkgdir/opt/$pkgname/start-pgmodeler.sh" "$pkgdir/usr/bin/$pkgname"
    But it fails in the first line of the package() function:
    [tae@localhost pgmodeler]$ makepkg -s
    ==> Making package: pgmodeler 0.4.1-1 (Sun Mar 17 23:03:08 CLST 2013)
    ==> Checking runtime dependencies...
    ==> Checking buildtime dependencies...
    ==> Retrieving Sources...
    -> Found pgmodeler-0.4.1-linux64.tar.gz
    -> Found pgmodeler.desktop
    ==> Validating source files with md5sums...
    pgmodeler-0.4.1-linux64.tar.gz ... Passed
    pgmodeler.desktop ... Passed
    ==> Extracting Sources...
    -> Extracting pgmodeler-0.4.1-linux64.tar.gz with bsdtar
    ==> Removing existing pkg/ directory...
    ==> Entering fakeroot environment...
    ==> Starting package()...
    install: omitting directory ‘/home/tae/GitHub/pgmodeler/src/pgmodeler-0.4.1-linux64’
    ==> ERROR: A failure occurred in package().
    Aborting...
    This is my first PKGBUILD and I'm trying to decipher how to make it by looking at this files: https://aur.archlinux.org/packages/dr/dropbox/PKGBUILD and https://aur.archlinux.org/packages/op/opcion/PKGBUILD and I never used the install command before so I'm pretty lost.
    Thanks beforehand.
    Last edited by Tae (2013-03-19 12:44:45)

    Thanks to all. I learned a couple of stuff, but I still have no luck. This is what I've tried:
    I wrote install -d "$pkgdir/opt" in the first line of the package() function before ask, but it didn't make any difference. In fact, I'm not sure what it does (from its man page: treat all arguments as directory names; create all components of the specified directories).
    I modified the function with all your suggestions, and now it looks:
    package() {
    cp -R "$srcdir/$pkgname-$pkgver-linux64" "$pkgdir/opt/$pkgname"
    chmod 644 "$pkgdir/opt/$pkname/"
    chmod 755 "$pkgdir/opt/$pkgname/start-pgmodeler.sh"
    install -Dm644 "$srcdir/$pkgname.desktop" "$pkgdir/usr/share/applications/$pkgname.desktop"
    install -Dm644 "$pkgdir/opt/$pkgname/pgmodeler_logo.png" "$pkgdir/usr/share/pixmaps/$pkgname.png"
    ln -s "/opt/$pkgname/start-pgmodeler.sh" "$pkgdir/usr/bin/$pkgname/"
    but I get:
    $ makepkg -s
    ==> Making package: pgmodeler 0.4.1-1 (lun mar 18 20:33:53 CLST 2013)
    ==> Checking runtime dependencies...
    ==> Checking buildtime dependencies...
    ==> Retrieving Sources...
    -> Found pgmodeler-0.4.1-linux64.tar.gz
    -> Found pgmodeler.desktop
    ==> Validating source files with md5sums...
    pgmodeler-0.4.1-linux64.tar.gz ... Passed
    pgmodeler.desktop ... Passed
    ==> Extracting Sources...
    -> Extracting pgmodeler-0.4.1-linux64.tar.gz with bsdtar
    ==> Removing existing pkg/ directory...
    ==> Entering fakeroot environment...
    ==> Starting package()...
    cp: cannot create directory ‘/home/tae/GitHub/pgModeler/pkg/opt/pgmodeler’: No such file or directory
    ==> ERROR: A failure occurred in package().
    Aborting...
    Here I can't understand why it tries to create /opt/pgmodeler inside the pkg/ directory. For what I found in other PKGBUILDs and from the $pkgdir definition of the PKGBUILD man page (This contains the directory where makepkg bundles the installed package (this directory will become the root directory of your built package)) I though it will be the root directory.
    So I removed all the $pkgdir from the function and now I get this error:
    mkdir: cannot create directory ‘/opt/pgmodeler/’: Permission denied

  • I'm in trouble... I can't understand how to use the tabs...

    I need tu use the tabs in a webpage but I can't find how I must made. The helps don't help me, maybe I don't see in the right place?
    Thanks for the answer.

    Have a look here.

  • Can't understand why my DefaultListCellRenderer doesn't work

    Hello i know that from the subject title it seems that this is the wrong category to post but because i need to load thumbnails in list and i resize them i didn't know where to post sorry if it is the wrong plase and also sorry for my bad english.
    I am making a programm that get's from the user some image paths , then makes thumbnails and then shows the thumbnails with a status and the name of the image. My list has HORIZONTAL_WRAP layout orientation and because i want to show the name the status and the thumbnail in the list i made a DefaultListCellRenderer. The problem is that when i add elements in the list it appears nothing but when i press with the mouse somewhere int the list the listImagesValueChanged is invoked and the data are passed correctly. I made an class named ImageThubInfo to save the name and the thumbnail for eatch image, also i am using a swing worker to create the thubnails and pass them along with all other information in ImageThubInfo and then store all ImageThubInfo objects to a list. When the worker thread is done it tries to add those elements to the list here is my code
    import java.awt.image.BufferedImage;
    import javax.swing.ImageIcon;
    import javax.swing.JOptionPane;
    * ImageThubInfo stores information for each image
    * @author maxsap
    public class ImageThubInfo  {
        public ImageThubInfo() {
        public ImageThubInfo(String status, String name, int width, int height, long size) {
            this(status, name, width, height, size, null);
        public ImageThubInfo(String status, String name, int width, int height, long size,BufferedImage thumbnail) {
            this.status = status;
            setName(name);
            this.width = width;
            this.height = height;
            this.size = size;
            this.thumbnail = thumbnail;
        public void setStatus(String status) {
            this.status = status;
        public String getStatus() {
            return status;
        public void setName(String name) {
            int indexOf = name.indexOf(".");
            this.name = name.substring(0, indexOf);
            JOptionPane.showMessageDialog(null, this.name);
        public String getName() {
            return name;
        public void setWidth(int width) {
            this.width = width;
        public int getWidth() {
            return width;
        public void setHeight(int heigth) {
            this.height = height;
        public int getHeight() {
            return height;
        public void setSize(long size) {
            this.size = size;
        public float getSize() {
            return size;
        public void setThumbnail(ImageIcon BufferedImage) {
            this.thumbnail = thumbnail;
        public BufferedImage getThumbnail() {
            return thumbnail;
        private String status;
        private String name;
        private int width;
        private int height;
        private long size;
        private BufferedImage thumbnail;
    }this is my DefaultListCellRenderer class
    import java.awt.Component;
    import java.awt.image.BufferedImage;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.ImageIcon;
    import javax.swing.JList;
    * @author maxsap
    public class ImageThubInfoRenderer extends DefaultListCellRenderer {
        public ImageThubInfoRenderer(){}
          @Override
        public Component getListCellRendererComponent(JList list,
                Object value,
                int index,
                boolean isSelected,
                boolean cellHasFocus) {
             super.getListCellRendererComponent(list,value,index,isSelected,
                                                                cellHasFocus);
            ImageThubInfo info = (ImageThubInfo) value;
            String name = info.getName();
            String state = info.getStatus();
            BufferedImage thumbnail = (BufferedImage)info.getThumbnail();
            setIcon(new ImageIcon(thumbnail));
            setText(name+" Current State: "+state);
            if (isSelected) {
                setBackground(list.getSelectionBackground());
                setForeground(list.getSelectionForeground());
            } else {
                setBackground(list.getBackground());
                setForeground(list.getForeground());
            return this;
    }and this is my swing worker class
    public class ThumbLoader extends SwingWorker<List<ImageThubInfo>, BufferedImage> {
          private DefaultListModel model;
          private int total;
          private File [] files;
          private List<ImageThubInfo> imageList;
          protected ThumbLoader(DefaultListModel model,File []files){
                this.model = model;
                this.files= files;
          @Override
          protected List<ImageThubInfo> doInBackground() throws Exception {
                imageList = new LinkedList<ImageThubInfo>();
                 for (int i = 0; i < files.length; i++) {
                    ImageIcon icon;
                    icon = createImageIcon(files.toString());
    if(icon != null){
    ImageIcon thumbnailIcon = new ImageIcon(getScaledImage(icon.getImage(), 100, 100,files[i]));
    return imageList;
    protected ImageIcon createImageIcon(String path) {
    if (path != null) {
    return new ImageIcon(path);
    } else {
    System.err.println("Couldn't find file: " + path);
    return null;
    private Image getScaledImage(Image srcImg, int w, int h, File file){
    BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = resizedImg.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2.drawImage(srcImg, 0, 0, w, h, null);
    ImageThubInfo tubInfo = new ImageThubInfo("Waiting",file.getName(),srcImg.getHeight(null),srcImg.getHeight(null),300,resizedImg);
    imageList.add(tubInfo);
    JOptionPane.showMessageDialog(null, new ImageIcon(resizedImg));
    g2.dispose();
    return resizedImg;
    }protected void done() {
    setProgress(100);
    try {
    //JOptionPane.showMessageDialog(null, imageList.size());
    List<ImageThubInfo> imageList = this.get();
    for(int i=0; i< imageList.size(); i++){
    JOptionPane.showMessageDialog(null, new ImageIcon(imageList.get(i).getThumbnail()));
    model.addElement(imageList.get(i));
    } catch (InterruptedException ex) {
    Logger.getLogger(ThumbLoader.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ExecutionException ex) {
    Logger.getLogger(ThumbLoader.class.getName()).log(Level.SEVERE, null, ex);
    JOptionPane.showMessageDialog(null, "DONE");
    }}can anyone tell me what i am doing wrong???? please help because i really can't understand what i am doing wrong.
    thenks in advance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Works okay now. Many changes to ThumbLoader:
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.util.concurrent.*;
    import java.util.logging.*;
    import java.util.List;
    import java.util.LinkedList;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.*;
    public class ThumbLoader extends SwingWorker<List<ImageThubInfo>, Void> {
        private DefaultListModel model;
        private int total;
        private File[] files;
        private List<ImageThubInfo> imageList;
        protected ThumbLoader(DefaultListModel model, File[] files){
            this.model = model;
            this.files = files;
        @Override
        protected List<ImageThubInfo> doInBackground() throws Exception {
            imageList = new LinkedList<ImageThubInfo>();
            for (int i = 0; i < files.length; i++) {
                BufferedImage image = null;
                try {
                    image = javax.imageio.ImageIO.read(files);
    } catch(IOException e) {
    System.out.println("read error for " + files[i].getPath() +
    ": " + e.getMessage());
    if(image != null){
    BufferedImage scaled = getScaledImage(image, 100, 100);
    ImageThubInfo tubInfo = new ImageThubInfo("Waiting",
    files[i].getName(),
    image.getHeight(),
    image.getHeight(),
    300, scaled);
    imageList.add(tubInfo);
    return imageList;
    private BufferedImage getScaledImage(BufferedImage srcImg, int w, int h){
    BufferedImage resizedImg = new BufferedImage(w, h,
    BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = resizedImg.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.drawImage(srcImg, 0, 0, w, h, null);
    g2.dispose();
    // JOptionPane.showMessageDialog(null, new ImageIcon(resizedImg));
    return resizedImg;
    protected void done() {
    setProgress(100);
    try {
    //JOptionPane.showMessageDialog(null, imageList.size());
    // List<ImageThubInfo> imageList = this.get();
    imageList = get();
    for(int i=0; i< imageList.size(); i++){
    // JOptionPane.showMessageDialog(null, new ImageIcon(
    // imageList.get(i).getThumbnail()));
    model.addElement(imageList.get(i));
    } catch (InterruptedException ex) {
    // Logger.getLogger(ThumbLoader.class.getName()).log(Level.SEVERE,
    // null, ex);
    System.out.println("InterruptedException: " + ex.getMessage());
    } catch (ExecutionException ex) {
    // Logger.getLogger(ThumbLoader.class.getName()).log(Level.SEVERE,
    // null, ex);
    System.out.println("ExecutionException: " + ex.getMessage());
    // JOptionPane.showMessageDialog(null, "DONE");
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    public class Test {
        private JScrollPane getContent() {
            File[] files = getFiles();
            DefaultListModel model = new DefaultListModel();
            JList list = new JList(model);
            list.setCellRenderer(new ImageThubInfoRenderer());
            SwingWorker worker = new ThumbLoader(model, files);
            worker.execute();
            return new JScrollPane(list);
        private File[] getFiles() {
            String prefix = "images/geek/geek";
            String[] ids = { "-c---", "--g--", "---h-", "----t" };
            String ext = ".gif";
            File[] files = new File[ids.length];
            for(int i = 0; i < ids.length; i++) {
                String path = prefix + ids[i] + ext;
                URL url = getClass().getResource(path);
                try {
                    files[i] = new File(url.toURI());
                } catch(URISyntaxException e) {
                    System.out.println("everything is busted!");
            return files;
        public static void main(String[] args) {
            Test test = new Test();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(test.getContent());
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    }geek images from [Geek Images|http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html]

  • I have done what it said in a previous question and exported my IE RSS feeds, but I can't understand how to import them into FireFox ot how to view them once they are imported.

    In a previous question, someone asked hoe to import RSS feeds from IE to FireFox:
    http://support.mozilla.com/en-US/forum/1/358684?s=rss&as=q
    I have done as it says, but had trouble with the second step which was "installing OPML Support 1.5.2 extension for Firefox, which you can use to import OPML file you just exported from IE". I think I installed the extension, but now what? how does it help me import the feeds? And where do i view RSS feeds in FireFox?

    PORT YOUR NUMBER OUT...T MOBILE WILL PAY YOUR ETF IF YOU GIVE THEM YOUR VERIZON PHONES.

  • Can not understand how to reset lost master password key

    I have read how to change it but can not figure to do it

    Did you try to use the chrome URL in the location bar?
    chrome://pippki/content/resetpassword.xul
    If using the chrome url doesn't work then delete the key3.db and signons.sqlite files in the Firefox profile folder.
    * http://kb.mozillazine.org/Profile_folder_-_Firefox
    You can use this button to go to the Firefox profile folder:
    *Help > Troubleshooting Information > Profile Directory: Show Folder (Linux: Open Directory; Mac: Show in Finder)
    * "Resetting the master password": http://kb.mozillazine.org/Master_password
    * https://support.mozilla.org/kb/Forgot+my+master+password

  • Im trying to make a poster size collage of pictures and also want to put a story in the middle of the poster. I just can't understand how to get multiple pictures and how to arrange them around the poster?

    Im trying to make a postersize picture collage and I don't know how to get multiple pictues arranged. Someone said I can use the layer option. But Im just not getting it. Please help!

    Click File >> Open and select all of your photos
    That will add them to the project bin
    Then select File >> New >> Blank File
    Select background color White (or whatever you prefer) and add your width and height for your final image (set resolution 72 for web usage or 240 to 300 for printing) then click OK
    In the project bin click your first photo and drag it up into the main window on top of your new background.
    Click on the move tool and click in the center of the photo and drag to arrange it where you want on the background - you can hold down the shift key to maintain original proportions whilst dragging the corner handles of the bounding box to get the size you want.
    Do the same with the next photo (drag it up into the main window) and use the move tool to position it. Then continue with each image.
    Finally Click Layer >>Flatten image and save as jpeg. (Save as PSD if you want to preserve the layers for editing again)
    N.B. as you add images they get dropped in the center. So you need to use the move tool to drag them apart. Click in the middle of one and move it around, and then the others until you get them positioned as you want.
    When you click again with the move tool a bounding box appears around the image and you can drag out the corner handles to re-size your photos. Hold down the shift key when dragging the corner handle and that will maintain the proportions of the original.
    Finally click Layer >>Flatten Image and save your collage - you may then want to use the crop tool to cut away any surplus white canvas, and then re-save. Click the T tool to add text.

  • Greetings world.I have created a dmg. of my entire iomega ext HDD via disk utility using a mac book pro. It is currently sitting on the desktop. I have erased the iomega and now I can not understand how to put the dmg back.

    It is safe to say that i need help..................
    let me start at the beginning.
    I have 1 2008 imac. always a pleasure never been a problem. Attached to it i have an iomega 500gb ext drive. also been ok.
    until now!!
    The HDD would not mount. Disk utility suggested that it was ok so i tested the imac HD. I got error code 4MOT/2/40000004: HDD- 1502. This doesnt worry me at the moment.
    I attached iomega to my Mac book pro and again it would not mount. The disk utility did tell me that the iomega needed repair. it advised that i should wipe it and restore.
    So I used the MB Pro disk utility to create a DMG. and saved it to the desk top. I then erased the iomega. did a repair and it all seemed ok. So then i try to do a restore.
    After a very long time it said internal error with the dmg. using disk utility i did a convert dmg (compressed) and saved it to the iomega. middle of the night job!!
    got up this morning and indeed it had sent the DMG to the iomega. But i could not open it. The iomega itself seemed dandy asking me if i wanted to use it as a time machine etc and it mounted ok and i saved a small jpeg to the iomega as well. I then thought that maybe when i did the convert as a compressed file i made a mistake. i'm guessing it should be a read and write so i started all over again.......... wiped iomega (which was quite quick) then tried the convert tool again.....it trys for a while then says there is not enough disk space...........I'm not sure which disk it is refering to.??
    I have purchased a 1tb hard drive today incase the iomega is some how full up.
    So really my question to the world is .........Help?

    well no reply from the community. sniff- do i stink!? - probably a little bit. If i have lost all that data then I'm gonna really really pong.
    Any ways i have purchased a 1tb usb HDD and have managed to duplicate the dmg file onto it. however still unable to mount the **** thing. so now i have ordered disk warrior which will be in my possession tomorrow.
    fingers toes eyes crossed.

Maybe you are looking for

  • [SOLVED] l2tp-ipsec-vpn-daemon from AUR fails to build

    Please let me know if there are other details that require posting:- ==> Starting build()... /usr/bin/qmake -o qttmp-Release.mk -after "OBJECTS_DIR=build/Release" "DESTDIR=dist/Release" nbproject/qt-Release.pro mv -f qttmp-Release.mk nbproject/qt-Rel

  • What happened to Photo Mail?

    Why can't I find "Photo Mail" under the Share tab?

  • All files in utilities folder gone how best to reinstall them ?

    My friend has somehow ended up with her Mac with no files in the utilites folder.. and a search shows they are gone She is a noob and lives in another country and does not want to do a full reinstall as she is scared of loosing her data. Is there a w

  • Hardcode and open source

    technically, what does hardcode and open source mean? And, jasper reports and ireports, they are used for report generation in java ryt? is report generation a separate process? or is it embedded in a java app?

  • I have a problem with Adobe programm

    Please help, in detail - http://wikileaksru.blogspot.com