Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
/*
* Created on 20.05.2005@10:27:28 by Darimont
*
* TODO Licence info
*/
package de.tutorials;
/**
* @author Darimont
*
* TODO Explain me
*/
public class StringRowEstimator {
public static void main(String[] args) {
final int MAX_COLUMNS = 2;
String str = "12345678901";
int len = str.length();
System.out.println("Der String mit der länge: " + len);
int rows = len / MAX_COLUMNS + ((len % MAX_COLUMNS) > 0 ? 1 : 0);
System.out.println("Benötigt: " + rows + " Zeilen");
}
}
package GUI;
import java.awt.*;
import java.awt.Component;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.*;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
public class TableViewModel extends DefaultTableCellRenderer implements TableCellRenderer {
public static void calculateNeededRows( String str, int width ) {
//final int MAX_COLUMNS = 2;
int length = str.length();
System.out.println("Der String mit der Länge: " + length);
int rows = length / width + ((length % width) > 0 ? 1 : 0);
System.out.println("Benötigt: " + rows + " Zeilen");
}
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) {
Component c = super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column);
Font font = new Font("Tahoma", Font.PLAIN, 11);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
table.getTableHeader().setBackground( Color.darkGray );
table.getTableHeader().setFont(font);
JTextArea area = new JTextArea();
area.setFont(font);
area.setWrapStyleWord(true);
area.setLineWrap(true);
area.setBackground( new Color(84,84,84) );
area.setForeground( Color.white );
JLabel label = new JLabel();
label.setHorizontalTextPosition(JLabel.LEFT);
label.setHorizontalAlignment(JLabel.LEFT);
JPanel panel = new JPanel();
FlowLayout flowLayout = new FlowLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
panel.setLayout(flowLayout);
/*if(row == 0) {
table.setRowHeight(29);
} else if(row == 1) {
table.setRowHeight(58);
area.setColumns(2);
}*/
if( column >= 0 && column <= 1 ) {
label.setText( (String) value );
panel.add( label );
} else if( column == 2 ) {
if( Editor.getEditedRows().contains(row) ) {
label.setForeground(Color.red );
//label.setForeground(Color.lightGray );
//label.setFont( new Font("Tahoma", Font.BOLD, 11) );
} else {
label.setForeground(Color.white);
}
label.setText( (String) value );
panel.add( label );
} else if( column == 3 ) {
int currentWidth = table.getColumnModel().getColumn(3).getWidth();
if(row == 0 || row == 1) {
this.calculateNeededRows( (String) value, currentWidth );
}
Dimension dim = new Dimension( currentWidth, 58);
area.setMinimumSize( dim );
area.setMaximumSize( dim );
area.setPreferredSize( dim );
area.setText( (String) value );
System.out.println(area.getHeight() + " " + area.getRows() );
panel.add( area );
} else if( column == 4 ) {
panel.add( new JButton("+") );
} else if( column == 5 ) {
panel.add( new JButton("-") );
}
panel.setOpaque(true);
panel.setBackground(table.getBackground());
if (isSelected) {
panel.setBackground( new Color(115, 107, 82) );
panel.setForeground( Color.WHITE );
area.setBackground( new Color(115, 107, 82) );
} else {
panel.setBackground( new Color(84,84,84) );
panel.setForeground( Color.WHITE );
}
return panel;
}
}