Changing L&F on a JFrame?

Hi all,
I am currently writing my own look and feel, and I am having trouble with applying this on the JFrame-object. I managed to do this on the JInternalFrame (by using MetalInternalFrameUI)
but I can not find a similiar class for a JFrame. I know that the look and feel for a JFrame is platform-dependent but still, I think it should be possible to do it. If not, is there any way to use JInternalFrame directly as a main container?
Thank you,
Regards Veroslav

Hi Veroslav
You need to tell the L&F manager what you are using. By simply calling
JFrame.setDefaultLookAndFeelDecorated You are telling JFrames to decorate using the L&F if one is provided. If you have not provided one it will use the default L&F implementation.
You need to do something like this.
String rootpaneClassName = "com.yourcompany.YourRootPaneUI";
UIManager.put("RootPaneUI", rootpaneClassName);
UIManager.put(rootpaneClassName, Class.forName(rootpaneClassName));This will tell the L&F manager to use you rootpane UI class opposed to the default.
You can then either set this to individual frames like so.
try
//get it to use our nice buttons and colours, loverly
m_externalFrame.setUndecorated(true);
m_externalFrame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
RootPaneUI rpUI = (RootPaneUI)Class.forName(tmp).newInstance();
m_externalFrame.getRootPane().setUI(rpUI);
}catch(Exception ex)
m_exceptionService.handleException(
ex, "Cannot find Branded Look & Feel for Main Frame" );
}You could alternatively write it directly into your L&F class to map all JRootPanes to use your RootPaneUI class
Have a look at the Metal L&F classes ;) to get an idea about the RootPaneUI and TitlePane implementations.
N35Sy

Similar Messages

  • How do you change the size of a JFrame?

    I have some code using a jframe for an application creating buttons, but i want to also have some graphics in there, and I was wondering if there was a way to change the size of the jframe.

    Use JFrame.setSize().
    Check the JavaDocs for the method signatures.
    Dave

  • Why I cannot change font  and Color in JFrame title??

    Dear sir:
    I try to change font and Color in JFrame title in code below,
    It display all html code, not expected formatted ones.
    but fail. Looks like no way to do it??
    Can somebody help??
    Thanks
    import java.awt.BorderLayout;
    import java.awt.Toolkit;
    import javax.swing.*;
    public class JFrameTester {
      public static void main(String[] args) {
         String iconPath ="file:C:/eclipse/workspace/Test/images/long.PNG";
         String title = "<html><body bgcolor=\"yellow\">" + "<img src=\""+iconPath+"\">" +
              " <font size=\"6\" face=\"Verdana\" color=\"red\"><b>"+ "New Tester" + "</b></font></html>";
        JFrame f = new JFrame(title);
        f.setIconImage(Toolkit.getDefaultToolkit().getImage("images/123.gif"));
        f.setSize(250, 250);
        f.setLocation(300,200);
        f.getContentPane().add(new BorderLayout().CENTER, new JTextArea(10, 40));
        f.setVisible(true);
    }

    Looks like no way to do it??depends on the L&F you want.
    here's one way
    import java.awt.*;
    import javax.swing.*;
    class JFrameTester {
      public static void main(String[] args) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.RED));
        UIManager.put("activeCaptionText", new javax.swing.plaf.ColorUIResource(Color.YELLOW));
        String title = "Hello World";
        JFrame f = new JFrame(title);
        f.getLayeredPane().getComponent(1).setFont(new Font("Tall Paul",Font.ITALIC,24));
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(250, 250);
        f.setLocation(300,200);
        f.getContentPane().add(new BorderLayout().CENTER, new JTextArea(10, 40));
        f.setVisible(true);
    }

  • How can I change the Icon on the JFrame?

    Everytime, when I create an application, the default javalogo will show on the left top concern of the application which using JFrame, how can I change it to the other?

    Have you tried using the setIconImage method like this:
    JFrame F=new JFrame();
    F.setIconImage(Toolkit.getDefaultToolkit().getImage("myIcon.gif"));
    Here is what the API doc says:
    setIconImage
    public void setIconImage(Image image)
    Sets the image to be displayed in the minimized icon for this frame. Not all platforms support the concept of minimizing a window.
    Parameters:
    image - the icon image to be displayed. If this parameter is null then the icon image is set to the default image, which may vary with platform.

  • Cant change window Icon in a JFrame

    I cannot seem to set the icon in the upper left of the window or in the task. I am using NetBeans and it created my JFrame for me using the following code to initialize:
    java.awt.EventQueue.invokeLater(new Unable() {
                public void run() {
                    new MainFrame().setVisible(true);
            });I have checked online tutorials and this seem to be a trully easy task BUT my JFrame, MainFrame, seems not to have the method I need....
    I should be able too do this:
    MainFrame.setIconImage(Image image); But it seems I cannot get that method in my JFrame at all, it just doesnt show up in NetBeans and wont allow me to compile. I have tried looking at the base JFrame class and see no setIconImage there either. Any help would be apriciated.
    KN

    Can you post the code for your MainFrame class. Use
    code tags.Ok, 1st excuse the messy code, I am teaching myself Java and the code is a bit unproffesional. Also the code is large as it is a calendar program that allows you to input text into the actual calendar day boxes, loads, saves etc. Here is the declaration of the MainFrame class and the MainFrame constructor.
    public class MainFrame extends javax.swing.JFrame {
        // Constants
        public final int DATE_HEIGHT = 17;
        public final int DAY_HEIGHT = 80;
        public final boolean DBG = true;
        public boolean Init = true;
        public int curMonth = 0;
        public int curYear = 0;
        /** Creates new form MainFrame */
        public MainFrame() {
            initComponents();
            for(int x = 0;x < 12;x = x + 2){
                jTable1.setRowHeight(x,DATE_HEIGHT);
                jTable1.setRowHeight(x+1,DAY_HEIGHT);
            jTable1.setDefaultRenderer(Object.class, new ColorCellRenderer());
            DateFormat dateFormat =
                    DateFormat.getDateInstance(DateFormat.FULL);
            // Create our Gregorian Calendar.
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(new Date());
            DaYear.setYear(cal.get(cal.YEAR));
            DaMonth.setMonth(cal.get(cal.MONTH));
            Init = false;
            LoadIt(curMonth, curYear);
        }KN

  • Changing L&F for the JFrame?

    Hi all,
    I am currently writing my own look and feel, and I am having trouble with applying this on the JFrame-object. I managed to do this on the JInternalFrame (by using MetalInternalFrameUI)
    but I can not find a similiar class for a JFrame. I know that the look and feel for a JFrame is platform-dependent but still, I think it should be possible to do it. If not, is there any way to use JInternalFrame directly as a main container?
    Thank you,
    Regards Veroslav

    It is platform dependent, but in 1.4 or later it is possible to "hint" the system that a frame should not have the native decorations.
    http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/JFrame.html#setDefaultLookAndFeelDecorated(boolean)
    http://java.sun.com/j2se/1.4.1/docs/api/java/awt/Frame.html#setUndecorated(boolean)

  • How to change the image in title bar for JFrames

    plz give me a small code to change the image of the JFrame in the Title bar.
    i know how to change the name of the title bar .
    import javax.swing.*;
    class Rathna1 extends JFrame
    Rathna1()
    super("rathna project ");
    public class Rathna
    public static void main(String ax[])throws Exception
    Rathna1 r=new Rathna1();
    r.setVisible(true);
    r.setSize(400,400);
    Like this how to change the image of the title bar
    Message was edited by:
    therathna

    hi,
    JFrame frame;
    frame.setVisible(true);
    frame.setIconImage(new ImageIcon("icons/img007.gif").getImage());
    frame.setSize(800,600);
    i think the thing u r searching is :
    frame.setIconImage(new ImageIcon("icons/img007.gif").getImage());
    ~~~radha

  • How to change the JFrame's title?

    Is it possible to change the title of a JFrame at runtime?
    If so, how?
    sincerely
    nir

    See JFrame.setTitle(String).
    Shaun

  • JFrame icon won't change in linux

    In windows, I'm able to change my JFrame's icon with the setIconImage(Image) but doing the same thing on linux (Gnome) does nothing. Is this a bug or is there something else I need to do to change an icon in a JFrame?

    In windows, I'm able to change my JFrame's iconwith
    the setIconImage(Image) but doing the same thingon
    linux (Gnome) does nothing. Is this a bug or is
    there something else I need to do to change anicon
    in a JFrame?Works for me! FC5 JKD1.4,1.5 and 1.6 beta.Are you able to change the icon of the JFrame after it's been set visible, or only as an initializing step? I can do the latter, but not the former. The icon never changes from what it originally set to.

  • 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).

  • How can i change/set a new icon on title bar in JFrame

    hi
    i want to change the icon of title bar on JFrame
    plz help me as soon as possible.
    thankyou

    I took you longer to post you message than to read the api documentation on JFrame. There is a method dedicated to changing the icon of the JFrame.

  • Need help:JPanel not being displayed in the JFrame

    Hello,
    I have a class called ConstructRoom.java which extends JFrame and another class called DimensionsPanel.java which extends JPanel. In the ConstructRoom class I use the following theContainer.add(new DimensionsPanel());, so I can display my JPanel. Well I get the JFrame but no JPanel. When the this call is made the DimensionsPanel.java code is cycled through, Where has my JPanel gone to?
    If I change the DimensionPanel.java extend JFrame and add the the JFrame code. Then I get the JFrame and the JPanel.
    Whats going on here?
    Thanks

    I made some of the changes with no luck. Here is some of the code:
    ---------from ConstructRoom.java--------
    //Imports
    public class ConstructRoom extends JFrame
    //----Member objects and varibles
    private static String theTitle; //Varible for title of frame
    private JFrame theFrame; //Object for the JFrame
    // ----------------------------------------------------------- ConstructRoom
    public ConstructRoom(String theTitle)
    super(theTitle); //JFrame super class
    theFrame = new JFrame("My frame");
    Container theContainer = theFrame.getContentPane(); //Frame container
    theContainer.setLayout(new FlowLayout());
    theContainer.add(new DimensionsPanel());
    theFrame.pack();
    theFrame.setBounds(10,10,400, 400);
    theFrame.addWindowListener(new WindowHandler());
    theFrame.setVisible(true);
    }//end ConstructRoom(String theTitle)
    // -------------------------------------------------------------------- main
    public static void main(String args[])
    ConstructRoom theRoom = new ConstructRoom(theTitle);
    }//end main(String args[])
    //----WindowHander
    }//end class ConstructRoom extends JFrame
    --------from DimensionsPanel.java
    //Imports
    public class DimensionsPanel extends JPanel
    //----Member objects and varibles
    private JPanel dimensionsPanel; //The main panel to hold all info
    private Box panelBox; //Box for all boxes which is added to the JPanel
    private Box furnListBox; //Box for all related items of the furnList
    private Box dimensionsBox; //Box for all dimensions (x, y, z)
    private Box xFieldBox; //Box for all related items of the xField
    private Box yFieldBox; //Box for related items of the yField
    private Box zFieldBox; //Box for related items of the zField
    private Box buttonsBox; //Box for all buttons
    private Box clearBox; //Box for related clear button items
    private Box buildBox; //Box for related build button items
    private JLabel furnListLabel; //Label for the furnList comboBox
    private JLabel xFieldLabel; //Label for the xField
    private JLabel yFieldLabel; //Label for yField
    private JLabel zFieldLabel; //Label for zField
    private JTextField xField; //Text field to enter the x dimension
    private JTextField yField; //Text field to enter the y dimension
    private JTextField zField; //Text field to enter the z dimension
    private JComboBox furnList; //List of selectable furniture objects
    private JButton clearButton; //Clear button
    private JButton buildButton; //Build button
    // --------------------------------------------------------- DimensionsPanel
    public DimensionsPanel()
    //----Setting up dimensions panel
    dimensionsPanel = new JPanel();
    dimensionsPanel.setLayout(new BorderLayout());
    dimensionsPanel.setPreferredSize(new Dimension(150,150));
    dimensionsPanel.setBorder(new TitledBorder(new EtchedBorder(),
    "Select Furniture and Enter Dimensions"));
    //----Initializing GUI components
    furnListLabel = new JLabel("Select from list ");
    furnList = new JComboBox();
    xFieldLabel = new JLabel("Enter Width ");
    xField = new JTextField();
    yFieldLabel = new JLabel("Enter Height ");
    yField = new JTextField();
    zFieldLabel = new JLabel("Enter Depth ");
    zField = new JTextField();
    buildButton = new JButton("Build Object");
    clearButton = new JButton("Clear Object");
    //-----Setting up the combo box and adding items
    furnList.addActionListener(new ComboProcessor());
    furnList.addItem(" "); //Default item
    furnList.addItem("Color Cube");
    furnList.setMaximumRowCount(6); //Max number of items before scrolling
    furnList.setSelectedItem(" "); //Set initial to default item
    //--Add the furnList to its box for placement in the JPanel
    furnListBox = Box.createHorizontalBox();
    furnListBox.add(Box.createHorizontalStrut(5));
    furnListBox.add(furnListLabel); //Adding the combo box label
    furnListBox.add(furnList); //Adding the combo box
    furnListBox.add(Box.createHorizontalStrut(5)); //Spacing
    //-------------------------------- Start Dimensions Components
    //----Setting up the xField
    xField.setEnabled(false); //Disabled at start
    xField.setFocusTraversalKeysEnabled(false); //Disabling the Tab Key
    //----Adding the event listeners
    xField.addActionListener(new XTextProcessor()); //Enter Key
    xField.addMouseListener(new ClickProcessor()); //Mouse Click
    //--Add the xField to its box for placement in the dimensionsBox
    xFieldBox = Box.createHorizontalBox();
    xFieldBox.add(Box.createHorizontalStrut(10)); //Spacing
    xFieldBox.add(Box.createGlue()); //Take up extra space
    xFieldBox.add(xFieldLabel); //Adding the text field label
    xFieldBox.add(xField); //Adding the text field
    xFieldBox.add(Box.createHorizontalStrut(100)); //Spacing
    //----Setting up the yfield
    yField.setEnabled(false); //Disabled at start
    yField.setFocusTraversalKeysEnabled(false); //Disabling TAB KEY
    //----Adding the event listeners
    yField.addActionListener(new YTextProcessor()); //Enter Key
    yField.addMouseListener(new ClickProcessor()); //Mouse Click
    //--Add the yField to its box for placement in the dimensionsBox
    yFieldBox = Box.createHorizontalBox();
    yFieldBox.add(Box.createHorizontalStrut(10)); //Spacing
    yFieldBox.add(Box.createGlue()); //Take up extra space
    yFieldBox.add(yFieldLabel); //Adding the text field label
    yFieldBox.add(yField); //Adding the text field
    yFieldBox.add(Box.createHorizontalStrut(100)); //Spacing
    //----Setting up the zfield
    zField.setEnabled(false); //Disabled at start
    zField.setFocusTraversalKeysEnabled(false); //Disabling TAB KEY
    //----Adding the event listeners
    zField.addActionListener(new ZTextProcessor()); //Enter Key
    zField.addMouseListener(new ClickProcessor()); //Mouse Click
    //--Add the zField to its box for placement in the dimensionsBox
    zFieldBox = Box.createHorizontalBox();
    zFieldBox.add(Box.createHorizontalStrut(10)); //Spacing
    zFieldBox.add(Box.createGlue()); //Take up extra space
    zFieldBox.add(zFieldLabel); //Adding the text field label
    zFieldBox.add(zField); //Adding the text field
    zFieldBox.add(Box.createHorizontalStrut(100)); //Spacing
    //----Adding all dimension components to the dimensionsBox
    dimensionsBox = Box.createVerticalBox();
    dimensionsBox.add(xFieldBox); //Adding the xFieldBox
    dimensionsBox.add(Box.createVerticalStrut(10)); //Spacing
    dimensionsBox.add(yFieldBox); //Adding the yFieldBox
    dimensionsBox.add(Box.createVerticalStrut(10)); //Spacing
    dimensionsBox.add(zFieldBox); //Adding the zFieldBox
    //-------------------------------- End Dimension Components
    //----Setting up the clearButton
    clearButton.setEnabled(false); //Disabled at start
    //----Adding the event listener
    clearButton.addActionListener(new ClearProcessor());
    //--Add the clear button to its box for placement
    clearBox = Box.createHorizontalBox();
    clearBox.add(Box.createHorizontalStrut(5)); //Spacing
    clearBox.add(clearButton); //Adding the clearButton
    //----Setting up the buildButton
    buildButton.setEnabled(false); //Disabled at start
    //--Add the action listener here
    buildBox = Box.createHorizontalBox();
    buildBox.add(buildButton); //Adding the buildButton
    buildBox.add(Box.createHorizontalStrut(5)); //Spacing
    //----Adding both buttons the buttonsBox
    buttonsBox = Box.createHorizontalBox();
    buttonsBox.add(clearBox); //Adding the clearBox
    buttonsBox.add(Box.createHorizontalStrut(10)); //Spacing
    buttonsBox.add(buildBox); //Adding the buildBox
    //----Create the JPanel (dimensionsPanel)
    //--Creating the main box to be added to the JPanel
    panelBox = Box.createVerticalBox();
    panelBox.add(furnListBox); //Adding the furnListBox components
    panelBox.add(Box.createVerticalStrut(10)); //Spacing
    panelBox.add(dimensionsBox); //Adding the dimensionBox components
    panelBox.add(Box.createVerticalStrut(10)); //Spacing
    panelBox.add(buttonsBox); //Adding the buttonsBox components
    panelBox.add(Box.createVerticalStrut(10)); //Spacing
    dimensionsPanel.add(panelBox); //Adding all components to the JPanel
    System.out.println("end dimensionpanel");
    }//end DimensionsPanel()
    //------ActionListeners
    }//end class DimensionsPanel extends JPanel

  • Problem with JFrame and JPanel

    Okay, well I'm busy doing a lodge management program for a project and I have programmed this JFrame
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class FinalTest extends JFrame
         public JPanel contentPane;
         public JImagePanel imgPanel;
         private JLabel[] cottageIcon;
         private boolean keepMoving;
         private int selectedCottage;
         public FinalTest()
              super();
              initializeComponent();
              addActionListeners();
              this.setVisible(true);
         private void initializeComponent()
              contentPane = (JPanel)getContentPane();
              contentPane.setLayout(null);
              imgPanel = new JImagePanel("back.png");
               imgPanel.setLayout(null);
              imgPanel.setBackground(new Color(1, 0, 0));
                   addComponent(contentPane, imgPanel, 10,10,imgPanel.getImageWidth(),imgPanel.getImageHeight());
              cottageIcon = new JLabel[6];
              keepMoving = true;
              selectedCottage = 0;
              cottageIcon[0] =  new JLabel();
              //This component will never be added or shown, but needs to be there to cover for no cottage selected
              for(int a = 1; a < cottageIcon.length; a++)
                   cottageIcon[a] = new JLabel("C" + (a));
                   cottageIcon[a].setBackground(new Color(255, 0, 0));
                    cottageIcon[a].setHorizontalAlignment(SwingConstants.CENTER);
                    cottageIcon[a].setHorizontalTextPosition(SwingConstants.LEADING);
                    cottageIcon[a].setForeground(new Color(255, 255, 255));
                    cottageIcon[a].setOpaque(true);
                    addComponent(imgPanel,cottageIcon[a],12,(a-1)*35 + 12,30,30);
                this.setTitle("Cottage Chooser");
                this.setLocationRelativeTo(null);
              this.setSize(new Dimension(540, 430));
         private void addActionListeners()
              imgPanel.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        imgPanel_mousePressed(e);
                   public void mouseReleased(MouseEvent e)
                        imgPanel_mouseReleased(e);
                   public void mouseEntered(MouseEvent e)
                        imgPanel_mouseEntered(e);
              imgPanel.addMouseMotionListener(new MouseMotionAdapter()
                   public void mouseDragged(MouseEvent e)
                        imgPanel_mouseDragged(e);
         private void addComponent(Container container,Component c,int x,int y,int width,int height)
              c.setBounds(x,y,width,height);
              container.add(c);
         private void imgPanel_mousePressed(MouseEvent e)
              for(int a = 1; a < cottageIcon.length; a++)
                   if(withinBounds(e.getX(),e.getY(),cottageIcon[a].getBounds()))
                        System.out.println("B" + withinBounds(e.getX(),e.getY(),cottageIcon[a].getBounds()));
                        selectedCottage = a;
                        keepMoving = true;
         private void imgPanel_mouseReleased(MouseEvent e)
              System.out.println("called");
              selectedCottage = 0;
              keepMoving = false;
         private void imgPanel_mouseDragged(MouseEvent e)
               System.out.println("XXX" + Math.random() * 100);
              if(keepMoving)
                   int x = e.getX();
                    int y = e.getY();
                    if(selectedCottage!= 0)
                         cottageIcon[selectedCottage].setBounds(x-(30/2),y-(30/2),30,30);
                    if(!legalBounds(imgPanel,cottageIcon[selectedCottage]))
                        keepMoving = false;
                        cottageIcon[selectedCottage].setBounds(imgPanel.getWidth()/2,imgPanel.getHeight()/2,30,30);
              System.out.println(cottageIcon[selectedCottage].getBounds());
         private void imgPanel_mouseEntered(MouseEvent e)
               System.out.println("entered");
         private void but1_actionPerformed(ActionEvent e)
              String input = JOptionPane.showInputDialog(null,"Enter selected cottage");
              selectedCottage = Integer.parseInt(input) - 1;
         public boolean legalBounds(Component containerComponent, Component subComponent)
              int contWidth = containerComponent.getWidth();
              int contHeight = containerComponent.getHeight();
              int subComponentX = subComponent.getX();
              int subComponentY = subComponent.getY();
              int subComponentWidth = subComponent.getWidth();
              int subComponentHeight = subComponent.getHeight();
              if((subComponentX < 0) || (subComponentY < 0) || (subComponentX > contWidth) || (subComponentY > contHeight))
                   return false;
              return true;
         public boolean withinBounds(int mouseX, int mouseY, Rectangle componentRectangle)
              int componentX = (int)componentRectangle.getX();
              int componentY = (int)componentRectangle.getY();
              int componentHeight = (int)componentRectangle.getHeight();
              int componentWidth = (int)componentRectangle.getWidth();
              if((mouseX >= componentX) && (mouseX <= (componentX + componentWidth)) && (mouseY >= componentY) && (mouseY <= (componentY + componentWidth)))
                   return true;
              return false;
         public static void main(String[] args)
              JFrame.setDefaultLookAndFeelDecorated(true);
              //JDialog.setDefaultLookAndFeelDecorated(true);
              try
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch (Exception ex)
                   System.out.println("Failed loading L&F: ");
                   System.out.println(ex);
              FinalTest ft = new FinalTest();
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class JImagePanel extends JPanel
      private Image image;
      public JImagePanel(String imgFileName)
           image = new ImageIcon(imgFileName).getImage();
        setLayout(null);
      public void paintComponent(Graphics g)
        g.drawImage(image, 0, 0, null);
      public Dimension getImageSize()
                Dimension size = new Dimension(image.getWidth(null), image.getHeight(null));
             return size;
      public int getImageWidth()
                int width = image.getWidth(null);
                return width;
      public int getImageHeight()
              int height = image.getHeight(null);
              return height;
    }Now the problem I'm having is changing that class to a JFrame, it seems simple but I keep having problems like when it runs from another JFrame nothing pops up. I can do it like this:
    FinalTest ft = new FinalTest();
    ft.setVisible(false);
    JPanel example = ft.contentPanehowever I will probably be marked down on this for bad code. I'm not asking for the work to be done for me, but I'm really stuck on this and just need some pointers so I can carry on with the project. Thanks,
    Steve

    CeciNEstPasUnProgrammeur wrote:
    I'd actually consider your GUI being a JPanel instead of a JFrame quite good design - makes it easy to put the stuff into an applet when necessary...
    Anyway, you should set setVisible() to true to make it appear, not to false. Otherwise, I don't seem to understand your problem.That is actually my problem. I am trying to convert this JFrame to a JPanel

  • How to show the updated content of a JFrame

    I have a JFrame with JPanel and JMenuBar (and JMenus). I would like when the user select some item from the menu to change the JPanel of the JFrame, but I can't figure out why this code doesn't work.
    Problem is in the methods operation1Performed() and operation2Performed(). What is the command
    import javax.swing.*;
    import java.awt.event.*;
    public class TestGUI2 {
         public static void main(String args[]) {
              Cordinator2 c=new Cordinator2();
              c.showFrame();
    class Cordinator2 {
         private JFrame frame;
         private JMenuBar menuBar;
         private JPanel panel;
         public Cordinator2() {
              frame=new JFrame("TestMenu");
              menuBar=new JMenuBar();
              menuBar.add(getMenu());
              panel=getDefaultPanel();
              frame.setJMenuBar(menuBar);
              frame.getContentPane().add(panel);
              frame.pack();
         public JMenu getMenu() {
              JMenu menu=new JMenu("Modul");
              JMenuItem operation1=new JMenuItem("Operation1");
              operation1.addActionListener(
                   new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             operation1Performed();
              menu.add(operation1);
              JMenuItem operation2=new JMenuItem("Operation2");
              operation2.addActionListener(
                   new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             operation2Performed();
              menu.add(operation2);
              return menu;
         public JPanel getDefaultPanel() {
              JPanel panel=new JPanel();
              JLabel label=new JLabel("Some text");
              panel.add(label);
              return panel;
         public void setPanel(JPanel p) {
              panel=p;
         public void operation1Performed() {
              System.out.println("operation1");
              JPanel t_panel=new JPanel();
              JLabel label=new JLabel("Operation1 performed");
              t_panel.add(label);
              //frame.remove(panel);
              //frame.getContentPane().add(t_panel);
              setPanel(t_panel);
              frame.repaint();
         public void operation2Performed() {
              System.out.println("operation2");
              JPanel t_panel=new JPanel();
              JLabel label=new JLabel("Operation2 performed");
              t_panel.add(label);
              //frame.remove(panel);
              //frame.getContentPane().add(t_panel);
              setPanel(t_panel);
              frame.repaint();
         public void showFrame() {
              frame.setSize(400, 300);
              frame.setVisible(true);

    First: New code for one of your methods
         public void operation2Performed() {          
              System.out.println("operation2");          
              JPanel t_panel=new JPanel();          
              JLabel label=new JLabel("Operation2 performed");          
              t_panel.add(label);          
              frame.remove(panel);          
              frame.getContentPane().add(t_panel);          
              setPanel(t_panel);          
              frame.validate();     
    From that you can make operation1 work too. What was happening was that you have two panels. You have to remove the one and then add the next one. Then you need to tell the frame that you've made a change.
    Cheers,
    Rachel

  • How to change the color of the progress bar and string

    Is their anyway to change the color of the progress bar and the string which shows the progress of the bar. The current color of the bar is purple and i would like it to be red or blue so that it stands out against the background of the JFrame i am using. I dont want to change the color of the JFrame
    Thanks in advance

    import java.awt.*;
    import javax.swing.*;
    public class ProgressEx {
        public static void main(String[] args) {
            UIManager.put("ProgressBar.background", Color.WHITE);
            UIManager.put("ProgressBar.foreground", Color.BLACK);
            UIManager.put("ProgressBar.selectionBackground", Color.YELLOW);
            UIManager.put("ProgressBar.selectionForeground", Color.RED);
            UIManager.put("ProgressBar.shadow", Color.GREEN);
            UIManager.put("ProgressBar.highlight", Color.BLUE);
            JFrame f = new JFrame("Test");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JProgressBar pb1 = new JProgressBar();
            pb1.setStringPainted(true);
            pb1.setValue(50);
            JProgressBar pb2 = new JProgressBar();
            pb2.setIndeterminate(true);
            Container cp = f.getContentPane();
            cp.add(pb1, BorderLayout.NORTH);
            cp.add(pb2, BorderLayout.SOUTH);
            f.pack();
            f.setVisible(true);
    }

Maybe you are looking for

  • How to manage PDF opening in client installed Adobe Reader?

    Hi! As a background, I have this Document Library in SharePoint Online containing PDF files that are supposed to be confidential files wherein the users can only view the pdf documents, restricting the Printing, Copying of Content and Saving/Dowloadi

  • Data Inconsistency when activating DSO in BI 7.0

    Hi Guys, We are using BI 7.0, We have an ODS object and 2 IOs in that A & B. When we load data to that DSO it is loaded propery and that 2 IOs data is seen in New Data Table. The real strange thing when we activate that request that 2 IOs data is not

  • Free Transform as Animation? (6.2.2. - 10.10)

    Hi! I'm creating some simple motion graphics in keynote (a surprisingly good balance of power - ease of use!) However, I want to animate a box transforming in length, i.e. getting broader. With the normal animations, you can only scale shapes, mening

  • How to change the font style

    Hi All I am able to dispaly the content of a .txt file on the screen using inline frames(11g webcenter application using content repository- file system) . But 'm able to add styles to it like displaying it in bold letters. Any help on how to add tem

  • Adobe reader cannot extract embedded font after pdf sent via outlook

    We have some pdf files that open fine in Adobe Reader 9.1.3.  Once we send them via e-mail (we use Outlook 2003), they will not open properly with the error message: "Cannot extract the embedded font 'TWDWSP+TradeGothic-Light.  Some characters may no