Click here to Skip to main content
11,934,425 members (52,834 online)
Click here to Skip to main content
Add your own
alternative version


33 bookmarked

Java 'Swing' style components written in MFC

, 23 May 2000
Rate this:
Please Sign up or sign in to vote.
A set of MFC classes the duplicate the Java Swing look and feel
<!-- Download Links -->
  • Download demo project - 77 Kb
  • <!-- Article image -->

    Sample Image - swing.jpg

    <!-- Main HTML starts here -->


    This library presents a set of MFC classes that replicate the Java Swing style controls.

    I sat down for two whole months to write this library. I was inspired from the cool GUI which Java Swing components offer. Although I tried to create the simulation as the same, in some places it was not possible. Win32 API does not have support to redraw a scrollbar. I also tried to make the combo box as good as possible. The progress bar looks even cooler, as does the slider. I hope you like these components - but email me if you have any bug fixes or suggestions.

    Note:The release version of this MFC extension dll will only work with with release versions of your application, and the debug version with the debug version of your application. Take care to avoid errors.

    To use the library

    First you need to compile the Swing libary. Unpack the downloaded zip and compile the project in the Swing/ directory. This will give you a swing.lib file for linking, and a swing.dll file that you application will use.

    In your project, be sure to include the "swing.h" header file, and also link to the swing.lib library file.

    To get the swing look and feel, set your dialog's background color in your application's InitInstance()

    SetDialogBkColor(RGB(204, 204, 204), RGB(0, 0, 0));

    Using class wizard create control variables for the controls. Then replace the variable types with those given below

    CButton (button) CSwingButton
    CButton (checkbox) CSwingCheckBox
    CButton (radio) CSwingRadio
    CEdit CSwingEdit
    CRichEditCtrl CSwingRichEditCtrl
    CProgressCtrl CSwingProgressCtrl
    CComboBox CSwingComboBox
    CSliderCtrl CSwingSliderCtrl
    CWnd CSwingBorderWnd

    To set the caption for a button use the function

    void SetButtonText (CString pstr)
    CString GetButtonText ()

    Simillarly for a checkbox and radio use:

    void SetRadioText (CString pstr)
    CString GetRadioText ()
    void SetCheckboxText (CString pstr)
    CString GetCheckboxText()

    For a progress bar use:

    void SetCaption (CString pstr)
    CString GetCaption ()

    You can also use following methods for check boxes and radios:

    void SetCheck (BOOL check)
    BOOL GetCheck ()

    As all the windows are derived classes, all the other member functions will work.

    There is a problem with radio buttons. You will have to set the control which comes after the last radio button of the last group also with the group property.

    I have also given the facilit where if there is a window which needs only a swing border, you can use the class wizard to create its variable and set its type to CSwingBorderWnd


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    No Biography provided

    You may also be interested in...

    Comments and Discussions

    GeneralMy vote of 1 Pin
    tinku5nov2-Nov-10 0:43
    membertinku5nov2-Nov-10 0:43 
    GeneralI like it. Pin
    greatghoul11-Oct-08 18:57
    membergreatghoul11-Oct-08 18:57 
    GeneralIt doesn't work using MFC as a static DLL Pin
    elove28-Oct-04 0:04
    memberelove28-Oct-04 0:04 
    Generalslider doesn't do tic marks Pin
    FrankRowe16-Jan-03 11:01
    memberFrankRowe16-Jan-03 11:01 
    GeneralRe: slider doesn't do tic marks Pin
    FrankRowe22-Jan-03 10:33
    memberFrankRowe22-Jan-03 10:33 
    GeneralSwing look for XP Pin
    Robert Pittenger6-Apr-02 17:43
    memberRobert Pittenger6-Apr-02 17:43 
    GeneralNice Intellictual Exercise, but . . . Pin
    Zac Howland20-Mar-02 6:24
    memberZac Howland20-Mar-02 6:24 
    GeneralRe: Nice Intellictual Exercise, but . . . Pin
    Brian O.5-Nov-02 13:09
    memberBrian O.5-Nov-02 13:09 
    GeneralYes, a wonderful intellictual exercise... Pin
    Anonymous15-Jul-03 7:19
    sussAnonymous15-Jul-03 7:19 
    GeneralYou should make another one of these on check boxes Pin
    LiquidKnight8-Mar-02 21:01
    memberLiquidKnight8-Mar-02 21:01 
    GeneralThis won't work. Pin
    Amanjit Gill28-Feb-02 15:46
    memberAmanjit Gill28-Feb-02 15:46 
    QuestionWhy??? Pin
    _XXX_4-Feb-02 8:50
    member_XXX_4-Feb-02 8:50 
    AnswerRe: Why??? Pin
    Anonymous19-Feb-02 8:05
    memberAnonymous19-Feb-02 8:05 
    GeneralRe: Why??? Pin
    Anonymous11-Mar-02 0:59
    memberAnonymous11-Mar-02 0:59 
    GeneralGood work Pin
    Nish [BusterBoy]27-Jan-02 2:04
    memberNish [BusterBoy]27-Jan-02 2:04 
    QuestionHow to create Java "Swing" Frame? Pin
    huwenwei4-Aug-00 20:04
    susshuwenwei4-Aug-00 20:04 
    GeneralNice sample, but one small little bug Pin
    Santosh Rao25-May-00 1:14
    sussSantosh Rao25-May-00 1:14 
    GeneralRe: Nice sample, but one small little bug Pin
    Stephan Poirier12-Feb-03 18:31
    sussStephan Poirier12-Feb-03 18:31 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.151126.1 | Last Updated 24 May 2000
    Article Copyright 2000 by Abhijit Bhole
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid