I wish to print the content of a JTextArea. I know I can do this with textarea.print(). However, I wish to print in a different font, font size and orientation from that of the JTextArea itself. I have been able to change the orientation by setting print attributes
PrintRequestAttributeSet printAttributes =
new javax.print.attribute.HashPrintRequestAttributeSet ();
printAttributes.add(javax.print.attribute.standard .OrientationRequested.LANDSCAPE);
And then using the textarea.print() method that allows me to set attributes. However, I haven't found any way to set the font and font size.
I am quite familiar with using JOptionPane and its various displayXDialog() methods and reasonably familiar with changing fonts.
I have a JOptionPane.displayMessageDialog() that is working fine but I decided to make the font larger.
I found an example from which I coded:
Font font = UIManager.getFont("OptionPane.font"); UIManager.put("OptionPane.font", new Font(font.getName(), font.getStyle(), 24)); font = UIManager.getFont("OptionPane.font"); JOptionPane.showMessageDialog(this, "Welcome to Mover", "About Mover", -1); // no icon
After the UIManager.getFont() call after the UIManager.put() call, font shows the new font size of 24, but the showMessageDialog() dialog still has the default font.
And yes I understand that, when this works, it will affect every JOptionPane in my program.
I also tried:
Font font = UIManager.getFont("OptionPane.font"); JOptionPane message = new JOptionPane("Welcome to Mover", JOptionPane.INFORMATION_MESSAGE); JDialog dlg = message.createDialog("About Mover");
[Code] ....
This gave me a dialog with the default font and an unwanted icon.
So I tried
// both Font font = UIManager.getFont("Dialog.font"); // and Font font = UIManager.getFont("JDialog.font");
and planned to use that font in my setFont() call but font was null.
So, I have a game. I would like to make a game where you press "start" and THEN it starts. Also, I want to have collision with triangles, not just squares. The way I handle collision right now is with if statements, if the object is within the other, game over.How would I do collision with triangles? Lastly, how do I set a high score? how to change fonts and font size in swing?
I am having problem with the JRadio Buttons to change the font color in my code. What needs to be done? Also if I were to connect this GUI to another GUI and save font colors, how would I go about that?
I am using Swing, I have a JPanel and in it there is a JTextArea and a JButton. I want the JTextArea to move when the button is clicked on. I'm Not really sure how to do the action listener for the button. at the moment the JTextArea only moves once when the button is clicked on, but i want it to move every time the button is clicked on.
This is what i have so far:
moveButton = new JButton("MOVE"); moveButton.setName("move"); moveButton.setBounds(20, 140, 70, 40); text = new JTextArea("hello"); text.setEditable(false); text.setBounds(x, 50, 40, 20); panel.add(moveButton); panel.add(text);
In the actionPerformed method this is what it does:
I have to do a small program about parking. In the 2-d array (parking lot), contains different kinds of cars, the user have to :
1)enter which car he wanna move, 2)what direction (w,a,s,d) and after that, 3) how many moves( not out of bound) he wants to make, and finally 4) we print out the new parking lot for his next move
And i am stuck at how to move the car to corresponding position and then prompt user for the next move?
For example:
I want to move A to the right by 1 (d)
擷取.PNG print result: 擷取1.PNG
How do I do that? The code that i have right now
public class CarParkGame { public static void main( String [] args) { String carPark[][] = new String [6][6] ; carPark[0] = new String[] {"A","A","A","0","0","0"}; carPark[1] = new String[] {"b","0","0","0","0","c"}; carPark[2] = new String[] {"b","X","X","0","0","c","<exit>"};
I get a Base64Encoded image string (GIF format) from an external system. While reading the byte array and saving the image to file, the image gets saved in landscape orientation. The code snippet is below.
I need to find the Winner using Object Orientation logic I have my old logic from my Tic Tac Toe game but it is not Object Orientated. So I want to convert it and add that code to my GUI Tic Tac Toe. I need to return a winner or tie.
I am new to applets and I am trying to create a program to display color and font. See my code below, I am getting some errors below.
import java.awt.Graphics; //program uses class Graphics import javax.swing.JApplet; //program uses class JApplet import javax.swing.JOptionPane; //program uses class JOptionPane public class AdditionApplet extends JApplet { private double sum; //sum of values entered by user private double average; //average of values entered by user
[Code] .....
java:11: error: cannot find symbol Color skyBlue; ^ symbol: class Color location: class AdditionApplet java:12: error: cannot find symbol Font sansFont;
How do i set a random font in java and random position on screen. I've got random color but cannot get the font and position to change except for two times.
import javax.swing.*; import java.awt.*; import java.util.Random; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class JChangeSizeAndColor extends JPanel implements ActionListener { private Random generator;
It's very simple, I've added an AWT component/control (specifically a Choice object to a Frame. It's a pop-up menu by any other name.
Above the pop-up, there's a label. I'm trying to change its font to no success.
* I create Label object called label1: Label label1 = new Label("This is a pop-up") * I create a Font object called f: Font f = new Font("Times New Roman, Font.BOLD, 18) * I apply the new font to the label: (in AFrame's constructor) label1,setFont(f)
When displayed the label's font seems to be stuck on Arialor something similar. Changing the point size however does have an effect.
import java.awt.Choice; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; /** * Defines a 'pop-up' AWT control that will be added to AFrame. * It extends Choice - I may need extra functionality later. */
public class APopUp extends Choice implements ItemListener { // instance variables int noi; // no of items String selected; // item selected from choice
I am having some troubles with a program fileviewer where you must be able to change font style and size when pressing JButton "Set font". I have solved the most of the program and every menu button is working but I don't know how to set in FileListener class method to change the font when running in main class. Anyway, this is my FileListener class
Java Code:
import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.util.*; import java.awt.Font; public class FileListener implements ActionListener
The Font style constants are of int: int[] fontStyleList = new int[] {Font.PLAIN, Font.BOLD, Font.ITALIC};But what do I do when I want to add the names such as PLAIN etc. as the name of a menu item?
The following is not going to work, right!String[] parts = (fontStyleList[i].toString()).split("."); or String[] parts = ("" + fontStyleList[i]).split(".");rbStyle = new JRadioButtonMenuItem(parts[1]);
Is there another way to do this or should I just do another array with the names as a String?
I'm trying to display a phrase in every font size from 6 thru 20. As it stands now, the code below cascades the phrase, sort of, down the frame, but the font size doesn't change.
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JFontSizes extends JFrame implements ActionListener { JButton button = new JButton("Press Me"); String aPhrase = new String("This is a phrase.");
I'm working on Java-GUI implementation in Ubuntu. Used font-type in the application throughout is "Arial". At earlier stage of application it was the same font-type("Arial"). As the implementation grew the font-type has been changed automatically to another font type. It seems Serif-font type.
Now I could not able to figure out the problem; why it is so.
Note- I used HTML code also for setting font style of Dialog box messages and buttons. This is the only point which I figured out. Can it is ?
So I have been working on this code for a bit now... basically just supposed to be a display for a calculator, next week in my class we are learning about how to make it do stuff. so it's supposed to just look right for now. Should look something like this actually
My first question is this, how can I get the JTextArea to display over the top like the example?
My second question is I just started getting an error that compiled before, and I haven't changed anything about this line. Here is everything.
import java.awt.*; import java.awt.font.*; import javax.swing.*; @SuppressWarnings("serial") public class CalcDisplay extends JFrame{ String[] buttonText = {
[Code]...
the output looked something like this though note this is an old screengrab from while I was working on it. I have since gotten it to color correctly and I have a jtextarea below the numbers. though I need to get it to implement above the numbers and can't figure out how to do so the other example is what it should look like, disregard the color choice.The error I was getting appeared on line 36
Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method setLayout(LayoutManager) in the type Container is not applicable for the arguments (GridLayout) The constructor GridLayout(int, int, int, int) is undefined
at CalcDisplay.addComponentsToPane(CalcDisplay.java:36) at CalcDisplay.main(CalcDisplay.java:82)
This code has worked through the whole project and I haven't changed a thing.
I have a JFrame that houses a JScrollPane that houses a JTextArea (I set the console to output to the JTextArea). For some reason, when the frame appears, text is being printed like usual, but the scroll pane isn't rendered unless I hover over it or click on it. Also when I resize the frame, nothing appears unless I hover over it or click on it.
I've tried repainting the frame when everything is added to the frame and packed, but it doesn't change anything. I tried searching for other people who had the same problem, but most of them were relating to setting the layout to null (which I don't do) and using JPanels.
I created this JTextArea with some text in it. And it also has few variables.
Sth like that:
Java Code:
protected JTextArea textLog; textLog = new JTextArea(); textLog.append("test: "+variable); mh_sh_highlight_all('java');
And now while I use button that changes variable value, in textLog variable still shows old value.
Tried to use remove(textLog); textLog.validate(); etc(remove, validate, revalidate, add, repaint), because it works fine with JButtons, but still, in textLog variable gives me old value.
like "you should use somethingvalidate(); while clickin button and it will works", not some shit for 3032 lines with 99% of code that I don't need to do what I want.
I have a JTextArea that the user car resize. Now, I want to check if the JTextArea is displaying all the text in order to change the border color. The JTextArea line wrap is set to true. how to do this?
Every time I load a txt file into a JTextArea it prints the results to the JFrame incorrectly I notice its mainly the white spaces this is happening to. I have tried a few ways to remedy this problem but it still keeps occurring? I've tried append() read() also setText() even Scanner. I have enclosed a picture of my GUI and my txt file I am using.
I have dragged and dropped a jTextArea from netbeans palette onto my form. But when I right clicked for Event > action > actionPerformed for implementation, I realized such was not there, unlike the jTextField component. For example, I have tried this but it didn't work: