Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Display, mini PC, periferiche e networking: le novità ASUS al CES 2026
Display, mini PC, periferiche e networking: le novità ASUS al CES 2026
Sono molte le novità che ASUS ha scelto di presentare al CES 2026 di Las Vegas, partendo da una gamma di soluzioni NUC con varie opzioni di processore passando sino agli schermi gaming con tecnologia OLED. Il tutto senza dimenticare le periferiche di input della gamma ROG e le soluzioni legate alla connettività domestica
Le novità ASUS per il 2026 nel settore dei PC desktop
Le novità ASUS per il 2026 nel settore dei PC desktop
Molte le novità anticipate da ASUS per il 2026 al CES di Las Vegas: da schede madri per processori AMD Ryzen top di gamma a chassis e ventole, passando per i kit di raffreddamento all in one integrati sino a una nuova scheda video GeForce RTX 5090. In sottofondo il tema dell'intelligenza artificiale con una workstation molto potente per installazioni non in datacenter
Le novità MSI del 2026 per i videogiocatori
Le novità MSI del 2026 per i videogiocatori
Con le nuove soluzioni della serie MEG, acronimo di MSI Enthusiast Gaming, l'azienda taiwanese vuole proporre per il 2026 una gamma di proposte desktop che si rivolgono direttamente all'utente più appassionato con schede madri, chassis e sistemi di raffreddamento. Non da ultimi troviamo anche gli alimentatori, che abbinano potenza a ricerca della massima sicurezza di funzionamento.
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 23-03-2004, 13: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, 14: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, 18: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, 09: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, 10: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, 12: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, 12: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


Display, mini PC, periferiche e networking: le novità ASUS al CES 2026 Display, mini PC, periferiche e networking: le n...
Le novità ASUS per il 2026 nel settore dei PC desktop Le novità ASUS per il 2026 nel settore de...
Le novità MSI del 2026 per i videogiocatori Le novità MSI del 2026 per i videogiocato...
I nuovi schermi QD-OLED di quinta generazione di MSI, per i gamers I nuovi schermi QD-OLED di quinta generazione di...
Recensione vivo X300 Pro: è ancora lui il re della fotografia mobile, peccato per la batteria Recensione vivo X300 Pro: è ancora lui il...
Fibra di carbonio, lega di magnesio e 8....
Inaugurato il Padiglione Italia al CES 2...
AGON PRO AG276QSG2: NVIDIA G-Sync Pulsar...
MSI mostra la scheda madre consumer con ...
MSI rinnova l'intera offerta notebook al...
Laifen Wave Pro: debutta al CES lo spazz...
XGIMI Titan Noir Max: al CES il videopro...
Atlas di Boston Dynamics: il robot umano...
TV da 130 pollici ed elettrodomestici, p...
I giochi classici cambiano volto con RTX...
OpenAI testa la pubblicità in Cha...
Plaud riscrive il modo di prendere appun...
Narwal presenta a Las Vegas la nuova gam...
1000W solo per la scheda video: la GeFor...
NVIDIA espande GeForce NOW: nuove app Li...
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: 22:38.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v
Hardware Upgrade Forum Database Error
Database Error Database error
The Hardware Upgrade Forum database has encountered a problem.

Please try the following:
  • Load the page again by clicking the Refresh button in your web browser.
  • Open the www.hwupgrade.it home page, then try to open another page.
  • Click the Back button to try another link.
The www.hwupgrade.it forum technical staff have been notified of the error, though you may contact them if the problem persists.
 
We apologise for any inconvenience.