Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Redmi Watch 6 in prova: lo smartwatch con ampio display da 2000 nit a meno di 100 euro
Redmi Watch 6 in prova: lo smartwatch con ampio display da 2000 nit a meno di 100 euro
Xiaomi ha portato Redmi Watch 6 anche sul mercato italiano, puntando su un display AMOLED da 2,07 pollici con picco di luminosità a 2000 nit, frame in alluminio da 9,9mm e un'autonomia dichiarata di 12 giorni. Lo smartwatch gira su HyperOS 3 e integra GPS, Bluetooth 5.4 e oltre 150 sport mode. Il tutto a meno di 100 euro
Mad Catz M.M.O. 7+: lo stesso DNA del R.A.T. 8+ ADV, ma con molti più pulsanti
Mad Catz M.M.O. 7+: lo stesso DNA del R.A.T. 8+ ADV, ma con molti più pulsanti
Con 22 tasti, il pulsante 5D, lo Shift Mode e il sensore PixArt 3395 da 26.000 DPI, il nuovo mouse wireless di Mad Catz si rivolge in modo preciso ai giocatori di MMO e RPG. Ma chi conosce già il R.A.T. 8+ ADV si accorgerà subito di quanto i due prodotti condividano, e di dove invece divergono
Radeon RX 9070 GRE, AMD la porta in tutto il mondo | Recensione Gigabyte Gaming OC
Radeon RX 9070 GRE, AMD la porta in tutto il mondo | Recensione Gigabyte Gaming OC
Abbiamo provato la Gigabyte Radeon RX 9070 GRE Gaming OC, nuova proposta RDNA 4 che si inserisce tra GeForce RTX 5060 Ti e RTX 5070. Prestazioni solide in rasterizzazione e ray tracing, frequenze elevate grazie all'overclock di fabbrica e raffreddamento efficace: ecco come si comporta nei nostri test.
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 23-03-2004, 12:07   #1
pinzi
Member
 
L'Avatar di pinzi
 
Iscritto dal: Oct 2003
Città: Umbertide
Messaggi: 180
tabelle in java

Salve a tutti
il seguente programma dovrebbe creare un dialogo in cui sia visibile una tabella in cui i nomi delle colonne sono evidenziati(il programma è diviso in due file):

//file:: Main_Program.java

package condensa;

import javax.swing.UIManager;
import java.awt.*;



public class Main_Program {
boolean packFrame = false;


public Main_Program() {
Frame1 frame = new Frame1();

if (packFrame) {
frame.pack();
}
else {
frame.validate();
}

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}

public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new Main_Program();
}
}



//file:: Frame1.java

package condensa;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;


public class Frame1 extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};

Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
final JTable table = new JTable(data, columnNames);


TitledBorder titledBorder1;
TitledBorder titledBorder2;


public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
titledBorder1 = new TitledBorder("");
titledBorder2 = new TitledBorder("");
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
this.getContentPane().add(table, BorderLayout.CENTER);
}

protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}


Il programma in effetti traccia la tabella descritta nel codice tuttavia non vengono mostrati i nomi delle tabelle.
Qualcuno sa dirmi dov'è l'errore?

Saluti Enrico.
pinzi è offline   Rispondi citando il messaggio o parte di esso
Old 23-03-2004, 13:27   #2
kingv
Senior Member
 
L'Avatar di kingv
 
Iscritto dal: Jan 2001
Città: Milano
Messaggi: 5707
aggiungi:

this.getContentPane().add(table.getTableHeader(), BorderLayout.PAGE_START);

prima della add della table (nella jbInit)
kingv è offline   Rispondi citando il messaggio o parte di esso
Old 23-03-2004, 17:37   #3
pinzi
Member
 
L'Avatar di pinzi
 
Iscritto dal: Oct 2003
Città: Umbertide
Messaggi: 180
Hai ragione con questa linea di codice riesco a visualizzare i nomi delle colonne. Ma allora perchè nel seguente programma non è necassario utilizzare il metodo che tu mi hai suggerito?

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class SimpleTableDemo extends JPanel {
private boolean DEBUG = false;

public SimpleTableDemo() {
super(new GridLayout(1,0));

String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};

Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};

final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));



//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);

//Add the scroll pane to this panel.
add(scrollPane);
}


