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
Posted On: Monday 22nd of October 2012 02:06:06 AM Total Views:  126
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

168

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

113

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

110

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

107

Posted on:

Thursday 27th September 2012
View Replies!

program making the whole screen to be blue instead of drawing

Can anyone help with a code please I need to draw a Mandelbrot set. import javax.swing.*; import java.awt.*; public class MPanel extends JPanel { // int count; JFrame frame; public MPanel(JFrame frame) { this.frame = frame; } public void init() { frame.add(this); this.setSize(700, 700); // frame.setSize(700,700); repaint(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void paint(Graphics g) { double factor = 1e6; double widthPixel; double heightPixel; for (int x = 0; x < this.getWidth(); x++) { for (int y = 0; y < this.getHeight(); y++) { widthPixel = Math .round((x / this.getWidth() * factor) / factor); heightPixel = Math.round((y / this.getHeight() * factor) / factor); double re = (-2 + widthPixel * 4); double im = (1.6 - heightPixel * 3.2); Complex c = new Complex(re, im); // Complex temp = new Complex(x * widthPixel, y * heightPixel); Complex temp = c; for (int count = 0; count < 100; count++) { // Complex temp = c; c.square(); c.add(temp); System.out.println(c.toString()); // c.toString(); if (c.modulusSquared() > 4) { chooseColor(g, count); // System.out.println(count); g.drawLine(x, y, x, y); break; } } } } } public void chooseColor(Graphics g, int count) { if (count
VIEWS ON THIS POST

128

Posted on:

Friday 28th September 2012
View Replies!

How to make the window (JPanel?) bigger in gridbaglayout

When I run this program, the window pops up and everything is smooshed (for lack of a better term) together. How do I change the size of it I'm using GridBagLayout.
VIEWS ON THIS POST

209

Posted on:

Saturday 29th September 2012
View Replies!

making JTable appear after initial load

Hi Guys, I'm creating an app that includes a JTable. However, I don't want the JTable to appear upon the initial launch of the application. I have a File/New menu that I want the user to use to make the JTable appear for the first time with one new row in it. This is what I have for my actionPerformed(ActionEvent event) method: public void actionPerformed(ActionEvent event) { if(event.getSource() == mnuNew) { if(fileOpen) { if(isDirty) { ... } } else { if(isDirty == false) { System.out.println("setting up new table"); createTable(); addNewBlankRow(); table.validate(); //DOESN'T DO ANYTHING table.repaint(); //DOESN'T DO ANYTHING container.repaint(); //DOESN'T DO ANYTHING } } } ... }
VIEWS ON THIS POST

60

Posted on:

Monday 1st October 2012
View Replies!

Need help in making my Oval increase in size.

Hi ! I need a little help in creating shapes. Below is my code, but no matter what I do, I cannot make the Oval increase gradually (ie. once I run the program I should be able to see it increase). Any advice
VIEWS ON THIS POST

173

Posted on:

Tuesday 2nd October 2012
View Replies!

JTree making a node act as parent

I want to make a node to reflect as a Parent node containing children (Means i need the "+" sign associated with that node when shown in JTree). Currently I am using the TreeSelectionListener interface to do some operation when a node is selected in the JTree. But I would like to do some operation only when the node is expanded using the TreeExpansionListener interface. At this point there is only a Root and say some 10 children under the root. I want all the 10 children to behave like a collapsed node (pretend they have some children within them). Is there a way I can do this If not how to use the TreeExpansionListener for a leaf node(bit awkward)
VIEWS ON THIS POST

82

Posted on:

Wednesday 17th October 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

123

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

89

Posted on:

Wednesday 17th October 2012
View Replies!

Eclipse's AbstractTextEditor - making links "alive"

Hi I have a basic class i've written extending AbstractTextEditor. I use it only to display text files, not to edit them. I want that when the text contains links (or paths like /usr/bin/mydir) - they will be clickable and i can control what happens when user clicks on them. If they can be drawn in another color, it's even better. How can I do that
VIEWS ON THIS POST

94

Posted on:

Wednesday 17th October 2012
View Replies!

Help in gridbaglayout

Hi all The code below doesnt do what it has to do. I need to place the components on the top left of my panel. But the components be still in the center of panel after giving this also gbc.anchor=GridBagConstraints.NORTHWEST; It doent work until i set gbc.weightx=0.0; and gbc.weighty=0.0;. Here the components get at the top position but the gap in between them is increasing. Someone please help me out. The code is here. import java.io.*; import java.sql.*; import javax.swing.event.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; public class test extends JFrame { Container c; JLabel l1; JTextField t1; JPanel panel; public test() { c=getContentPane(); panel=new JPanel(); GridBagConstraints gbc = new GridBagConstraints(); GridBagLayout gl=new GridBagLayout(); panel.setLayout(gl); // gbc.weightx=1.0; // gbc.weighty=1.0; gbc.anchor=GridBagConstraints.NORTHWEST; l1=new JLabel("Name"); t1=new JTextField(25); gbc.gridy=0; panel.add(l1,gbc); panel.add(t1,gbc); getContentPane().add(panel); setSize(600,600); setVisible(true); } public static void main(String args[]) { new test(); } }
VIEWS ON THIS POST

114

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

122

Posted on:

Wednesday 17th October 2012
View Replies!

how to display textfield in a gridbaglayout

, Using a gridbag layout & constaints i want to place a small textfield and a button near to it.when the applet window is maximized the textfield will expand upto 40-50% of the window but the button will be of same size and near to the textfield without much change.I tried a lot but the text button when maximized is moving awat frm the textfield.Help Me.
VIEWS ON THIS POST

127

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

118

Posted on:

Wednesday 17th October 2012
View Replies!

making buttons circular

hey , im wondering if theres an easy way to make jbutton circular instead of rectangular. Suppose if i have a: class Mybutton extends JButton{ } im guessing i would have to override paintComponent but im not too good on the swing side of things. If anyone has any suggestions let me know. Sincely, Chris Dancy
VIEWS ON THIS POST

74

Posted on:

Thursday 18th 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

175

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

163

Posted on:

Thursday 18th October 2012
View Replies!