Resizing of JFrame while the font on buttons increases

Hey,
I would like to ask you how to resize my JFrame ,when the size of buttons put in this frame increases.
I mean the font on the buttons increases by 1 point every time I press the button. My goal is to make the two buttons visible all the time. Therefore I need to resize my JFrame. I tried in the following method, but it did not work :(
(cp is contentPane() of my JFrame - frame)
public void actionPerformed(ActionEvent e) {
Component c = (Component) e.getSource();
Integer nazwa= c.getFont().getSize()+1;
int width = (int) cp.getPreferredSize().getWidth();
if(cp.getPreferredSize().getWidth()>cp.getWidth()) {
cp.setSize(new Dimension(width, cp.getHeight()));
cp.validate();
int height = (int) cp.getPreferredSize().getHeight();
if(cp.getPreferredSize().getHeight()>cp.getHeight()) {
cp.setSize(new Dimension(cp.getWidth(),height));
cp.validate();
c.setFont( new Font(c.getName(), c.getFont().getStyle(), nazwa));
frame.validate();
}

pack() does not help, as I have already used it.
Pls find below the whole code of the program:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class GUI implements ActionListener{
final int BNUM = 2;
static JFrame frame = new JFrame()
static Container cp = frame.getContentPane();
GUI() {
cp.setLayout(new BoxLayout(cp, BoxLayout.X_AXIS));     
for (int i = 1; i <= BNUM; i++) {
JButton b = new JButton("Przycisk " + i);
b.addActionListener(this);
cp.add(b);
frame.pack();
frame.show();
public void actionPerformed(ActionEvent e) {
Component c = (Component) e.getSource();
Integer nazwa= c.getFont().getSize()+1;
int width = (int) Integer.parseInt(cp.getPreferredSize().getWidth().toString());
if(cp.getPreferredSize().getWidth()>cp.getWidth())
cp.setSize(new Dimension(width, cp.getHeight()));
if(cp.getPreferredSize().getHeight()>cp.getHeight()) {
cp.setSize(new Dimension(cp.getWidth(),cp.getPreferredSize().getHeight()));
cp.validate();
c.setFont( new Font(c.getName(), c.getFont().getStyle(), nazwa));
public static void main(String[] a) {
//cp.setPreferredSize(new Dimension(200,200));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new GUI(); }
}

Similar Messages

  • JDevelper10g can't  show the font in buttons!

    i installed jdeveloper10g preview edition,and when running it ,the jdev windows can't show fonts on button.
    our os environment is windows xp pro(eng),and switch to chinese region.

    The problem is the source for the image, you have
    <img src="X:\CVS Norge\94 Prosjekter\945
    Trading\SovReflex\Bilder\Thumbs\litenalarmpakke_it400.jpg"
    alt="test"
    border="0" align="top" id=""
    onclick="MM_goToURL('parent','produkter/prodDetal.cfm?ProdID=21');return
    document.MM_returnValue" />
    So the source for the image is referring to a filepath, ie
    X:\ rather than a
    web path, so you`ll only see the image on your computer
    connected to the X
    drive. You need to change it to a web relative path, and then
    it will work.
    Gareth
    http://www.phploginsuite.co.uk/
    PHP Login Suite V2 - 34 Server Behaviors to build a complete
    Login system.

  • Resizing and/or Moving the JFrame on the Screen

    Is there any way to resize a JFrame when the undecorated property is set to true.
    I would like to have a JFrame that is both undecorated and resizable.
    Similarly, I was also wondering how to move the JFrame on the screen if the
    undecorated property is set to true since there is not Border to select the
    JFrame to initiate the Move.
    Thanks!

    yes... setSize(), setLocation().
    And if you want the user to be able to do it with the mouse, you need to add a border to the rootpane to prevent anyone adding things over the whole rootpane, and add a mouse listener to it to catch mouse click and drag events and do the calculations.
    If you look at the BasicInternalFrameUI, or some thing in there should have some code that does the same thing.

  • Font size button does not appear when I read imported PDF books (in ibooks)

    I imported several books in PDF forman in my iPad 2, and I can read them fine, but the Font size button (A A  on the uper right corner) does not appear. I only have the brightness button (that only controls the brightness and nothing else), the Search and the Bookmark buttons. Any idea? Thanks.

    Thanks King_Penguin, I suspected that this would be the case but I wanted an expert oppinion. Thanks again.

  • How can you change the font size in the application and system headers?

    How can you change the font size in the application and system headers?  I searched the system and finder prefs to no avail.  Changing the screen density is not a good option.
    Thanks

    I downloaded Tinkertool.  Found the font section and increased the size of most selections.  The only thing that changed that I can see is the window label.  The apple line, bookmarks line, the tool bar in safari are all the same---font size of about 4.  Found the finder "show view options" but that didn't seem to change anything either.  I'll keep working.  Restarted all apps after changes as well.

  • How to resize the components in a JFrame when the JFrame Resizes?

    Hi all,
    i have some problems with my app. I have set the JFrame resizable and that works fine for the JFrame but not for the components in the JFrame.
    So my question is how can i set the components in a JFrame to resize automatically when the JFrame resizes?
    Here are the important things from my code,...if you need more, just let me know, its my first post in a forum .
    Its a JFrame with a JTabbedPane and on the Tabs are Panels with buttons and Tables.
    Thank you in advance!
    public class MainMonitor extends JFrame {
    public MainMonitor() {
              super();
              initialize();
              setVisible(true);
         private void initialize() {
              this.setSize(1145, 785);
              this.setIconImage(Toolkit.getDefaultToolkit().getImage("Images/c.gif"));
              this.setContentPane(getJContentPane());
              this.setTitle("Company Manager");
              this.setResizable(true);
              this.setLocationRelativeTo(null);
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.setOpaque(true);
                   jContentPane.add(getJTabbedPane(), null);
                   jContentPane.add(getJPanel11(), null);
              return jContentPane;
         private JTabbedPane getJTabbedPane() {
              if (jTabbedPane == null) {
                   jTabbedPane = new JTabbedPane();
                   jTabbedPane.setLocation(new Point(6, 69));
                   jTabbedPane.setSize(new Dimension(1120, 684));
                   jTabbedPane.addTab("P", null, getJPanel(), null);
                   jTabbedPane.addTab("K", null, getJPanel1(), null);
                   jTabbedPane.addTab("B", null, getJPanel2(), null);
              return jTabbedPane;
         

    Giasaste wrote:
    Thanks a lot, i didnt knew that the Layout Manager is a must.It's not a must, but it is the way to allow your app to be resized nicely and makes it much easier to maintain and enhance your program. Imagine creating a complex gui then later decide that you want another radiobutton and to remove a jlabel / jtextfield pair. with layout managers a chore becomes easy.

  • Does anyone know how to select text in Appleworks, click on the font button and then be able to scroll thru all the font so that one can see the text change as you scroll down the list, at present  I have to do it one font style at a time and then repeat

    does anyone know how to view text in Appleworks, to be able to click on the font button and then be able to scroll thru all the font so that one can see it change as you scroll down the list, at present  I have to do it one font style at a time and then repeat? Thanks jl

    Welcome to the Apple forums
    Your question really belongs in the AppleWorks community/forum.
    You can turn on fonts in actual type in the AppleWorks preferences.

  • HT201263 When my Ipod touch is in autolock I can only restart the device holding the sleep/wake button and home button at the same time for 10 seconds.  While in auto-lock it is using battery power and will do so until the battery is drained.  Whats wrong

    When my Ipod touch is in autolock I can only restart the device holding the sleep/wake button and home button at the same time for 10 seconds.  While in auto-lock it is using battery power and will do so until the battery is drained.  Whats wrong?

    - Try a reset. Nothing is lost:
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears
    - Connect the iPod to your computer and try to restore via iTunes. Try placing in Recovery mode if necessary to restore.
    - If you can't turn the iPod completely off, let the batter fully drain. After charging for at lerast anhour try again
    - If still not successful time for an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.

  • InDesign doesn't let embed the font while exporting to PDF

    I used a font while working on a document in InDesign and later while exporting to PDF I got a warning that the software is unable to include that font.
    Is there a way to go around it? It was a free cyrillic font and it's not possible to buy it. I suppose creating outlines is not the right way to go
    Thanks in advance

    Eugene Tyson wrote:
    … Most free fonts that I know of don't allow embedding - for this reason it's not a good idea to use a free font. …
    I'm no particular fan of so-called “free fonts” — you most often get exactly what you pay for. However, that having been said, in my years of gathering such fonts for debugging and problem solving, in fact very few of them are actually set with the protection bits to prohibit embedding. For TrueType and OpenType fonts, you can readily check outside of InDesign as to whether a font is embeddable in a PDF file. For Windows, right-click on a font file and check the properties; embedding privileges are described in one of the tabs. For MacOS, the FontBook utility can provide the same information for a font.
    The problem is that when you attempt to use a font that is physically protected against embedding, you pretty much need to follow the advice given by Eugene. Personally, I would recommend the use a different font option, checking the font prior to using it for your rights to embed it in PDF.
    Note that font licensing is legal minefield. Many fonts that are posted on-line are not really free. Some are shareware with restrictions in their written licenses that require payment for commercial use (often in ReadMe files which may somehow be “lost” when such fonts are reposted over and over again) or even pirated fonts (i.e., commercial fonts simply illegally posted on-line).
    My personal recommendation is that for any commercial use, you explicitly license your fonts from a known, reliable source to avoid possible legal issues in the future.
              - Dov

  • While editing a scanned pdf, Acrobat will not recognize the current font & change to very different font. How can I choose the font I want to match the current document?

    While editing a scanned pdf, Acrobat will not recognize the current font & change to very different font. How can I choose the font I want to match the current document?

     Thanks for answering. The version is XI.0.10. I just did the update yesterday hoping that I could now properly edit a scanned pdf document. Yes, it's happening on most all scanned documents. I followed your steps & found the list of fonts used in the document & then attempted to edit. The same occurs. When I type in a correction, I get an error alert... "the original font (in this case Fd 5805) is not available or can't be used in editing. Acrobat is using the font Minion Pro in its place." 
    When I select the text & right click as you suggested, my only choices are cut, copy, delete or select all, no "edit text".
    I have no other options to choose another font. Thanks for any help you can direct my way. 
    Debbie
          From: sukritd15 <[email protected]>
    To: Deborah Karr <[email protected]>
    Sent: Friday, February 13, 2015 5:35 AM
    Subject:  While editing a scanned pdf, Acrobat will not recognize the current font & change to very different font. How can I choose the font I want to match the current document?
    While editing a scanned pdf, Acrobat will not recognize the current font & change to very different font. How can I choose the font I want to match the current document?
    created by sukritd15 in Creating, Editing & Exporting PDFs - View the full discussionHi Deborah , I would like to know couple of things before I assist you further.1.Which version of Acrobat are you using ?2.Is it happening for all the scanned PDF' or any particular PDF? You can try these steps,Launch the scanned PDF >right click >Document Properties(from the drop down list) >Fonts(on the dialog box)>From here you will get the fonts used in that PDF . While editing the PDF ,select the text that are editing or typing in with the help of selection tool .After you select the text ,right click on the text and choose "edit text" from the drop down list .From there you will be able to choose the desired font . RegardsSukrit Dhingra If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/7190881#7190881 and clicking ‘Correct’ below the answer Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/7190881#7190881 To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, & "Stop Following"  Start a new discussion in Creating, Editing & Exporting PDFs by email or at Adobe Community For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624.

  • I have an iPad 1st generation that no longer has working volume buttons but every once in a while the sound turns on.  So I know the speakers still work.  I have tried resetting all settings and made sure that my side switch was auto lock not auto mute.

    I have an iPad 1st generation that no longer has working volume buttons but every once in a while the sound turns on.  So I know the speakers still work.  I have tried resetting all settings and made sure that my side switch was auto lock not auto mute. I have tried the mystical swiping upward on the screen with 4 fingers to get some special sound menu (which I never succeeded in getting).  My headphone jack doesn't work all the time either so some times my kids can hear their games and sometimes they can't.  I am super frustrated at this point.  So any suggestions would be great.  Am I missing something basic or do we just have a soundless iPad now?

    http://www.atreks.com/app-no-sound-on-ipad-4-%E2%80%93-what-to-do/
     Cheers, Tom

  • My ipod nano 6th generation does not start on pressing the sleep/pause button  or pressing both sound low and sleep pause button.it starts while connected to power it is fully charges

    i have an ipod nano 6th generation .version 1.2 yesterday i  restored it on i tunes  using my system window 7. for the last few days it does not start when the sleep/pause button is pressed.or even by pressing the both button sleep/pause and sound minus..It starts while connected to power. and then continues working. I can not put off it and it automatically goes off after some time its performance is ok  after starting by connecting to power and then disconnecting the cord.
    what would be the reason and what to do?>

    Call Apple Care as you are still under warranty.  

  • I am trying to set up my newly purchased Apple TV but when I enter my network password while setting up, I am not able to enter the Submit button, any idea how to hit the visible submit button that is visible on screen but not responding?

    I am trying to set up my newly purchased Apple TV but when I enter my network password while setting up, I am not able to enter the Submit button, any idea how to hit the visible submit button that is visible on screen but not responding?

    You need to use the right arrow on the remote to go all the way to the right. The submit button will be highlighted and you can then press select on the remote to proceed.

  • My classic has come up with a sreen which 5 lins of text (in large font) Line 1  says 5 in 1 line 2 sdrampass L3 chksum any ideas I've tried the MENU   CENTRE BUTTON with no joy HELP

    My classic has come up with a screen which has 5 lines of text (in large font) Line 1 says 5 in 1 Line 2 sdrampass L3 chksum Any ideas ? I've tried the MENU + CENTRE BUTTON with no joy HELP

    Hi starbugdriver,
    I recommend trying the iPod classic troubleshooting assistant here:
    iPod classic Troubleshooting Assistant
    http://www.apple.com/support/ipod/five_rs/classic/
    Have a good one!
    - Ari

  • In "purchases" while in my App Store, Mountain Lion says, "an error has occurred" and the green 'download' button is grey and I cannot re-start the download. I was abroad when I purchased this app and during download, my internet connection was lost.

    In "purchases" while in my App Store, Mountain Lion says, "an error has occurred" and the green 'download' button is grey and I cannot re-start the download. I was abroad when I purchased this app and during download, my internet connection was lost. At the time, Apple was still offering the e-chat, so I did that and the man was very helpful and it was a quick fix, so my download button turned green again, and I was able to begin the download. BUT during the download, I was kicked offline once again, and I decided to wait until I was back in the USA. I will go in to an Apple store and ask assistance, but if there is something I am missing, I'd like to try that first. Thanks in advance for any advice.

    Welcome to the support forums.
    Please ask this question in the Mac App Store forum where they can better assist you.

Maybe you are looking for

  • About BBPUPDVD and BBPMAININT

    Hello people, I think I have a basic question for you... I have may vendors defined in R3 in some Purchasing Organizations. And I have to transfer this information to EBP. I know I can use BBPUPDVD to update the vendors catalog in EBP from R3. If thi

  • ITunes crashes when I view music library in Cover-Flow view.

    *Whenever I try to view my music library in cover-flow mode iTunes freezes. The only way I can close it is to use Task Manager to stop the iTunes.exe process.* I can then restart iTunes which works fine until I try to switch to Cover-Flow view and it

  • Where-used list for class-based exception texts

    G'Day, With traditional exceptions, one can look at a message, go to SE91 and do a where-used for that particular message. This is not possible with ZCX classes, a where-used can be done for the entire class but there doesn't seem to be a way to find

  • Document Journal

    Hi FI Gurus, I would like to change the report description that I can see in the output. How can I change "Document Journal" in a different description? Thanks a lot in advance. Best regards. Antonio.

  • NIC teaming and direct access in windows 2012 server core

    Hello All, I have installed windows 2012 r2 server core and i want to implement direct access with nic teaming enabled. Has anyone tried this kind of setup? Were they successful in it? Moreover can we configure Direct access when we have NIC teaming