/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {

JFrame.setDefaultLookAndFeelDecorated(true);


JFrame frame = new JFrame("SimpleTableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


SimpleTableDemo newContentPane = new SimpleTableDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);


frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {

javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
pinzi è offline   Rispondi citando il messaggio o parte di esso
Old 24-03-2004, 08:54   #4
kingv
Senior Member
 
L'Avatar di kingv
 
Iscritto dal: Jan 2001
Città: Milano
Messaggi: 5707
uhm così ad occhio non saprei, puo' darsi che nel costruttore di JScrollPane lo faccia, quando ho tempo gli do un occhio
kingv è offline   Rispondi citando il messaggio o parte di esso
Old 24-03-2004, 09:02   #5
cn73
Senior Member
 
L'Avatar di cn73
 
Iscritto dal: Jul 1999
Città: Torino
Messaggi: 2221
Perchè nel secondo esempio aggiungi la tabella a un JScrollPane e poi aggiungi quest0ultimo al contentPane del Frame...
come CHIARAMENTE spiegato nel Tutorial delle Swing:

Quote:
Adding a Table to a Container
It's easy to put a table in a scroll pane. You need just one or two lines of code:
JScrollPane scrollPane = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));

The scroll pane automatically gets the table's header, which displays the column names, and puts it on top of the table. Even when the user scrolls down, the column names remain visible at the top of the viewing area. The scroll pane also tries to make its viewing area the same as the table's preferred viewing size. The previous code snippet sets the table's preferred viewing size with the setPreferredScrollableViewportSize method.
If you're using a table without a scroll pane, then you must get the table header component and place it yourself. For example:

container.setLayout(new BorderLayout());
container.add(table.getTableHeader(), BorderLayout.PAGE_START);
container.add(table, BorderLayout.CENTER);
cn73 è offline   Rispondi citando il messaggio o parte di esso
Old 24-03-2004, 11:12   #6
pinzi
Member
 
L'Avatar di pinzi
 
Iscritto dal: Oct 2003
Città: Umbertide
Messaggi: 180
Mi puoi dare il link a questo tutorial per le swing? E forse nel sito della SUN?
pinzi è offline   Rispondi citando il messaggio o parte di esso
Old 24-03-2004, 11:16   #7
cn73
Senior Member
 
L'Avatar di cn73
 
Iscritto dal: Jul 1999
Città: Torino
Messaggi: 2221
E' linkato anche nelle API della JTable. E' linkato nei topic in rilievo.
Cmq tutti i tutorial sono raggiungibili da http://java.sun.com/docs/books/tutorial/index.html

Quello sulle swing: http://java.sun.com/docs/books/tutor...ing/index.html

L'indice visuale: http://java.sun.com/docs/books/tutor...omponents.html
cn73 è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Redmi Watch 6 in prova: lo smartwatch con ampio display da 2000 nit a meno di 100 euro Redmi Watch 6 in prova: lo smartwatch con ampio ...
Mad Catz M.M.O. 7+: lo stesso DNA del R.A.T. 8+ ADV, ma con molti più pulsanti Mad Catz M.M.O. 7+: lo stesso DNA del R.A.T. 8+ ...
Radeon RX 9070 GRE, AMD la porta in tutto il mondo | Recensione Gigabyte Gaming OC Radeon RX 9070 GRE, AMD la porta in tutto il mon...
Reolink OMVI 3i WiFi: videosorveglianza più intelligente e facile da usare Reolink OMVI 3i WiFi: videosorveglianza pi&ugrav...
Recensione Vivo X300 Ultra: fotocamera eccezionale, ma prezzo proibitivo Recensione Vivo X300 Ultra: fotocamera ecceziona...
Addio ai cavi in auto: questo adattatore...
Polaroid Go Generation 3 è la nuo...
Virgin Galactic torna a far volare lo sp...
La sonda spaziale marziana NASA MAVEN &e...
Nucleare in Italia, approvata la legge d...
Surface Pro, nuova variante in arrivo: a...
Iliad lancia la sua prima offerta FWA pe...
Addio compromessi? I nuovi tablet rugged...
Cooler Master al Computex 2026: case sil...
G.Skill mostra AMD EXPO ULL al Computex:...
Hilti e i data center, l'ingegneria dell...
Narwal anticipa il Prime Day: sconti fin...
Sharkoon mantiene il rapporto qualit&agr...
Xference e Aruba insieme per l'IA privat...
Google Wallet, in arrivo i documenti d'i...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 05:20.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v