java swing draw centered text
Java
public void centerString(Graphics g, Rectangle r, String s,
Font font) {
FontRenderContext frc =
new FontRenderContext(null, true, true);
Rectangle2D r2D = font.getStringBounds(s, frc);
int rWidth = (int) Math.round(r2D.getWidth());
int rHeight = (int) Math.round(r2D.getHeight());
int rX = (int) Math.round(r2D.getX());
int rY = (int) Math.round(r2D.getY());
int a = (r.width / 2) - (rWidth / 2) - rX;
int b = (r.height / 2) - (rHeight / 2) - rY;
g.setFont(font);
g.drawString(s, r.x + a, r.y + b);
}
Also in Java:
- Title
- system.arraycopy java
- Category
- Java
- Title
- fibonacci sequence in java recursion
- Category
- Java
- Title
- compile java
- Category
- Java
- Title
- java android development get element by id
- Category
- Java
- Title
- programa que convierete un archi de c a java
- Category
- Java
- Title
- javafx datepicker
- Category
- Java
- Title
- array null pointer java
- Category
- Java
- Title
- how to add to a file in java
- Category
- Java
- Title
- actionListener java
- Category
- Java
- Title
- primitive and non primitive data types in java
- Category
- Java
- Title
- dicom read with java
- Category
- Java
- Title
- how to create a random number in java
- Category
- Java
- Title
- java find biggest number in array
- Category
- Java
- Title
- java set value of arraylist
- Category
- Java
- Title
- integer max value java
- Category
- Java
- Title
- java create map
- Category
- Java
- Title
- how to create a subclass in java
- Category
- Java
- Title
- how to make a variable unchangeable in java
- Category
- Java
- Title
- how to convert char to uppercase java
- Category
- Java
- Title
- convert string to localdatetime
- Category
- Java
- Title
- find first non repeating character in a string
- Category
- Java
- Title
- arrays.fill java
- Category
- Java
- Title
- remove unused imports intellij
- Category
- Java
- Title
- error message pushes button down
- Category
- Java
- Title
- how to create a 2d arraylist java
- Category
- Java
- Title
- java gateway process exited before sending its port number pyspark anaconda
- Category
- Java
- Title
- reentrantreadwritelock java
- Category
- Java
- Title
- java pass array as method parameter
- Category
- Java
- Title
- rgb to hex java
- Category
- Java
- Title
- java while loop break
- Category
- Java
- Title
- dataframe to dict without index
- Category
- Java
- Title
- create object of static class in java
- Category
- Java
- Title
- springBoot
- Category
- Java
- Title
- java int array
- Category
- Java
- Title
- java get excectuon time
- Category
- Java
- Title
- arraylist get last
- Category
- Java
- Title
- java string split underscore
- Category
- Java
- Title
- how to make a searchable list in java
- Category
- Java
- Title
- spring-boot actuator not working
- Category
- Java
- Title
- what is graphics default color java
- Category
- Java
- Title
- indexof java
- Category
- Java
- Title
- how intent
- Category
- Java
- Title
- java size of stack
- Category
- Java
- Title
- java max
- Category
- Java
- Title
- what it means when create final variable in java
- Category
- Java
- Title
- java catch multiple exceptions
- Category
- Java
- Title
- dictionary in java
- Category
- Java
- Title
- how to access private vairable in java method
- Category
- Java
- Title
- refrence xml textfield in javafx
- Category
- Java
- Title
- read csv java
- Category
- Java
- Title
- java get html from url
- Category
- Java
- Title
- how to change the icon of a jframe
- Category
- Java
- Title
- log4j print stacktrace
- Category
- Java
- Title
- convert from integer to character java
- Category
- Java
- Title
- java return new instance of generic type
- Category
- Java
- Title
- determine if a given binary tree is a valid bst
- Category
- Java
- Title
- loop through array java
- Category
- Java
- Title
- android how to switch between activities
- Category
- Java
- Title
- java vs javascript
- Category
- Java
- Title
- how to get orientation lock to portrait android stackoverflow
- Category
- Java
- Title
- throwing exceptions java
- Category
- Java
- Title
- how to set a windows background image tkinter
- Category
- Java
- Title
- java split for multiple characters
- Category
- Java
- Title
- Java's BigInteger class
- Category
- Java
- Title
- java string to lower case
- Category
- Java
- Title
- room insert and return id
- Category
- Java
- Title
- get last element of array java
- Category
- Java
- Title
- java save string in text file
- Category
- Java
- Title
- java try catch
- Category
- Java
- Title
- java.lang.ClassCastException: cannot be cast to javax.servlet.Servlet
- Category
- Java
- Title
- java execute for cycle parallel thread
- Category
- Java
- Title
- import classes from another project java
- Category
- Java
- Title
- java shuffle list
- Category
- Java
- Title
- java simple jframe example
- Category
- Java
- Title
- how to check if the file has remaining without reading from it java
- Category
- Java
- Title
- how to check internet is working or not in java
- Category
- Java
- Title
- java string regexp replace
- Category
- Java
- Title
- java regex replace all characters before
- Category
- Java
- Title
- creating array java
- Category
- Java
- Title
- spark write partitionby
- Category
- Java
- Title
- how to read a csv file java
- Category
- Java
- Title
- java stack push
- Category
- Java
- Title
- java script zip function
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- how to change top of window in java
- Category
- Java
- Title
- number to char java
- Category
- Java
- Title
- android java shared preferences remove key
- Category
- Java
- Title
- spigot spawn firework
- Category
- Java
- Title
- java output array lists to file
- Category
- Java
- Title
- java create directory
- Category
- Java
- Title
- array in java
- Category
- Java
- Title
- how to create a circle in java
- Category
- Java
- Title
- loop array using stream java
- Category
- Java
- Title
- center textview programmatically android
- Category
- Java
- Title
- how to parse a string into a number in java
- Category
- Java
- Title
- how to check the end of a string java
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- send variable intent
- Category
- Java
- Title
- hide element selenium
- Category
- Java
- Title
- java printf tab
- Category
- Java