/*
* HTML_Display.java
*/
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
import javax.swing.table.*;
public class HTML_Display extends JFrame {
public HTML_Display() {
super("HTML_Display");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setExtendedState(JFrame.MAXIMIZED_BOTH);
//JComponents erzeugen:
label = new JLabel(" Klick auf einen Index Eintrag um die HTML Datei anzuzeigen.");
splitPane = new JSplitPane();
scrollPane1 = new JScrollPane();
table = new JTable();
scrollPane2 = new JScrollPane();
editorpane = new JEditorPane();
//Table model:
tableModel = new DefaultTableModel(
new Object [][] {
{"http://www.tactika.com/realhome/contents.html"},
{"file:c:\\htmltext.html"},
{null},
{null}
},
new String [] {"Index"}
) {
Class[] types = new Class [] {String.class};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
};
//Layout:
getContentPane().add(label, BorderLayout.NORTH);
splitPane.setDividerLocation(200);
table.setModel(tableModel);
scrollPane1.setViewportView(table);
splitPane.setLeftComponent(scrollPane1);
scrollPane2.setViewportView(editorpane);
splitPane.setRightComponent(scrollPane2);
getContentPane().add(splitPane, BorderLayout.CENTER);
//Listener:
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
tableMouseClicked(evt);
}
});
}
private void tableMouseClicked(MouseEvent evt) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
String urlValue = (String) table.getValueAt(table.getSelectedRow(),
table.getSelectedColumn());
try {
URL url = new URL(urlValue);
editorpane.setPage(url);
} catch (Exception e) {}
setCursor(Cursor.getDefaultCursor());
}
public static void main(String args[]) {new HTML_Display().setVisible(true);}
private JEditorPane editorpane;
private JLabel label;
private JScrollPane scrollPane1, scrollPane2;
private JSplitPane splitPane;
private JTable table;
private DefaultTableModel tableModel;
}