Changing JFrame/JWindow shape

Hi,
Is there a way to change the shape of a JFrame of JWindow?
So instead of the usual rectangle, say, a circle or anything else
I choose?
Cheers.

I don't believe so. You can take a look at the source code (free to download) for those classes and see if anything can be done in the painting to make part of the window transparent. I suspect there is native code involved in rendering a JFrame or JWindow so I don't think you'll have much luck.
Take a look at http://www.l2fprod.com/index.php. They have custom shapes but it appears just for Windows (requires native code).

Similar Messages

  • How to change JFrame Defult Shape ?

    Hello All,
    JFrame defult shape is rectanguler, i want to change it
    in oval shape or circluer shape or any other shape.
    Any body tell me how it is posible, if any example code then please
    Help.
    i m thanksfull.
    Arif.

    Its somehow a tedious job and I havent tryied that!
    You have to make use of JNI.

  • How we can change JFrame Border Color Not Background.

    How we change jframe border color not background
    if any body know about that then plz tell me
    at this [email protected]
    i m thanksfull to ..... .

    hi Shafr
    beleive it or not, i got it using trial and error. i keep
    trying words in the function setStyle until the color changed. i
    dont know why it is not documented.
    var periodBarColor:SolidColor = new
    SolidColor(taskSchedColorChooser.selectedColor, 1);
    periodBar.setStyle("fill",periodBarColor);
    //where taskSchedColorChooser is colorPicker component. you
    can replace it by any color you want

  • Change jFrame to be jDialog

    I wrote a big application using mostly jFrames as pop up screens to collect data. I only realized now I should have used jDialogs instead. Is there a way to convert the jFrames to jDialog instead of writing all new??

    question is - is there a way to convert a jFrame to be a jDialog?They are the same. You use either:
    JFrame frame = new JFrame();
    or
    JDialog dialog = new JDialog();
    They both use a content pane and you add components to the content pane the same way whether its a frame or a dialog.
    So your question doesn't make sense. You go through the code and change JFrame to JDialog. That is the simplest way.
    Of course it is not the best design as was stated in the first reply.

  • Changing the JButton shape

    Hi All,
    The shape of JButton is usually a rectangle
    =========
    btnName
    =========
    but I want to change it's shape to Triangle or Circle like this
    o
    oooo
    o o
    o bntN o
    ooooooooooo
    can I do that with swing?
    Please help.
    Thanks,
    Long

    The easiest thing to do would be to create a triangular icon and put it on your button, then make the background of the button the same color as the background of the rest of your page. You may also need to remove the border by doing
    setMargin(new Insets(0, 0, 0, 0));

  • Know how to change the outline shape of a tooltip?

    Hi All,
    I was wondering if anybody knows how to change the shape of a tooltip popup box?
    I've implemented my own UI delegate for ToolTipUI and overridden the paint( Graphics g, JComponent c ) method which I thought would have allowed me to completely control the rendering of the tooltip, box and all. But what I discovered was that even when I did nothing inside this method, the rectangular popup window was still appearing (I stepped through the code, and the correct instance of UI was being used, not the one that may have been defined by UIManager.set( "ToolTipUI", "foo.Bar" )) After a little more investigation, I ended up in ToolTipManager.showTipWindow() which eventually calls
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    tipWindow = popupFactory.getPopup(insideComponent, tip, location.x, location.y);
    tipWindow.show();To try to overcome this, as a test I extended JButton with the following constructor:
    public TestButton() {
        super();
        setUI( new MyCustomUI() );
        ToolTipManager.sharedInstance().unregisterComponent( this );
    }but this didn't solve the problem either. Has anybody got any ideas on this?
    Cheers,
    Paul.

    Try this.
    regards,
    Stas
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    public class Test {
        JScrollPane scroll;
        JPanel p=new JPanel(new BorderLayout());
        Robot robot=new Robot();
        public Test()  throws Exception {
            final JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(p);
            JButton b=new JButton("Test balloon!");
            b.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    TransparentFrame frame1=new TransparentFrame();
                    int x=frame.getX()-100;
                    if (x<0) x=0;
                    int y=frame.getY()-100;
                    if (y<0) y=0;
                    frame1.setBounds(x,y,100,100);
                    frame1.createBalloon();
                    frame1.setVisible(true);
            frame.getContentPane().add(b);
            frame.setBounds(200,200,120,50);
            frame.show();
        public static void main(String[] args) throws Exception {
            new Test();
    class TransparentFrame extends JWindow {
        Robot robot;
        BufferedImage screenImg;
        Rectangle screenRect;
        MyPanel contentPanel=new MyPanel();
        boolean userActivate=false;
        Area Balloon;
        public TransparentFrame() {
            super();
            createScreenImage();
            contentPanel.Balloon=Balloon;
            this.setContentPane(contentPanel);
            this.addComponentListener(new ComponentAdapter() {
                public void componentHidden(ComponentEvent e) {}
                public void componentMoved(ComponentEvent e) {
                    resetUnderImg();
                    repaint();
                public void componentResized(ComponentEvent e) {
                    resetUnderImg();
                    repaint();
                public void componentShown(ComponentEvent e) {}
            this.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                public void windowClosed(WindowEvent e) {
                public void windowOpened(WindowEvent e) {
                public void windowIconified(WindowEvent e) {
                public void windowDeiconified(WindowEvent e) {
                public void windowActivated(WindowEvent e) {
                public void windowDeactivated(WindowEvent e) {
                    Balloon=null;
        protected void createScreenImage() {
            try {
                if (robot==null)
                    robot=new Robot();
            catch (AWTException ex) {
                ex.printStackTrace();
            Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
            screenRect=new Rectangle(0,0,screenSize.width,screenSize.height);
            screenImg=robot.createScreenCapture(screenRect);
        public void createBalloon() {
            Rectangle bounds=new Rectangle(0,0,getWidth(),getHeight());
            Balloon=new Area(new Rectangle(bounds));
            System.err.println(Balloon.getBounds());
            RoundRectangle2D content=new RoundRectangle2D.Double(0,0,getWidth(),getHeight()/3,20,20);
            Polygon polygon=new Polygon(new int[] {20,getWidth()/2,getWidth()},new int[] {getHeight()/3,getHeight()/3,getHeight()},3);
            Area a=new Area(new Rectangle(bounds));
            a.subtract(new Area(content));
            a.subtract(new Area(polygon));
            Balloon.subtract(a);
            contentPanel.Balloon=Balloon;
        public void resetUnderImg() {
            if (robot!=null && screenImg!=null) {
                Rectangle frameRect=getBounds();
                int x=frameRect.x;
                contentPanel.paintX=0;
                contentPanel.paintY=0;
                if (x<0) {
                    contentPanel.paintX=-x;
                    x=0;
                int y=frameRect.y;
                if (y<0) {
                    contentPanel.paintY=-y;
                    y=0;
                int w=frameRect.width;
                if (x+w>screenImg.getWidth())
                    w=screenImg.getWidth()-x;
                int h=frameRect.height;
                if (y+h>screenImg.getHeight())
                    h=screenImg.getHeight()-y;
                contentPanel.underFrameImg=screenImg.getSubimage(x,y,w,h);
    class MyPanel extends JPanel {
        BufferedImage underFrameImg;
        Area Balloon;
        int paintX=0;
        int paintY=0;
        public MyPanel() {
            super();
            setOpaque(true);
        public void paint(Graphics g) {
            super.paint(g);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(underFrameImg,paintX,paintY,null);
            if (Balloon!=null) {
                g.setColor(Color.yellow);
                ((Graphics2D)g).fill(Balloon);
            g.setColor(Color.red);
            g.drawString("Balloon test!",10,20);
    }

  • Best way to change colour of shapes

    Hi, i am using the code below:
    public static Color shapeColor; for storing the current colour
    public void paint(Graphics g)
                Graphics2D g2D = (Graphics2D) g;
                for (Shape tempS : allShapes)
                    g2D.setPaint(shapeColor);
                    g2D.fill(tempS);
            } note that allShapes is an arraylist which stores all my shapes
    In another class i call the static variable and change it according to wat the user has selected.
    My problem is that when i change the colour, the colour for all my shapes change. For example if i create a shape with the colour green and then create another shape with colour blue, both will be blue.
    Thanks for your time.

    Ravi:
    Here's an example for you:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.Polygon;
    import java.util.ArrayList;
    import java.util.Random;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class Junk{
      Color[] starColor = {Color.RED, Color.WHITE, Color.BLUE};
      public Junk(){
        Random r = new Random();
        JFrame f = new JFrame("Junk");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        MyJPanel p = new MyJPanel();
        p.setBackground(Color.BLACK);
        Star star = null;
        for(int i=0; i<50; i++){
          star = new Star(new Point(r.nextInt(490), r.nextInt(490)));
          star.setColor(starColor[r.nextInt(3)]);
          p.add(star);
        f.add(p);
        f.pack();
        f.setVisible(true);
      public static void main(String[] args){
        new Junk();
      class Star extends Polygon{
       Point location = null;
       Color color = Color.YELLOW;
       public Star(Point location){
         int x = location.x;
         int y = location.y;
         this.location = location;
         this.addPoint(x, y+8);
         this.addPoint(x+8, y+8);
         this.addPoint(x+11, y);
         this.addPoint(x+14, y+8);
         this.addPoint(x+22, y+8);
         this.addPoint(x+17, y+12);
         this.addPoint(x+21, y+20);
         this.addPoint(x+11, y+14);
         this.addPoint(x+3, y+20);
         this.addPoint(x+6, y+12);
       public void setColor(Color color){
         this.color = color;
       public Color getColor(){
         return color;
      class MyJPanel extends JPanel{
        private ArrayList<Star> l = new ArrayList<Star>();
        public MyJPanel(){
          this.setPreferredSize(new Dimension(512, 512));
        public void add(Star star){
          l.add(star);
        public void paintComponent(Graphics g){
          super.paintComponent(g);
          for(Star star: l){
            g.setColor(star.getColor());
            g.fillPolygon(star);
    }

  • Change jFrame to JPanel

    I have a gui that uses Jframe how easy would it be to change it to use jPanel instead? would it just be a few tweeks or would i be basically writting my code again?
    Also kind of off topic but if any one could give there view i'd be very happy
    The class file that uses the GUI is for entering names and DOB's, the same class can also be used for reading it back in again (data gets saved to a file) in your opinion which would look best
    if i split the gui in half so the left side was for entering and the right hand side was for reading in or
    if i just had it so there was one lot of text fields which could be used to enter data and if you read in the file would show the data from the file?

    I have a gui that uses Jframe how easy would it be to change it to use jPanel instead?You already are already using panels most likely.
    All GUI's need a top level container (JFrame, JDialog or JWindow). To the top level container you add Swing components (JPanel, JButton, JTextField, JTable etc...).
    So your question doesn't make any sense.
    Take a look at the Swing tutorial which has a [url http://java.sun.com/docs/books/tutorial/uiswing/components/components.html]Visual Index of Swing Componentsurl. Click on each component and you will find example programs that use the component and you can see how the program is structured and use that approach in your design.

  • Background Color change JFrame

    I have to change the background color when the result is either too high or low. Program runs great except the background color doesn't change. And before you complain about my code, I hit the "CODE" button before and after my code in here and it does nothing. The videos wouldn't play. So I don't know how to add code correctly.
    import java.awt.*;
    import java.util.Random;
    import javax.swing.*;
    public class NumberGuess extends JFrame {
    Random rand = new Random ( ) ;
    int randomNumber = 1 + rand.nextInt(1000);
    int count = 0;
    private JFrame panel = new JFrame();
    private JFrame panelButtons = new JFrame();
    private JFrame panelBottom = new JFrame();
    private void compareResult() {
    int userInput = Integer.parseInt(tempTextField.getText().trim());
    if ( userInput > randomNumber )
    resultLabel.setText( "Too High. Try a lower number." );
    setBackgroundColor(Color.blue);
    private void setBackgroundColor(Color color)
    panel.setBackground(color);
    panelBottom.setBackground(color);
    panelButtons.setBackground(color);

    Goofy_1969 wrote:
    And before you complain about my code, I hit the "CODE" button before and after my code in here and it does nothing.Well, you did manage to create 2 empty code blocks though.
    I know this is New To Java, so I need to be nicer and most of you people don't probably have the intrinsic knowledge of "start tag" and "end tag".
    But still. All you need is to put your code between tags and everything will work great.
    AND HEY, There's the preview button too! So you can actually try and try and try until it works. It's just that programming is a difficult hobby and if you can't work the code tags, you really need to rethink whether you're ready for something that's actually complicated.
    (Also if you're not using the code tags, your code will totally get screwed up and people can't help you even if they wanted to.)
    As for your code, try using SwingUtilities.invokeLater(). That's the only way you can modify the GUI when you're not running in the event thread.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Cursor changes to X shape at certain sizes

    I currently am running Photoshop CS6 on Windows 7. When I am using the Brush or Pencil tools, sometimes the Cursor will change to a curved X shape. This appears to happen at certain sizes (between 65px to250px) and then goes back to the normal circle shape when larger or smaller. The brush itself paints normally but there are times where I need to know exactly what areas it is going to color. I am using the default brushes, no custom ones.
    I have attached a picture of what the cursor looks like when it changes:
    How do I make it so that this does not occur?

    How are your Photoshop cursor settings set and does this happen for all brush types tips etc,

  • Trying to change JFrame at eof

    Hello, very new to the community and to Java. My question is....I have created two JFrames, one to enter data and one to read two different files depending on user choice once they input their data. I would like for the JFrame to change the title once it reaches the end of the first file and starts reading the next. For example, the user clicks "view files" to display each file in the "blue" data file one at a time (meanwhile, the title reads "blue file") and once the "Blue" file reaches the end, it displays the "red" file data. This is when I want the title on the JFrame to switch to read "red file". I have completed the application already, so everything is being written and read. I only need to change the title. I don't need exact code or anything, I just need to know whi ch method to use to do this. Thanks for replies.
    I have tried adding "JLabel title = new JLabel("Red List");" in my try catch block, don't laugh, but it was worth a try right?

    So you've looked through the JFrame API and you've searched on the term "title" and nothing came up?

  • Changing the cursor shape

    how can i change the shape of a cursor to "hand" when the mouse rolls over specific text item. i have tried the cursor_style property but it returns only some of the cursor styles plus the are just behind the mouse clik trigeers so it chnges the shape when the mouse is cliked while i want it to change when mouse just rolls over the specific text item.as done in hyperlinks .

    Which form version you are using?
    Forms 6, has got cursor styles which are HAND, MOVE not documented in help.
    SET_APPLICATION_PROPERTY(CURSOR_STYLE,'HAND');
    regards

  • Change color in shapes

    I've selected the shape, double clicked it, gone to inspector, changed the color in the color chooser, but it has no effect on the selected shape. What's up?

    After selecting your shape, go to the Inspector and select Graphic inspector
    In the Fill pull-down select Color Fill and click on the color
    The crayons or other color method should open and after you select a new color it should appear right away
    if you don't pick a fill nothing will happen
    hope this helps...

  • Changing JFrame Color

    Hello ........
    I Have an Application(JFrame) With several panels in its content pane at different times. I changes the background colors of all the panels say (blue). But there is an outline in gray around the frame (I suppose)
    I have also used frame.setbackground(Color.blue);
    But that doesnt change that color.
    What can I do cause its kind of visible and doesnt look so nice when everything else is in another color.
    Thanks
    Shirantha.

    Hi,
    I found why there is no method to set the border in frame.
    All other components in inherit from JComponent so they also get the
    setBorder inherited.
    But JFrame does not. JFrame is extended by Frame which is extended by Window. Window does not have a border or title bar and buttons.
    So if I could do something so JFrame will not have a border, it might work.
    But I still have no idea on this
    Shirantha

  • Changing a letter shape

    I am new to In Design and am trying to change the shape of a letter. I assume you need nodes but I haven't found them yet.

    A better solution, in my opinion, would be to make your own font and use that character (you can probably find a way to do this as a nested or GREP style) so the type remains edidable.
    Before you say you cannot make a font, see Adobe Community: [Ann] IndyFont Demo: make your own (1 character) font
    This is a truly amazing script from our own regular contributor Theunis deJong, AKA Jongware. The demo will allow you to make a single character and save it as a custom font that you can apply as a character style.
    For your project, type the base character on the pasteboard and scale it as required, then position it in the working window and convert it to outlines as explained above, then make your modifications before saving as your custom font.

Maybe you are looking for