Clipboard
I need to copy the value of one JTable field to Clipboard. I'm not understanding how this mecanism works. Can some give me: Good explanation. Reference to a article with this information. Some simple working code. Since Drag and drop seem to use a similar interface and I will need to do it, in one week, I estend the question to this as well. Thanks Marcos Rebelo ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
Bringing one JInternalFrame to the front of the JDesktopPane
I'm using one JDesktopPane in my project and I need to set one JInternalFrame in front of all the other and selected. Until know this is the better I can do. If the JInternalFrame is iconifyed this don't work. I know this must be a very simple thing to do but I don't find how. import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JPanel; import javax.swing.JSplitPane; public class Test { public static void main(String[] args) { JFrame frm = new JFrame(); JSplitPane spn = new JSplitPane(); JPanel pnButtons = new JPanel(); final JDesktopPane dsk = new JDesktopPane(); final JInternalFrame ifr1 = new JInternalFrame(1,true,true,true,true); final JInternalFrame ifr2 = new JInternalFrame(2,true,true,true,true); pnButtons.add(new JButton(new AbstractAction(Open 1){ public void actionPerformed(ActionEvent arg0) { dsk.getDesktopManager().deiconifyFrame(ifr1); ifr1.hide(); ifr1.show(); } })); pnButtons.add(new JButton(new AbstractAction(Open 2){ public void actionPerformed(ActionEvent arg0) { dsk.getDesktopManager().deiconifyFrame(ifr2); ifr2.hide(); ifr2.show(); } })); dsk.add(ifr1); ifr1.pack(); ifr1.setSize(200,100); ifr1.show(); dsk.add(ifr2); ifr2.pack(); ifr2.setSize(200,100); ifr2.show(); spn.setLeftComponent(pnButtons); spn.setRightComponent(dsk); frm.setContentPane(spn); frm.setSize(800, 600); frm.show(); } } ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
RE: Bringing one JInternalFrame to the front of the JDesktopPane
Thanks, seems to be perfect. In the end of this work I shall write a book called Tips for real dummy programmers like me. Thanks Marcos -Original Message- From: Brian Gagne [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 18, 2004 5:19 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Bringing one JInternalFrame to the front of the JDesktopPane Calling just the desktop manager method only does part of the job and leaves the state inconsistent. This code should fix your problem: pnButtons.add(new JButton(new AbstractAction(Open 1){ public void actionPerformed(ActionEvent arg0) { try { ifr1.setIcon(false); ifr1.setSelected(true); } catch( java.beans.PropertyVetoException e ) {} ifr1.toFront(); } })); pnButtons.add(new JButton(new AbstractAction(Open 2){ public void actionPerformed(ActionEvent arg0) { try { ifr2.setIcon(false); ifr2.setSelected(true); } catch( java.beans.PropertyVetoException e ) {} ifr2.toFront(); } })); [EMAIL PROTECTED] wrote: I'm using one JDesktopPane in my project and I need to set one JInternalFrame in front of all the other and selected. Until know this is the better I can do. If the JInternalFrame is iconifyed this don't work. I know this must be a very simple thing to do but I don't find how. import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JPanel; import javax.swing.JSplitPane; public class Test { public static void main(String[] args) { JFrame frm = new JFrame(); JSplitPane spn = new JSplitPane(); JPanel pnButtons = new JPanel(); final JDesktopPane dsk = new JDesktopPane(); final JInternalFrame ifr1 = new JInternalFrame(1,true,true,true,true); final JInternalFrame ifr2 = new JInternalFrame(2,true,true,true,true); pnButtons.add(new JButton(new AbstractAction(Open 1){ public void actionPerformed(ActionEvent arg0) { dsk.getDesktopManager().deiconifyFrame(ifr1); ifr1.hide(); ifr1.show(); } })); pnButtons.add(new JButton(new AbstractAction(Open 2){ public void actionPerformed(ActionEvent arg0) { dsk.getDesktopManager().deiconifyFrame(ifr2); ifr2.hide(); ifr2.show(); } })); dsk.add(ifr1); ifr1.pack(); ifr1.setSize(200,100); ifr1.show(); dsk.add(ifr2); ifr2.pack(); ifr2.setSize(200,100); ifr2.show(); spn.setLeftComponent(pnButtons); spn.setRightComponent(dsk); frm.setContentPane(spn); frm.setSize(800, 600); frm.show(); } } ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing _ Do you Yahoo!? Yahoo! http://us.rd.yahoo.com/mailtag_us/*http://antispam.yahoo.com/tools?tool=1 Mail SpamGuard - Read only the mail you want. ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
Path Files
In my program I'm using ImageIcon for the buttons and I had this code Action actClose = new AbstractAction(Close, new ImageIcon(images/file_close.gif)){...} This works if I'm in the correct directory, but if I'm not the images are not found. What is the correct way to do the previus code? Thanks Marcos ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
Add new lines to the JTable
What is the better way to add lines to a JTable. I have my TableModal and I add one line to the Model, know I need the line to apear in the interface. The only way that I get it to work is with the line 'scrollPane.getViewport().add(table);' (I tryed allot of things before I get here). What is the correct way to do it? This is a simple code showing my problem. import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.table.AbstractTableModel; class MyTableModel extends AbstractTableModel { int nRows = 5; public int getRowCount() { return nRows; } public int getColumnCount() { return 4; } public Object getValueAt(int arg0, int arg1) { return new Integer(arg0*arg1); } void IncrementRow() { nRows++; } } public class Main { static JFrame m_frame; public static void main(String[] ARGS) { m_frame = new JFrame(Teste); m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); m_frame.getContentPane().setLayout(new BorderLayout()); final JTable table = new JTable(); final MyTableModel myTableModel = new MyTableModel(); table.setModel(myTableModel); final JScrollPane scrollPane = new JScrollPane(table); m_frame.getContentPane().add(scrollPane, BorderLayout.SOUTH); JButton bt = new JButton(XXX); bt.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { myTableModel.IncrementRow(); scrollPane.getViewport().add(table); } }); m_frame.getContentPane().add(bt, BorderLayout.NORTH); m_frame.pack(); m_frame.setVisible(true); } } ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
RE: Add new lines to the JTable
Thanks for this answer, I look in the table and I never remember to go to the TableModel. Onether question. Know I have the Table with the cells editable. If I chose another column the setValueAt is called. If I press the button the setValueAt is not called. If I go to the TextArea the setValueAt is not called. if I close the Frame the setValueAt is not called. This isn't suposed? Simple code. I'm seeing just the output. import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.table.AbstractTableModel; class MyTableModel extends AbstractTableModel { int nRows = 5; public int getRowCount() { return nRows; } public int getColumnCount() { return 4; } public Object getValueAt(int arg0, int arg1) { return new Integer(arg0*arg1); } void IncrementRow() { System.out.println(IncrementRow()); nRows++; } public boolean isCellEditable(int nRow, int nCol) { System.out.println(isCellEditable(int nRow, int nCol)); return true; } public void setValueAt(Object arg0, int arg1, int arg2) { System.out.println(setValueAt(Object arg0, int arg1, int arg2)); } } public class Main { static JFrame m_frame; public static void main(String[] ARGS) { m_frame = new JFrame(Teste); m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); m_frame.getContentPane().setLayout(new BorderLayout()); final JTable table = new JTable(); final MyTableModel myTableModel = new MyTableModel(); table.setModel(myTableModel); final JScrollPane scrollPane = new JScrollPane(table); m_frame.getContentPane().add(scrollPane, BorderLayout.CENTER); JButton bt = new JButton(XXX); bt.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { myTableModel.IncrementRow(); myTableModel.fireTableDataChanged(); } }); m_frame.getContentPane().add(bt, BorderLayout.NORTH); m_frame.getContentPane().add(new JTextField(), BorderLayout.SOUTH); m_frame.pack(); m_frame.setVisible(true); } } ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
FW: right click open one menu
I'm lost how to do it with a JTable. This code is not running import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; class PopupListener extends MouseAdapter { JPopupMenu m_pmnPopup; public PopupListener(JPopupMenu pmnPopup) { m_pmnPopup = pmnPopup; } public void mousePressed(MouseEvent e) { maybeShowPopup(e); } public void mouseReleased(MouseEvent e) { maybeShowPopup(e); } void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { m_pmnPopup.show(e.getComponent(), e.getX(), e.getY()); } } } class MyTableColumn extends TableColumn { public MyTableColumn(int modelIndex) { super(modelIndex); JPopupMenu pmnPopupHeader = new JPopupMenu(); pmnPopupHeader.add(new JMenuItem(header1)); pmnPopupHeader.add(new JMenuItem(header2)); pmnPopupHeader.add(new JMenuItem(header3)); // ((Component)getHeaderRenderer()).addMouseListener(new PopupListener(pmnPopupHeader)); JPopupMenu pmnPopupCell = new JPopupMenu(); pmnPopupCell.add(new JMenuItem(cell1)); pmnPopupCell.add(new JMenuItem(cell2)); pmnPopupCell.add(new JMenuItem(cell3)); // ((Component)getCellRenderer()).addMouseListener(new PopupListener(pmnPopupCell)); } } public class Main { static JFrame m_frame; static final int NUMBER_OF_COLUMNS = 100; public static void main(String[] ARGS){ m_frame = new JFrame(Teste); m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); m_frame.getContentPane().setLayout(new BorderLayout()); JTable table = new JTable(); table.setModel(new AbstractTableModel(){ public int getRowCount() { return 2047; } public int getColumnCount() { return NUMBER_OF_COLUMNS; } public Object getValueAt(int arg0, int arg1) { return new Integer(arg0*arg1); }}); table.setAutoCreateColumnsFromModel(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); for (int nColumn = 0; nColumn NUMBER_OF_COLUMNS; nColumn++) { table.addColumn(new MyTableColumn(nColumn)); } JScrollPane scrollPane = new JScrollPane(table); m_frame.getContentPane().add(scrollPane, BorderLayout.SOUTH); JLabel label = new JLabel(XXX); JPopupMenu pmnPopup = new JPopupMenu(); pmnPopup.add(new JMenuItem(item1)); pmnPopup.add(new JMenuItem(item2)); pmnPopup.add(new JMenuItem(item3)); label.addMouseListener(new PopupListener(pmnPopup)); m_frame.getContentPane().add(label, BorderLayout.NORTH); m_frame.pack(); m_frame.setVisible(true); } } For the JLabel works but for the JTable don't. In the Cell case I'have to know the Row as well. Thanks Marcos -Original Message- From: Meikel Bisping [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 28, 2004 1:03 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: right click open one menu Try JPopupMenu http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html [EMAIL PROTECTED] schrieb am 28.01.2004: I need to create one menu with some options if right click in one component. Is this possible? Thanks MArcos ___ Swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/swing ___ Swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/swing ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
Limits in JTable
This is one of the most strange error that I ever found. If I run the some code in Windows NT works, in a sun workstation works and in Window throw Exceed to a sun worstation don't work. With this code works in the 3: import javax.swing.*; import javax.swing.table.*; public class Main { static JFrame m_frame; public static void main(String[] ARGS){ m_frame = new JFrame(Teste); m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(); table.setModel(new AbstractTableModel(){ public int getRowCount() { return 2047; } public int getColumnCount() { return 436; } public Object getValueAt(int arg0, int arg1) { return new Integer(arg0*arg1); }}); table.setAutoCreateColumnsFromModel(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); JScrollPane scrollPane = new JScrollPane(table); m_frame.getContentPane().add(scrollPane); m_frame.pack(); m_frame.setVisible(true); } } Know if I change public int getRowCount() { return 2047; } to public int getRowCount() { return 2048; } Or if I change public int getColumnCount() { return 436; } to public int getColumnCount() { return 437; } I get problems. When I do scroll the table has problems whith the refrescement, seems that background of the cell in the JTable are not painted but if I resize the Frame the repaint is done with a wrong color. Probably the JScrollPanel color, I don't know. This error just occores in the exceed. Thanks Marcos ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
Trees and XML
I don't have access to the internet, it's why I'm asking this in here. I need to learn the JTrees and to read and write XML files. Someone as example of how to do this? Thanks Marcos ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
Dialog for Open one File
I need a Open file Dialog. I was seeing the JFileChooser and I did this class. public class JDialogFileOpen extends JFileChooser { public int showDialog(Component arg0, String arg1) throws HeadlessException { while (true) { int nOption = super.showDialog(arg0, arg1); if (nOption != JDialogFileOpen.APPROVE_OPTION) { return nOption; } else { File file = this.getSelectedFile(); if (file.exists() file.isFile()) { return nOption; } else { JOptionPane.showMessageDialog( this, file.getPath()+\nFile not found., null, JOptionPane.ERROR_MESSAGE); } } } } } When the file does not exists shows a error message and reshow the JFileChooser. I don't want the JFileChooser to desapear. Is this possible? Thanks Marcos ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
Setting new JPane to a JFrame.
This is the most simple code that I found to show this error. I have JFrame with a complex Content Pane (not this one). I'm trying to recreate the Content pane for each File but after I set the new Content Pane there is no Change, But if I try to resize the new Pane alredy apears. What do I need to set this simple example to work? import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; public class Main { static JFrame m_frame; public static void main(String[] args) { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); m_frame = new JFrame(Teste); m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); m_frame.setContentPane(createPanel(null)); m_frame.pack(); m_frame.setVisible(true); } static JPanel createPanel(File file) { JPanel panel = new JPanel(); JButton bRecreate = new JButton(Recreate); bRecreate.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { JFileChooser fileChooser = new JFileChooser(); if (fileChooser.showOpenDialog(m_frame) != JFileChooser.APPROVE_OPTION) return; m_frame.setContentPane(createPanel(fileChooser.getSelectedFile())); }}); JLabel label = new JLabel(); if (file != null) { label.setText(file.getPath()); } panel.add(label); panel.add(bRecreate); return panel; } } ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing