"Automatisches" Lineal

vanteX

Mitglied
Hallo

Ich hätte da mal eine Frage und zwar wollte ich wissen, ob es in Java irgendeine fertige Klasse oder Componente gibt, welche ein Lineal erstellen.
Für alle die nicht genau wissen was ich meine: Wenn man in Photoshop ein Bild öffnet, kann man dort ja ein Lineal einblenden, was einem dann anzeigt, welche Dimensionen das Bild hat und wo sich gerade die Maus befindet.

Gibt es sowas in Java?
Danke im Vorraus!
 
Hallo,

ich suche auch so ein ding bin aber noch nicht genau fündig geworden. Hat in zwischenzeit mal jemand was gefunden ?
 
Java:
import javax.swing.JFrame;

public class Main {
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setLayout(null);
		
		JRuler ruler = new JRuler();
		ruler.setResolution(15);
		ruler.setBounds(0, 0, 300, 100);

		frame.add(ruler);
		frame.setSize(800, 600);
		frame.setVisible(true);
	}
}

Mit Comps. kenne ich mich intern nicht so aus, du musst ihm eventuell verändern und neu compilieren, damit er bei dir richtig hinhaut. Ist eher auf das Null-Layout ausgelegt.
 

Anhänge

Hallo,

ich konnte erst mit dem Code nicht viel anfangen da ich rings um solch ein Linal benötigte, nach lagem suchen habe ich dann doch diesen Code hier modifiziert. Ich wollte ihn nur mal falls nochmal jemand das Problem hat zur verfügung stellen :-D und @kai008 Danke nochmal.


Code:
package main;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class Truler extends JLabel
{
	private static final long serialVersionUID = 1L;

	private int dpi;
	
	public void setBounds(int x, int y, int width, int height)
	{
		super.setBounds(x, y, width, height);
		
		int distance = (int)(((double)(1 * dpi)) / 2.54d);
		
		if(width > 0 && height > 0) {
			BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
			Graphics g = image.getGraphics();
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, width, height);
			g.setColor(Color.BLACK);
			
	//unterer Rand		
			x = 0;
			for(int i = 0; x < width; x+= distance, i++) {
				g.drawLine(x+10, (i%5 == 0 ? height - 10 : height - 5), x+10, height);		
			}
	//oberer Rand
			x = 0;
			for(int i = 0; x < width; x+= distance, i++) {
				g.drawLine(x+10, 0, x+10, (i%5 == 0 ? 10 : 5));		
			}
	//linker Rand
			x = 0;
			for(int i = 0; x < width; x+= distance, i++) {
				g.drawLine((i%5 == 0 ? 10 : 5), x+10, 0, x+10);		
			}			
	//rechter Rand
			x = 0;
			for(int i = 0; x < width; x+= distance, i++) {
				g.drawLine((i%5 == 0 ? width - 10 : width - 5), x+10, width, x+10);		
			}			
	        
			g.dispose();
			setIcon(new ImageIcon(image));
		}
	}
	/**
	 * Set the Resolution in dpi.
	 */
	public void setResolution(int newDpi)
	{
		dpi = newDpi;
	}
}
 

Neue Beiträge

Zurück