Resizing JFrame with ChangeListener


I have a JFrame that contains 5 JTabbedPane. I added a changeListener event to these JTabbedPane because I want to frame to be a different size depending on which tab you selected and are viewing. Here's the code for that:
tabPane.addChangeListener( new TabHandler() ); . . . private static class TabHandler implements ChangeListener { public void stateChanged( ChangeEvent ce ) { if( ((JTabbedPane)ce.getSource()).getSelectedIndex() == 4 ) frame.setSize( 800, 650 ); else frame.setSize( 700, 510 ); } }
Posted On: Tuesday 23rd of October 2012 11:37:59 PM Total Views:  241
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




no repaint while resizing when using .setPaint(gradient)

hello as soon a i use gradients in my code, the repaint isn't done while resizing i get something like that while resizing (black rectangles where it has been resized, see below). And when i stop resizing, everything is drawn again, but only then. if i don't use g2d.setPaint(gradient); i have a quick redraw public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; //sample of the code GradientPaint gradient = new GradientPaint(startX, startY, greyColor1, endX, endY, new Color(120,120,120)); g2d.setPaint(gradient); g.drawLine(i, startY, i, endY); }
VIEWS ON THIS POST

136

Posted on:

Friday 21st September 2012
View Replies!

JFrame resizing

Okay so here is my problem. I have created a JFrame class and I want to make the content pane inside be a certain size. Since the JFrames size is not the size of the content pane I have to resize the contentpane and pack the JFrame to the correct size. The problem is that I think that setting the JFrame resizable to false causes an increase in the panels size even if I set to maximum size. This happens verry randomly (1 in 50 or so) so I decided to put the code in the AWT thread because I thought it would fix it. Here is the said code: try { SwingUtilities.invokeAndWait( new Runnable() { public void run() { setResizable( false ); //Set the size of the content pane then pack the JFrame around it. getContentPane().setPreferredSize( new Dimension( 640, 480 ) ); getContentPane().setMinimumSize( new Dimension( 640, 480 ) ); getContentPane().setMaximumSize( new Dimension( 640, 480 ) ); pack(); setVisible( true ); } }); } catch(Exception e) { System.exit(1); }
VIEWS ON THIS POST

89

Posted on:

Friday 21st September 2012
View Replies!

JButton resizing issue

I am directly sizing and locating JButtons in an app and for some reason the last button that is added to the container always fills the container. Here is the code /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package parkinglot; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; /** * * @author Ranger Rick */ public class ParkingLot extends JFrame implements ActionListener{ String[] spots = {"1","2","3","4","5","6","7","8","9","10","11","12","13", "14","15","16","17","18","19","20","21","22","23","24","25","26","27","28"}; JButton[] spotButtons = new JButton[28]; int sizeX = 100; int sizeY = 50; int startY = 505; int startX = 300; int midY = 395; int midX = 600; int backY = 200; int backX = 600; int rightY = 300; int rightX = 900; public ParkingLot(){ super("Parking Lot"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(screenSize.width/4, 50, screenSize.width-screenSize.width/4, screenSize.height-90); for(int i=0;i
VIEWS ON THIS POST

82

Posted on:

Wednesday 26th September 2012
View Replies!

Panel appears only when resizing JFrame.

hello i have a layout in which i have four buttons in the west side of my border layout, and when i click on any of button my panel of center layout gets change.. (ie, if i click home, the center of border layout get home panel, when i click register the center of border layout get register panel and so on....) but the problem is the are appearing only when i m resizing my frame, i mean maximizing my frame.. here is my code: WelcomeScreen.java import javax.swing.*; import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class WelcomeScreen extends JFrame{ private JLabel labelTitle; JPanel mainPanel,northPanel,westPanel,southPanel,eastPanel; private BorderLayout bLayout; CustomerLayout cl = new CustomerLayout(); Home h = new Home(); JButton buttonHome, buttonSearch, buttonRegister, buttonAbout; public static void main(String args[]) { new WelcomeScreen(); } WelcomeScreen() { mainPanel = new JPanel(); bLayout = new BorderLayout(5,5); mainPanel.setLayout(bLayout); northPanel = new JPanel(); northPanel.setBorder(new TitledBorder(new EtchedBorder(),"")); mainPanel.add(northPanel, BorderLayout.NORTH); RichJLabel label = new RichJLabel("Poona College of Pharmacy",0); label.setLeftShadow(1,1,Color.white); label.setRightShadow(1,1,Color.gray); label.setForeground(Color.BLUE); label.setFont(label.getFont().deriveFont(20f)); Box top = Box.createHorizontalBox(); top.add(Box.createHorizontalStrut(10)); top.add(label); top.add(Box.createHorizontalStrut(10)); northPanel.add(top); cl.panel.setBorder(new TitledBorder(new EtchedBorder(),"")); mainPanel.add(h, BorderLayout.CENTER); eastPanel = new JPanel(); eastPanel.setBorder(new TitledBorder(new EtchedBorder(),"")); mainPanel.add(eastPanel, BorderLayout.EAST); Box right = Box.createVerticalBox(); right.add(Box.createVerticalStrut(20)); right.add(new JLabel("EAST SIDE!")); eastPanel.add(right); westPanel = new JPanel(); westPanel.setBorder(new TitledBorder(new EtchedBorder(),"")); mainPanel.add(westPanel, BorderLayout.WEST); Box left = Box.createVerticalBox(); left.add(Box.createVerticalStrut(10)); buttonHome = new JButton("Home"); buttonHome.setToolTipText("Click to go Home Page"); left.add(buttonHome); left.add(Box.createVerticalStrut(15)); BtnListener bt = new BtnListener(); buttonHome.addActionListener(bt); buttonHome.setBorderPainted(true); buttonHome.setOpaque(false); buttonHome.setMargin(new Insets(1,1,1,1)); buttonHome.setBackground(Color.lightGray); buttonRegister = new JButton("Register"); buttonRegister.setToolTipText("Click to Register"); left.add(buttonRegister); left.add(Box.createVerticalStrut(15)); buttonRegister.addActionListener(bt); buttonRegister.setBorderPainted(true); buttonRegister.setOpaque(false); buttonRegister.setMargin(new Insets(1,1,1,1)); buttonRegister.setBackground(Color.lightGray); buttonSearch = new JButton("Search"); buttonSearch.setToolTipText("Click to Search"); left.add(buttonSearch); left.add(Box.createVerticalStrut(15)); buttonSearch.addActionListener(bt); buttonSearch.setBorderPainted(true); buttonSearch.setOpaque(false); buttonSearch.setMargin(new Insets(1,1,1,1)); buttonSearch.setBackground(Color.lightGray); buttonAbout = new JButton("About us"); buttonAbout.setToolTipText("Click to go About Us"); left.add(buttonAbout); left.add(Box.createVerticalStrut(15)); buttonAbout.addActionListener(bt); buttonAbout.setBorderPainted(true); buttonAbout.setOpaque(false); buttonAbout.setMargin(new Insets(1,1,1,1)); buttonAbout.setBackground(Color.lightGray); westPanel.add(left); southPanel = new JPanel(); southPanel.setBorder(new TitledBorder(new EtchedBorder(),"")); mainPanel.add(southPanel, BorderLayout.SOUTH); RichJLabel label1 = new RichJLabel("Poona College of Pharmacy",0); label1.setLeftShadow(1,1,Color.white); label1.setRightShadow(1,1,Color.gray); label1.setForeground(Color.BLUE); label1.setFont(label1.getFont().deriveFont(10f)); Box bottom = Box.createHorizontalBox(); bottom.add(Box.createHorizontalStrut(10)); bottom.add(label1); bottom.add(Box.createHorizontalStrut(10)); southPanel.add(bottom); mainPanel.setOpaque(true); this.add(mainPanel); this.setSize(800,800); //this.setExtendedState(Frame.MAXIMIZED_BOTH); this.setVisible(true); //this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } class BtnListener implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource()==buttonHome) { mainPanel.add(h, BorderLayout.CENTER); h.show(); cl.panel.hide(); } else if(e.getSource()==buttonRegister) { mainPanel.add(cl.panel, BorderLayout.CENTER); h.hide(); cl.panel.show(); } } } }
VIEWS ON THIS POST

83

Posted on:

Thursday 27th September 2012
View Replies!

Image resizing as per desired size through JSP page

I have a JSP page which browse the image file select it and upload it on the server . But I need to change the size of image before uploading it to the server . Please Help
VIEWS ON THIS POST

102

Posted on:

Wednesday 17th October 2012
View Replies!

restrictions on resizing JFrame

hi there. i just want to ask, well, i have here a JFrame size set as 1024 x 768. it is resizable. what i want to know is, how can i restrict the frame from resizing when it reaches 800 x 600 i mean, when resized, the smallest possible size of the frame must be 800 x 600 and will not go smaller than that. any suggestions are very much appreciated.
VIEWS ON THIS POST

69

Posted on:

Wednesday 17th October 2012
View Replies!

Why Glass Pane becomes visible when resizing JInternalFrame?

, I've created a JFrame with JDesktop and one JInternalFrame on it. I've also added a glasspane (which draws a black circle only) to JFrame - it's invisible by default but when I resize JInternalFrame it shows up.. is this correct behavior Why it is visible only when I resize and diappears when I release mouse button after resize How I can make it invisible when resizing JInternalFrame (Is removing JFrame's glasspane only solution)import java.awt.Graphics; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JPanel; public class RunMe extends JFrame { public RunMe() { this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setBounds(10, 10, 800, 600); JDesktopPane desktop = new JDesktopPane(); JInternalFrame testJIF = new JInternalFrame("test", true, true, true, true); testJIF.setBounds(10, 10, 100, 100); desktop.add(testJIF); testJIF.setVisible(true); this.add(desktop); this.setGlassPane(new MyGlassPane()); this.setVisible(true); } private class MyGlassPane extends JPanel { public MyGlassPane() { this.setOpaque(false); } @Override protected void paintComponent(Graphics g) { g.fillOval(0, 0, 100, 100); super.paintComponent(g); } } public static void main(String[] args) { new RunMe(); } }
VIEWS ON THIS POST

91

Posted on:

Wednesday 17th October 2012
View Replies!

scaling a font when resizing by dragging

I am using g.drawString() in paintComponent() to display a text string on a JPanel. I am resizing the JPanel by dragging it on a canvas (another JPanel). I want the text string to resize as well. Is there a way to do this so that the displayed string stays within the bounds of the JPanel. The text string has to increase when the dragged JPanel increases and decrease when the dragged JPanel decreases in size. In other words, the bounds of the text string has to change more or less in proportion to the bounds of the dragged JPanel.
VIEWS ON THIS POST

97

Posted on:

Wednesday 17th October 2012
View Replies!

resizing without using gridbaglayout

hey we've been using gridbaglayout in class now for quite sometime now, and including the professor thinks its overly complicated. I have now one question. When using gridbaglayout its possible to set the variables to let specific panels stretch horizontally and vertically. Is it possible to do this without using gridbagLayout. My professor sais it is, but that its more complicated someone please tell me he's wrong and if so, how would i go about doing so
VIEWS ON THIS POST

152

Posted on:

Thursday 18th October 2012
View Replies!

Problem in displaying images while resizing in AWT

With 500X500 screen size the images are displayed properly. If I change the screen size 350X450 none of the images are getting displayed. However if I maximize the screen and resize window size back the images are visible. We cannot go for swings because the JVM for PDA supports AWT only. Please give your valuble inputs on this.
VIEWS ON THIS POST

130

Posted on:

Thursday 18th October 2012
View Replies!

How to disable maximise button of jframe

actually am developing application and i want to disable maximize button of jframe... i am using this to enable JFrame.setDefaultLookAndFeelDecorated(true); now i want to disable the maximize button
VIEWS ON THIS POST

117

Posted on:

Thursday 18th October 2012
View Replies!

printing jframe content in core java

I want to print Jframe like our word document. I have one jframe on jframe i have Jpanel ond on that panel i have j label . In jlabel i written a letter i want to print that letter so how can I print that letter.
VIEWS ON THIS POST

349

Posted on:

Sunday 21st October 2012
View Replies!

GridBagLayout resizing is making component invisible

So I'm working on an app that has a JSplitPane. The right pane of the JSplitPane is a GridBagLayout ( I didn't choose it, the previous developers did). In it is a JTextField that is approx 10 characters wide. *Problem* If I make the GridBagLayout pane larger, everything works fine. But if I shrink it by setting the JSplitPane divider to halfway, the text field completely disappears, even though there is obviously more space to the right of it. I've set the JTextField's gridwidth to be the maximum possible, but it still disappears. Any suggestions\t
VIEWS ON THIS POST

111

Posted on:

Monday 22nd October 2012
View Replies!

jpanel into jframe

i have jframe1. jframe having menu bar and i have 5 jpanel. now i want a result like, when i select one menu item it will show me a panel (i.e. - jpanel1) when i click on other menu item then it has to show other jpanel (i.e. - jpanel2) and jpanel1 get hide.
VIEWS ON THIS POST

105

Posted on:

Monday 22nd October 2012
View Replies!

resizing JPanel

Often when I add a widget to a JPanel that is on a JFrame, it doesn't show up. I had the same problem with JFrame. Stuff that I added to a JFrame didn't show up. I figured out that if you resize the JFrame, or use pack(), or setVisible(true), the changes made to JFrame would become visible. Is there some kind of command that you should use for a JPanel that would make it reflect changes in its content (specifically, showing the added widget)
VIEWS ON THIS POST

70

Posted on:

Monday 22nd October 2012
View Replies!

jsplitpane resizing problem

hi, i have a jsplitpane that has a jscrollpane on the left on the right.The one on the left contans a jtree while the one on the right contains several jpanel(and different layout managers).The problem comes in the displayam of the split pane, its compressed and i have to manually resize it to see the components. i thot that on calling the frame's pack(), the frame is resized according to the components it contained but apparently this isn't the case.Further more, i displayed the components' sizes and they're all Dimension(0,0). Seems i forgot something , or should i expicitly set some minimum size to all jpanels .. am really not sure of what to do , so if anyone could give me an idea , i'd be super grateful.
VIEWS ON THIS POST

75

Posted on:

Tuesday 23rd October 2012
View Replies!

resizing JInternalFrame when content grows

hello, i have a JPanel inside a JInternalFrame that can change its size (it grows) is there any way to make the JInternalFrame grow with it, now i have to manually resize it...
VIEWS ON THIS POST

64

Posted on:

Tuesday 23rd October 2012
View Replies!

get a jframe to "stay on top" in Applet

Hi I am trying to develop an applet where the user can open a jframe and keep it on top of the browser window. I don't want a Modal Dialog as the user will still need to interact with the Applet on the web page. If I monitor the focus and simply refocus the frame if it loses focus then the user wont be able to interact with the applet below it I need a way similar to windows API call setWindowPos(HWND_TOPMOST) Any Ideas Edited because I meant JFrame not JPanel [ September 08, 2005: Message edited by: Chris Topher ]
VIEWS ON THIS POST

93

Posted on:

Tuesday 23rd October 2012
View Replies!

window resizing

I am creating a GUI application using Java and Swing. The GUI portion of the application consists of two panels, one above the other. The frame is given a border layout so that the top panel can be placed in the NORTH section and the bottom panel can be placed in the WEST section. The top panel contains a text field and a button. The bottom panel contains a canvas for drawing shapes. This is where it starts to get tricky for me. The canvas must always be a perfect square. When the application loads, the top panel is filled and added to the frame. Then I have to figure out how much blank space is available for the bottom panel. The canvas must take up this blank space. But since it has to be a perfect square, the shorest side of the available space must be used as the value for the height and width of the canvas. I could pass all of this information along through the constructors of all of my components, but the reason I don't want to do this is because I also have to reconfigure the size of the canvas each time the window is resized. To me, it would make more sense to use a function in my class MyCanvas (which extends Canvas) to update the size of the canvas each time paint is called. I should also add that I am programmatically setting the size and location of the window based on the screen resolution when the application loads. Any ideas to help me solve this problem would be much appreciated.
VIEWS ON THIS POST

78

Posted on:

Tuesday 23rd October 2012
View Replies!

Canvas resizing

I would like to know how to resize a canvas which has been added my applet. And also is it possible to add a canvas to a JPanel.
VIEWS ON THIS POST

104

Posted on:

Tuesday 23rd October 2012
View Replies!