473,657 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Specify Font Size

1 New Member
Hello All, I'm not very good at Java...

With this piece of Java code, how could I modify the StyleOptions.ja va program to allow the user to specify the size of the font, while using the text field to obtain the user’s input.

Thanks.
-----------------------------------------------------------------

import javax.swing.*;
import java.awt.*;
import java.awt.event. *;

public class StyleOptionsPan el extends JPanel
{
private JLabel saying;
private JCheckBox bold, italic;


public StyleOptionsPan el()
{
saying = new JLabel ("Say it with style!");
saying.setFont (new Font ("Helvetica" , Font.PLAIN, 36));

bold = new JCheckBox ("Bold");
bold.setBackgro und (Color.cyan);
italic = new JCheckBox ("Italic");
italic.setBackg round (Color.cyan);


StyleListener listener = new StyleListener() ;
bold.addItemLis tener (listener);
italic.addItemL istener (listener);

add (saying);
add (bold);
add (italic);

setBackground (Color.cyan);
setPreferredSiz e (new Dimension(300, 100));
}

private class StyleListener implements ItemListener
{
//--------------------------------------------------------------
// Updates the style of the label font style.
//--------------------------------------------------------------
public void itemStateChange d (ItemEvent event)
{
int style = Font.PLAIN;

if (bold.isSelecte d())
style = Font.BOLD;

if (italic.isSelec ted())
style += Font.ITALIC;

saying.setFont (new Font ("Helvetica" , style, 36));
}
}
}
=============== =============== =============== ======

import javax.swing.JFr ame;

public class StyleOptions
{

public static void main (String[] args)
{
JFrame frame = new JFrame ("Style Options");
frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);

StyleOptionsPan el panel = new StyleOptionsPan el();
frame.getConten tPane().add (panel);

frame.pack();
frame.setVisibl e(true);
}
}
Mar 23 '07 #1
1 8632
DeMan
1,806 Top Contributor
Maybe I missed the point, but you could add a button (or combo box or other thing) with a new listener....
Mar 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

115
7180
by: J | last post by:
I've run CSSCheck on my style sheets and I always get a warning similar to this: "font: bold 9pt/100% sans-serif Warning: Absolute length units should not generally be used on the Web ..." Yet if I use 'x-small' instead of 9pt, I get bigger type on IE6 and smaller type on Mozilla. My choices seem to be:
9
3770
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with body like <br><br> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1>
3
3222
by: Yeah | last post by:
I have an HTML table with two columns of text. Here's what it looks like: FIRST COLUMN (each cell is ID="date') Background orange, font Serif size 13px, aligned center SECOND COLUMN (each cell is class="entry") Background white with clickable text link (Sans-serif 11px, link black, visited blue, hover navyblue) The first column's content has been assigned CSS ID "date", in the above mentioned style. The second column's content has...
4
3487
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a snippet from my .css file: *************************** body { margin:0; padding:0;
7
2955
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and already formatted as "Shopping" ---Bold "for" -----Regular Now I want to underline whole text by preserving old style i.e. Bold and
16
3887
by: JD | last post by:
Hi guys What's the best way to specify font size using CSS? I try to avoid absolute units like pt and px because then users can't resize the fonts in IE, but % and em are a complete pain to use IMO. I read somewhere (a W3C tip I think) that the best way is to specify a "base" size and then have all your fonts relative that, but I'm not sure how that works. TIA
7
3040
by: Daniel Kaplan | last post by:
I have the item below at the top of my style sheet. And it seems that the font-szie is ignored. I know that my linked style sheet is being read, and used because if I remove the font-family line, the font changes. But it appears that no matter what I do with the font-size, it is ignored, and I cannot figure out why! Any clues? At the very bottom is the entire style sheet, just incase anyone comes accross something that they feel is...
10
1711
by: Yeah | last post by:
Is there a way to tell CSS to specify one font for a table that has many cells in which the font is being used? As in, one font that represents the table itself (rather than specifying in every cell) Thanks! :-)
0
1101
by: Dino123 | last post by:
Hi I have a page written in VBScript, which uses values from a page posted to it, to send an e-mail. The problem is that when I try to specify a control within the page I get an error, saying "Object Required : Document". Here is a the code: <%@ Language=VBScript %> <% Dim szMail szMail = "<form id= SendAccounting name = SendAccounting language=VBScript>"&_ "<table>"&_
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7333
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.