IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Java Discussion :

Récupération des informations dans un Jtable


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau membre du Club
    Inscrit en
    Juillet 2010
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 5
    Par défaut Récupération des informations dans un Jtable
    Bonsoir, je travaille avec les commandes AT sur un modem E300, j'envoie une commande AT pour récupérer les informations radio.
    Le problème est comment je peux récupérer le resultat dans un jtable ??
    Le résultat de la commande est :

    Ch, SC, RSCP, EcNo, PTxPwr, ULTxPwr, ServL, ServQ, Hn, Rn
    10813, 46, 0, 0, 200, 24, 1, 13, ,
    10813, 47, 0, 0, 37, 24, 1, 13, ,
    10813, 414, 0, 0, 255, 24, 1, 13, ,
    10813, 288, 0, 0, 4, 24, 1, 13, ,
    10813, 289, -91, -7, 0, 24, 1, 13, ,
    10813, 280, 0, 0, 0, 24, 1, 13, ,
    10813, 281, -103, -19, 0, 24, 1, 13, ,
    10813, 300, 0, 0, 0, 24, 1, 13, ,
    10813, 301, 0, 0, 0, 24, 1, 13, ,
    10813, 209, 0, 0, 0, 24, 1, 13, ,
    10813, 210, 0, 0, 0, 24, 1, 13, ,
    10813, 504, 0, 0, 0, 24, 1, 13, ,
    10813, 505, 0, 0, 0, 24, 1, 13, ,
    10813, 506, 0, 0, 0, 24, 1, 13, ,
    10813, 426, 0, 0, 0, 24, 1, 13, ,
    10813, 304, 0, 0, 0, 24, 1, 13, ,
    10813, 306, 0, 0, 0, 24, 1, 13, ,
    10813, 312, 0, 0, 0, 24, 1, 13, ,
    10813, 314, 0, 0, 0, 24, 1, 13, ,
    10813, 296, -95, -11, 0, 24, 1, 13, ,
    10813, 297, 0, 0, 0, 24, 1, 13, ,
    10813, 298, 0, 0, 0, 24, 1, 13, ,

  2. #2
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2007
    Messages : 60
    Par défaut
    Voici un exemple complet trouvé sur internet :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
     
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableColumn;
     
    public class TableRowColumn extends JFrame
    {
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
    	private final static String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	JTable table;
    	DefaultTableModel model;
    	JPanel buttonPanel;
    	JButton button;
     
    	public TableRowColumn()
    	{
    		//  Create table
     
    		Object[][] data = { {"1", "A"}, {"2", "B"}, {"3", "C"} };
    		String[] columnNames = {"Number","Letter"};
    		model = new DefaultTableModel(data, columnNames);
    		table = new JTable(model);
    		table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
     
    		//  Add table and a Button panel to the frame
     
    		JScrollPane scrollPane = new JScrollPane( table );
    		getContentPane().add( scrollPane );
     
    		buttonPanel = new JPanel();
    		getContentPane().add( buttonPanel, BorderLayout.SOUTH );
     
    		//
     
    		button = new JButton( "Add Row" );
    		buttonPanel.add( button );
    		button.addActionListener( new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    				model.addRow( createRow() );
    				int row = table.getRowCount() - 1;
    				table.changeSelection(row, 0, false, false);
    				table.requestFocusInWindow();
    			}
    		});
     
    		//
     
    		button = new JButton( "Insert Row" );
    		buttonPanel.add( button );
    		button.addActionListener( new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    				model.insertRow( 0, createRow() );
    				table.changeSelection(0, 0, false, false);
    				table.requestFocusInWindow();
    			}
    		});
     
    		//
     
    		button = new JButton( "Empty Row" );
    		buttonPanel.add( button );
    		button.addActionListener( new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    				model.setRowCount( model.getRowCount() + 1 );
    				int row = table.getRowCount() - 1;
    				table.changeSelection(row, 0, false, false);
    				table.requestFocusInWindow();
    			}
    		});
    		//
    		button = new JButton( "Add Column" );
    		buttonPanel.add( button );
    		button.addActionListener( new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    				String header = "Col" + (table.getColumnCount() + 1);
    				model.addColumn( header );
    				table.requestFocusInWindow();
    			}
    		});
    		//
    		button = new JButton( "Add Column & Data" );
    		buttonPanel.add( button );
    		button.addActionListener( new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    				String header = "Col" + (table.getColumnCount() + 1);
     
    				int rows = table.getRowCount();
    				String[] values = new String[rows];
     
    				for (int j = 0; j < rows; j++)
    				{
    					values[j] = Integer.toString(j);
    				}
     
    				model.addColumn( header, values );
    				table.requestFocusInWindow();
    			}
    		});
    		//
    		button = new JButton( "Add Column - No Reordering" );
    		buttonPanel.add( button );
    		button.addActionListener( new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    				//  Use this method when you don't want existing columns
    				//  to be rebuilt from the model.
    				//  (ie. moved columns will not be reordered)
     
    				table.setAutoCreateColumnsFromModel( false );
    				String header = "Col" + (table.getColumnCount() + 1);
    				model.addColumn( header );
     
    				//  AutoCreate is turned off so create table column here
     
    				TableColumn column = new TableColumn( table.getColumnCount() );
    				column.setHeaderValue( header );
    				table.addColumn( column );
     
    				// These won't work once setAutoCreate... has been set to false
    				buttonPanel.getComponent(3).setEnabled( false );
    				buttonPanel.getComponent(4).setEnabled( false );
    				table.requestFocusInWindow();
    			}
    		});
    		//
    		button = new JButton( "Remove Last Column" );
    		buttonPanel.add( button );
    		button.addActionListener( new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    				int columns = model.getColumnCount();
     
    				if (columns > 0)
    				{
     
    					if (!table.getAutoCreateColumnsFromModel())
    					{
    						int view =
    							 table.convertColumnIndexToView(columns - 1);
    						TableColumn column =
    							table.getColumnModel().getColumn(view);
    						table.getColumnModel().removeColumn( column );
    					}
     
    					model.setColumnCount( columns - 1 );
    				}
    				table.requestFocusInWindow();
    			}
    		});
     
    	}
     
    	private Object[] createRow()
    	{
    		Object[] newRow = new Object[2];
    		int row = table.getRowCount() + 1;
    		newRow[0] = Integer.toString( row );
    		newRow[1] = LETTERS.substring(row-1, row);
    		return newRow;
    	}
     
    	public static void main(String[] args)
    	{
    		TableRowColumn frame = new TableRowColumn();
    		frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    		frame.pack();
    		frame.setLocationRelativeTo( null );
    		frame.setVisible(true);
    	}
    }

  3. #3
    Nouveau membre du Club
    Inscrit en
    Juillet 2010
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 5
    Par défaut
    Merci bien )
    sa résolu l'affaire

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Récupération d'information dans des sous-sites.
    Par lesanglier dans le forum SharePoint
    Réponses: 2
    Dernier message: 27/11/2009, 23h36
  2. Récupération des informations contenues dans un fichier
    Par dream_of_australia dans le forum Débuter
    Réponses: 16
    Dernier message: 08/07/2009, 17h47
  3. Réponses: 1
    Dernier message: 26/11/2008, 03h15
  4. Réponses: 7
    Dernier message: 13/08/2008, 11h08
  5. Réponses: 4
    Dernier message: 03/04/2008, 13h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo