Java Loses Focus When Printing

Aug 1, 2014

I am working on a Java program to monitor meal consumption by members of an organization. They swipe their ID cards, enter PIN, and number of meals they want. System knows if dining room is open and what meal based on time. The system then prints out a receipt on an Epson TM-T88IV receipt printer.

The system is running in console mode. My problem is that when the system prints, a Notepad window pops up for milliseconds and then the Java program loses focus. The screen reverts back to Windows home screen. I'm using Windows XP, SP3 and the latest Java build.

How to prevent the loss of focus?

View Replies


ADVERTISEMENT

Batch Printing Of Files In Java

May 21, 2014

One challenging task in java i am facing is, batch printing of files in java .....

View Replies View Related

Printing Array Elements In Java

Oct 15, 2014

I have tried to print array elements using standard print statement. I am getting errors. How to print them. Here is my code:

class arrayEx1{
public static void main(String args[]) {
int a[]=new int[3]; //Declaring Single Diomentional Array
a[0]=10;
a[1]=20;
a[2]=30;
int total=a[0]+a[1]+a[2];
System.out.println("Values stored in a[0],a[1],a[2]elements are :" + a[0] a[1] a[2]);
System.out.println("Total values of a[0],a[1],a[2]elements is :"+ total);
}
}

if i give comma (,) in between above print stament (print statement 1) stil i am getting errors.

View Replies View Related

Printing From Java Application To USB Printer

Apr 28, 2014

How can I print to a USB printer from my Java application? I've always printed to network printers using IP addresses.

View Replies View Related

Java Printing HTML Document

Nov 18, 2014

My current calculator (currently available on my site) launches your default webbrowser with the CalculatorHistory file allowing you to print through your browser, but I been working on self contain the html page in a the JEditorPane which is great it does what i want, so I started working on the printing side and I am stuck...

The code I have was from a example (modified) but when I run the code I get the following error:

Exception in thread "main" java.lang.IllegalArgumentException: services must be non-null and non-empty
at javax.print.ServiceUI.printDialog(Unknown Source)
at gcclinux.co.uk.PrintReport.main(PrintReport.java:28)

The Line 28 equals to PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);

package gcclinux.co.uk;
import java.io.FileInputStream;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;

[Code] .....

View Replies View Related

Printing Textfile Through A Printer From Java

Jan 7, 2015

I want to print a text file from java by clicking on a JButton. How to use PrintJob for that?

View Replies View Related

Printing Asterisks Shape In Java

Mar 17, 2014

I am supposed to Write a program that prints a shape similar to the following shape. Maximize use of loops and minimize use of print statements.

.....*
....**
...***
..****
...***
....**
.....*

(without the "...")(i couldn't get it to stay in shape)

This is what i got so far:

Java Code: package assignment7;

public class Exercise3
{
public static void main (String[] args)
{
for (int count =0; count < 4; count++)
{
for (int j=0; j < count+1; j++)
[Code] ....

Tthis compiles to:

*
**
***
****
**
*

How do i center it to create the shape?

View Replies View Related

Printing Highest And Lowest Of Three Numbers Using Java?

Feb 23, 2014

I am working on an assignment but I am not getting any out put and I couldn't fix it?The class HighLow below asks for three integers and prints the highest and lowest of them on screen. Your task is to write the missing methods high and low, which receives the integers user inputs as parameters and return the highest and lowest integers respectively.

import java.util.Scanner;
public class HighLow {
public static void main(String[] args) {
int number1, number 2, number 3, high, low;
Scanner reader = new Scanner(System.in);

[code]......

View Replies View Related

Printing Highest And Lowest Of Three Numbers Using Java

Feb 23, 2014

The class HighLow below asks for three integers and prints the highest and lowest of them on screen. Your task is to write the missing methods high and low, which receives the integers user inputs as parameters and return the highest and lowest integers respectively.

import java.util.Scanner;
public class HighLow {
public static void main(String[] args) {
int number1, number 2, number 3, high, low;
Scanner reader = new Scanner(System.in);

[code]....

View Replies View Related

JSF :: Focus The First Element?

Apr 4, 2015

I'm creating a simple login screen and I need to focus on the first field "login" after I click a submit button, so when the page return. I tryed using JS :

window.onload = function() {document.forms[0].elements[0].focus();};

but it not worked. I need a solution if possible without using JS. I'm using raw JSF implementation without PrimeFaces or anything else like this.

View Replies View Related

How To Focus At One Component

Feb 23, 2014

I want to focus at a JTextField, how to do that? Can setfocusable work?

View Replies View Related

Java ArrayList - Printing Shopping Cart Receipts Project

Oct 26, 2014

I'm new to the concept of ArrayList and I want to solve this problem in my code.

My main problem: I don't know how to sort itemA and itemB to appear only once then It will just add the total prices together.

This is the behavior of my code:

C:Documents and SettingsDrewDesktop>java ReceiptCode
Enter Company Name
ABC Co
Enter STREET ADDRESS
123 Main Street
Enter CITY, STATE, ZIP

[Code] ....

I don't know how to sort itemA and itemB to appear only once then It will just add the total prices together. Here is my sourcecode:

ReceiptCode.java
import java.util.Scanner;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

[Code] ....

View Replies View Related

Who Keeps Track Of Which JComponent Has Focus

Aug 31, 2014

I have two JFrames: frame1 and frame2. frame2 currently has focus, and I want to determine which component of frame1 would have focus if I were to switch focus to frame1, hopefully without actually temporarily changing focus.

Is it the KeyboardFocusManager who keeps track of which element in each frame has focus? Or does each container itself keep track? How does Java figure out which element in a frame gets focus when I switch to that window?

View Replies View Related

Loop That Calculate Distance Traveled - Why Java Not Printing Method Results

Apr 13, 2014

I am trying to write a loop that calculates the distance traveled (distance = speed * time). It should use the loop to calc how far the vehicle traveled for each hour of time. My program asks for hours and then mph but its not calculating time * speed. Here is my code.

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
System.out.println("Enter Hours Traveled ");
int hoursTraveled = input.nextInt();
System.out.println("Enter MPH ");
int mph = input.nextInt();
 
[Code] .....

View Replies View Related

Swing/AWT/SWT :: Printing JTable - Java (TM) Platform SE Binary Has Stopped Working

Nov 19, 2014

I am getting the following message when trying to print a JTable.

"Java(TM) platform SE binary has stopped working"

Here is the code:

try {
MessageFormat headerFormat = new MessageFormat("Page {0}");
MessageFormat footerFormat = new MessageFormat("- {0} -");
table.print(JTable.PrintMode.FIT_WIDTH, headerFormat, footerFormat);
} catch (java.awt.print.PrinterException pe) {
System.err.println("Error printing: " + pe.getMessage());
}

View Replies View Related

Swing/AWT/SWT :: How To Customize Focus Traversal Through Tab Key

Apr 29, 2014

I'm facing a problem in controlling the focus traversal mechanism inside a jframe...as i want the focus to travel from top to bottom by pressing tab key regularly , but it travels left to right and then top to bottom through the textfields... The form looks like
textfield1 textfield4

textfield2 textfield5

textfield3

The focus travels from 1 to 4 , 2 to 5 and then rests at 3. but i want it to be like from 1 to 2 to 3 and then 4 and 5....

View Replies View Related

How To Get Keyboard Input Without Focus On The Frame

Jan 29, 2015

so i'm working in a chat program and i'm trying to make it so that you are able to open another tab yet still be able to chat.

right now the client that the user download uses the keyadapter to get the keyboard input, but whenever the user un-focus the chat window, the keyadapter no longer gets the keyboard input.so is there another way i can get the keyboard input? so it doesn't matter what window you are focused on, you get the keyboard input either way?

View Replies View Related

JTextField Cannot Be Edited After Requesting Focus

Oct 27, 2014

Im trying to embed swt browser in swing , the problem that I have is that i cant change the value of JTextField even when i request focus ,when i try to give input the input goes in the browser's page bar..

public static void main(String[] args) {
final SwtBrowserCanvas browserCanvas = new SwtBrowserCanvas();
final JTextField textField = new JTextField(15);

[Code]....

View Replies View Related

Swing/AWT/SWT :: How To Change Jbutton Color While It Is In Focus

Jan 27, 2013

refer to this code~

import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Color;
import javax.swing.JButton;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Have JDialog Dispose When Focus Is Lost?

Jan 21, 2014

This code will not dismiss the MemoryDateDialog when it loses focus, while it is what it is intended to do.

btnMemoryReason.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
List<MemoryDates> lMemoryDates = db.getMemoryDates(custID);
final MemoryDateDialog mdd = new MemoryDateDialog(lMemoryDates);

[URL] .....

View Replies View Related

Change Frame And Focus In Card Layout

Feb 18, 2014

I'm nearing the final development stages of my first game, but have run into a problem. I've constructed 4 different levels and allow the user to select the level they want to play from a central JPanel in a Card Layout system. My problem is that once a level is completed, I can't switch the JPanel which is displayed to start the next level, since I don't know how to access the original JPanel which acts as a driver for the other panels.

MainFrame.java

Java Code:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;

[Code] ....

View Replies View Related

JSF :: 1.2 - Add Focus To Certain Element On Page Using Custom Component

Apr 28, 2014

I don't know if this is possible before JSF2.0, but I got a requirement that basically says that I need to be able to add focus to a certain element on the page using a custom JSF 1.2 component.

Currently, I do this with a short jQuery method where you add a class called 'focus' to the inputText component you want focus on. This works perfectly, but I need to also foresee a nested component inside h:inputText to do this.

Example:

<h:inputText id="myFirstTextField" value="#{bean.someText}">
<o:focus/>
</h:inputText>

I had thought about just putting an element with a certain class and using a jQuery selector to get its parent, but then I realized the html input tag does not allow subtags and that couldn't work, so I need something that won't be rendered but will do the job.

Migrating is evidently not an option.

I'm using Seam 2.1.2 and richfaces 3.3.4

View Replies View Related

Swing/AWT/SWT :: How To Use Container Order Focus Traversal Policy

Feb 1, 2014

the focus traversal policy (hereafter "tab order") in forms and panels doesn't follow the order in which controls were inserted into the container, but is derived from the position of the components on the form or panel. This is very neat (and probably allows sloppy coders and GUI builders to exist without actually ever thinking about the tab order), except when it isn't. As when you actually want to specify a different component order, for example.

In the following example, I've created a form with two columns of buttons. I want the tab order to go through the first column of buttons, followed by second column of buttons (ie. a column-by-column schema). The default tab order is row-by-row, however, and can be obtained for reference by commenting out the setupFocus() call in the constructor.

I had hoped that the ContainerOrderFocusTraversalPolicy would do the job, but there is a couple of problems (which I've addressed in the setupFocus() method). Firstly, the container itself is part of the focus chain. This at least is easily remediable by calling setFocusable(false), but I don't have to do that with the initial focus traversal policy, so I wonder why I have to do it with this one. The other problem is more pressing, though - the ContainerOrderFocusTraversalPolicy lets me (un)hapilly tab through JLabels. Again, I've fixed this, but the initial policy knows all by itself that it's not a good idea to focus a JLabel. Moreover, I'm afraid there might be other components that do not receive focus with the original policy, but ContainerOrderFocusTraversalPolicy might plod though them.

isn't there some focus traversal policy implementation that I could just set and it would tab through exactly the same components as the original policy, except it would order them according to their order in the container?

Code:

package test;
import java.awt.Component;
import java.awt.ContainerOrderFocusTraversalPolicy;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

[code]...

View Replies View Related

Swing/AWT/SWT :: Give JTextArea Focus - Using It On A Panel And With JToolBar

Apr 21, 2014

I have a program with a main panel JPanel that implements KeyListener. I added a JTextArea to which I added as the KeyListener: this, meaning the main panel. I made the JTextArea fill the entire main panel because I want to catch a key press anywhere in the main panel.I catch the key presses and the program does what I want it to.

I added a JToolBar to the program; it is working just fine.Now that I have two components on the main panel - toolbar and panel with textarea -, the textarea must have the focus before it will send the KeyEvent and call keyPressed(). I don't want to expect the user to click on the main window to get the program to start or after each time they use the toolbar.

I have tried calling both requestFocus() and requestFocusInWindow() on the textarea; neither call worked. I put the toolbar at PAGE_END instead of PAGE_START; this worked to allow the program to start but I don't want to have the toolbar at the bottom and once I clicked on a toolbar button, the textarea lost the focus.

I need to be able to give the textarea the focus when the program starts and after the user uses a toolbar button. (I suspect that if I solve the problem when the program starts, I can use the same method after handling a button press.)

View Replies View Related

Swing/AWT/SWT :: JTable - Cell Keeps Focus After Clear Selection

May 7, 2014

I'm having a small problem using a jTable.

After calling the .clearSelection() methode of the table object, the cell clicked in when selecting the table row, keeps it's focus.

How do I remove the focus of the cell?

View Replies View Related

Focus Listener - JTable Stops Showing Data In It

Apr 5, 2014

public void createSearchArea(){
filterText = new JTextField("Search Here");
filterText.setForeground(Color.gray);
filterText.setBounds(130,5,950,25);
filterText.getDocument().addDocumentListener(
new DocumentListener() {

[Code] .....

I want to add a text to JTextField whenever the text field is clicked it should be removed and if user types nothing then it should come back.

I've used focus listener but on focus lost my JTable also stops showing data in it.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved