Scaling Text According To Screen Size
Jul 4, 2014
What I am creating is a clock. That goes round n round using "getcalendar". It's realtime, but the clock has a constant resolution of 800x800. I have carefully placed numbers from 1-12 on the clock using that resolution placing them pixel by pixel. Now if I resize the window, the clock resizes but the text, it fades away out of the screen because the resolution is too small.
This is how I draw them.
g2.drawString(six, 380, 750);
g2.drawString(twelve, 375, 70);
g2.drawString(nine, 30, 415);
g2.drawString(three, 725, 415);
g2.drawString(one, 570, 120);
g2.drawString(two, 690, 250);
g2.drawString(four, 685, 575);
g2.drawString(five, 570, 700);
g2.drawString(seven, 200, 710);
g2.drawString(eight, 80, 585);
g2.drawString(ten, 80, 235);
g2.drawString(eleven, 205, 115);
I understand why this is happening, obviously because the strings are in a certain place just can't understand how do I make them scaleable? Is there an universal formula? Or do I have to draw every string relevant to some mathematical equation regarding to the screen size.
For example : g2.drawString(twelve, diameter / 2, screenheight / 3);
View Replies
ADVERTISEMENT
Sep 29, 2014
I have created a java gui on Windows 7 with Eclipse EE, using a screen resolution of 1366 x 768. I used groups with specified boundaries. For example:
final Group g5_script_data = new Group(shell, SWT.BORDER_SOLID);
g5_script_data.setText("Current DB");
g5_script_data.setBounds(0, 0, 680, 380);
g5_script_data.setBackground(green);
The groups cover the whole screen.
However my colleague with a smaller resolution looses the far right of the screen.
As this is a proto-type and I'm new to Java I don't want to rework everything or convert it to say a grid layout until the proto-type is accepted and I can start from scratch with a real detailed design. It already has 6500 lines of source.
Just wondered what is my quickest/easiest way to get my app to display on a slightly smaller resolution. For sure it will not be anything silly. Something like 1280 x 768 to 1366 x 768 would do.
View Replies
View Related
Feb 17, 2014
Basically the code is for a game which is displayed in a window. The statement if(false) //full screen mode is confusing me a little. How does this if work? it doesn't seem to be testing for anything so how does it ever get set to full screen mode? Is the if even needed? why not just code windowed mode?
public class Window extends JFrame{
private Window()
{
// Sets the title for this frame.
this.setTitle("My test");
// Sets size of the frame.
if(false) // Full screen mode
[Code] .....
View Replies
View Related
May 10, 2015
The code:
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
[Code] ....
run (when window height > 700px ) :
HTMLEditor default height is 670px, the other area (green color) is not filled,why?
HTMLEditor 高度总是670px, 怎么把HTMLEditor 填充满窗口?
这是一个bug吗?
is it bug?
View Replies
View Related
Feb 28, 2014
I am using JSF 2 & Richfaces 4
My input text box should accept only 1 character.
<h:inputText id="empid" value="#{details.val}" size="1" />
Set the size as 1, still it showing more size in the screen.
Apart from size =1, any other place to set the size of the text box?
View Replies
View Related
Mar 18, 2014
Here I would like to collect automatically in a file ( txt) the characters displayed on the screen. I'm working on a system that the database is remote. To receive information, there is a terminal by which sends commands. The feedback is displayed only on the screen and you can only print. This is actually a terminal black screen, white character, such as command line "DOS" . The software can not export , or access to the database or other means of information retrieval .
I explored the track of the OCR . But the result produced is not consistent with the captured picture. How can I do this? I have no other tracks ....
View Replies
View Related
Sep 25, 2014
I have code to convert tiff image to PNG image.I want to scale my PNG image to 800X800 without losing quality.I use the below code but seems doesn't work.Its not resizing the image to specific height and width.
Java Code:
SeekableStream seekableStream = new FileSeekableStream(file);
ImageDecoder imageDecoder = ImageCodec.createImageDecoder(
Constants.TIFF, seekableStream, null);
RenderedImage renderedImage[] = new RenderedImage[imageDecoder
.getNumPages()];
for (int i = 0; i < imageDecoder.getNumPages(); i++) {
[code]...
View Replies
View Related
Nov 11, 2014
I want to create 3 JTextFields in a row with all being of equal size.But my first Text field gets so wide than the other two.After adding each component at a time and seeing what causes the problem I realized that if I type a long text for the JLabel that's when this problem occurs.If I reduce the length of the text in the JLabel JTextFields get into the sizes I want. Here's my code
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
public class Calculator1 extends JFrame {
JTextField value1=new JTextField("0");
JTextField value2=new JTextField("0");
[Code] ....
How can I stop the JTextFields changing size when I change the JLabel label1's text length...
View Replies
View Related
Apr 14, 2014
I have a major problem. the text size is like 6 or 8 pt font and I can't read it. I'm trying to run a downloaded exe program which uses the jre7 which I had to download beforehand. the font size stays at 6 or 8 even if I try to change it in windows settings. it's a high res monitor on a lenovo yoga laptop. is there a way for me to edit the java code and manually change the font size?
View Replies
View Related
Apr 23, 2015
I'm trying to implement a scene with a ScrollPane in which the user can drag a node around and scale it dynamically. I have the dragging and scaling with the mouse wheel working as well as a reset zoom.
Here's my issue:
I'm having trouble with the calculations to fit the node to the width of the parent.
If I zoom in or out, the fit to width does not work.
If I change the window size after running fitWidth() once, the fit to width does not work the second time.
Here is my code as an SSCCE and how it works...
1. (works) Mouse wheel will zoom in and out around the mouse pointer
2. (works) Left or right mouse press to drag the rectangle around
3. (works) Left double-click to reset the zoom
4. (doesn't work) Right double-click to fit the width
My calculations to re-position the rectangle to the upper left of the pane and fit it (i.e. scale it up or down) to the width of the parent are incorrect.
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
[Code] ....
View Replies
View Related
Feb 18, 2014
I have a large text file of 1 GB size. I need to print the line when a matching word is found in a particular line. Below is the code I am using. But if there are many lines that has the matching word, it's taking lot of time. Any solution to print the lines much faster.
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if(line.contains("xyz")) {
System.out.println(line);
}
}
View Replies
View Related
Mar 16, 2015
I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so
Here is the code from my CardLayout:
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
[Code] ....
I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.
Here is the main important GUI from my CheckerBoard class:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
[Code] ....
Once again kept to a minimal.
View Replies
View Related
May 13, 2015
This is the code that I wrote but I have two problem with two buttons one of them ... I want to delete the selected text inside the text Area which represented as b[8] and the other button that I want to select parts of the texts which represented as b[0]....
Here is the code..
package KOSAR2;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
[Code] .....
View Replies
View Related
Dec 12, 2014
I am checking how to do following task.
01. pickup the selected text file and read the line by line and output the text in to visual text pane.
what i did:.
01. I wrote code that read the text file and output in to jave console/ also some of the interface.
the code read txt file:
Java Code:
String fileName = "C:/Users/lakshan/Desktop/lawyer.txt";
File textFile = new File(fileName);
Scanner in = new Scanner (textFile);
while(in.hasNextLine()){
[code]....
so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?
View Replies
View Related
Mar 24, 2014
this is my first java game im making i tried to add tiles to the screen but i just get a black screen with no errors?
View Replies
View Related
Apr 2, 2014
How to clear console screen ? I am using Linux machine.
1) Runtime.getRuntime().exec("clear"); // this is not working. Not clearing the screen
2) for ( int i = 0; i < SOME_NUMBER; i++)
System.out.println();
2nd way is working but i think it is not a good option as i need to move scroll bar again and again.
View Replies
View Related
Oct 9, 2014
in my JSF2 app I have screens composed with :
- Header
- Body
In the header I have a combo list. At each change in value in the combo list I have an Ajax request that updates the data in the Body. So far everything is working properly. Now the home screen's structure should be change when the value of combo list change. To do this I have :
- 1 ManagedBean HomeBean that manage the home
- 1 ManagedBean HeaderBean that manage the header
- 2 object HomeScreen1.java and HomeScreen2.java that allows me to valued data from each screen
- 2 services HomeScreen1Loader.java and HomeScreen2Loader.java that manage loading of each type of screen
- 1 template home.xhtml
- 2 fichier home1.xhtml et home2.xhtml
When I log in to the application, I get the good page corresponding (Element type 1 => home page 1). But when I select a type 2 item, the actionListener methode is execute, ManagedBean's data was updated (for type 2 screen) , but the page does not updated. What do you do ?
HeaderBean.java :
package com.omb.view;
import java.io.Serializable;
import java.util.List;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
[Code] .....
View Replies
View Related
Jan 30, 2014
I was working on adding a selector on the screen. Searching for code, I found something that some created better than I ever could. I'm trying to integrate it into my code.
I have a program that is pretty MVC.
I'm in my controller class and I'm calling this code:
java - Drawing a bounding rectangle to select what area to record - Stack Overflow
I've changed it to a runnable and called a wait after I called this class, but it still continues on to the next line.
I'm thinking I'll have to either create a super controller (one that manages two controllers and have a multiple set of views and models) because I'll have multiple views or I'll have to figure out how to wait for it to finish as a thread. As mentioned above, wait() doesn't work.
This is the code in my controller after I changed it back from a Runnable:
SelectionRectangle m_rect = new SelectionRectangle();
//Thread m_thread = new Thread(m_rect);
//m_thread.start();
TopLeft = m_rect.getTopLeft();
BottomRight = m_rect.getBottomRight();
C_view.setText(TopLeft.toString());
View Replies
View Related
Apr 29, 2014
I'm having an issue with a swing application I'm working on. Java version is 4 (I know...). I have a main screen panel with multiple sub-panels (rows). Each of these row panels contains an additional 2 sub-panels. One of these 2 sub-panels contains buttons. When 1 button is pressed, I want to disable all of the buttons on-screen (or any other way of blocking user input) until a background event finishes. The row panels do not know about each other.
The first thing I have tried doing is, when a button is pressed, getting the parent. Using the parent I then iterate through its components, and so on until I'm iterating through the buttons. For each button, I am doing a .setEnabled(false); However, this does not work, why. I've also tried wrapping this process in SwingUtilities.invokeLater() out of desperation, but that didn't work either.
What would be the cleanest way to disable all buttons? Or block all user input? I've also tried adding an opaque dialog which hasn't worked. Last resort would be maintaining some sort of button list, but I'd rather not.
View Replies
View Related
Jan 20, 2014
I just started taking a Java class and i'm having problems with this code,
I'm trying to add up the 4 numbers have them print out on screen.
public class finalGrade
{
public static void main(String[] arg)
{
double pLp = 28.3; //Participation, lab work, and programming
[Code] .....
View Replies
View Related
May 16, 2014
how to access my rrmLogin from the web?
With JSP can do? How do it? or exist other way? or: [URL] ....
I tested (i need some configuration): [URL] .... but this method download the jar file (and other libraries) right? and the program act same as a Desktop app, right?
View Replies
View Related
Feb 7, 2014
I am trying to draw an image unto the screen, however, nothing appears...
Java Code:
private ImageIcon i = new ImageIcon("image.png");
private Image image;
...
image = i.getImage();
...
g.drawImage(image, (int)(x - r), (int)(y - r), null); mh_sh_highlight_all('java');
Am I doing it right? The program gives me no error, it's just that when I try to draw it, I see nothing.
View Replies
View Related
Apr 10, 2014
I have a program thats ran over a network and is multi-player. However whenever I fire any bullets they do not fire on the other clients screen. Here's the code
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.util.*;
public class TankWar {
[Code] ....
View Replies
View Related
Jan 30, 2015
Haven't used java in a long long time and firstly need to know if its possible to build an app to replicate my ipad touch so that I can loop it between two different points on the screen. Friend recommended I got netbeans to get me started but wanted to ensure its possible before I get started.
View Replies
View Related
Feb 11, 2015
I had developed small GUI using swing group layout, which is nice to see on windows, but when I tried it on Linux the GUI look is varied. Then I set the GUI height and width by taking screen resolution, still it is varies the screen look. How I can make the GUI such that it looks the same on all screen resolutions.
View Replies
View Related
Sep 22, 2014
I am making a game and i am trying to have enemies spawn slight off the screen and randomly each time the game is run. I can get them to spawn randomly but i cant seem to get them off the screen properly ( when i do they take too long to enter the screen).
here is the code
for(int b = 0; b < GamePanel.enemy_amount; b++){
GamePanel.enemy.add(new Enemy((int)(Math.random() * 4000),(int)(Math.random() * 200)));
}
here is the width and height of the JFrame
setSize(1200, 800);
View Replies
View Related