Geral

Botões em portugues

Descobri que a solução era mudar de showConfirmDialog para showOptionDialog, criando um vetor com as Strings que aparecerão nos botoes:

String options[] = {"Sim","Não"

http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html

Focus global

Set forwardKeys = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);

Set newForwardKeys = new HashSet(forwardKeys);

newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));

setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,newForwardKeys);

 

Transferencia de foco

 

Programmatic Traversal

 

In addition to user-initiated focus traversal, client code can initiate a focus traversal operation

programmatically. To client code, programmatic traversals are indistinguishable from user-initiated

traversals. The preferred way to initiate a programmatic traversal is to use one of the following

methods on KeyboardFocusManager:

 

      KeyboardFocusManager.focusNextComponent() 

      KeyboardFocusManager.focusPreviousComponent() 

      KeyboardFocusManager.upFocusCycle() 

      KeyboardFocusManager.downFocusCycle() 

 

Each of these methods initiates the traversal operation with the current focus owner. If there is

currently no focus owner, then no traversal operation occurs. In addition, if the focus owner is not a

focus cycle root, then downFocusCycle() performs no traversal operation.

 

KeyboardFocusManager also supports the following variants of these methods:

 

    * KeyboardFocusManager.focusNextComponent(Component)

    * KeyboardFocusManager.focusPreviousComponent(Component)

    * KeyboardFocusManager.upFocusCycle(Component)

    * KeyboardFocusManager.downFocusCycle(Container) 

 

Each of these methods initiates the traversal operation with the specified Component rather than the

focus owner. That is, the traversal occurs as though the specified Component is the focus owner,

though it need not be.

 

Alternate, but equivalent, APIs are defined on the Component and Container classes themselves:

 

    * Component.transferFocus()

    * Component.transferFocusBackward()

    * Component.transferFocusUpCycle()

    * Container.transferFocusDownCycle()

 

Icone na JTable

http://www.java2s.com/Code/Java/Swing-Components/IconCurrencyTable.htm

 

 public Class getColumnClass(int column) {

         if (column == C_CARTAO) return ImageIcon.class;

         else

 public Object getValueAt(int row, int column) {

         Pagar pagar = (Pagar) vetor.get(row);

         switch(column) {

         case C_DESCRICAO: 

                 return String.valueOf(pagar.getNome());

         case C_VCTO:

                 return new SimpleDateFormat("dd/MM/yy EEE").format(pagar.getVcto());

         case C_CHEQUE:

                 return (pagar.getCheque()==0?"":pagar.getCheque()); 

         case C_CARTAO:

                 return (pagar.isCartao()?new ImageIcon("/i1.gif"):new ImageIcon("/i2.gif"));

Sendmail in Java 6

browser

  private void onLaunchBrowser(java.awt.event.ActionEvent evt) {

        URI uri = null;

        try {

            uri = new URI(txtBrowserURI.getText());

            desktop.browse(uri);

        }

        catch(IOException ioe) {

            ioe.printStackTrace();

        }

        catch(URISyntaxException use) {

            use.printStackTrace();

 

        }

        ...

    }

 

Enviar email

private void onLaunchMail(java.awt.event.ActionEvent evt) {

        String mailTo = txtMailTo.getText();

        URI uriMailTo = null;

        try {

            if (mailTo.length() > 0) {

                uriMailTo = new URI("mailto", mailTo, null);

                desktop.mail(uriMailTo);

            } else {

                desktop.mail();

            }

        }

        catch(IOException ioe) {

            ioe.printStackTrace();

        }

        catch(URISyntaxException use) {

            use.printStackTrace();

        }

        ...

    }