Empty JPanel's aren't invisible


I've been trying to get JTextFields onto my JFrame using the GridBagLayout. I've managed to do this. I was recommended to use empty JPanels with weightx / weighty set as 1, in order to space things out like I wanted. This seemed to work until I put a jpg image onto my frame, and I noticed 2 small grey(same colour as regular background) squares in the centres of the regions where I placed the 2 empty JPanels.

Is there anyway of getting rid of these squares, or doing it some other way\t
Posted On: Thursday 18th of October 2012 02:03:13 AM Total Views:  74
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




How to make a JFrame transparent with solid border

Hi , I am wondering how to make the content pane of a JFrame transparent, but not its border. The border is still opaque and solid. Does anyone have ideas
VIEWS ON THIS POST

176

Posted on:

Friday 21st September 2012
View Replies!

easiest way to create & setting jpanels?

I am try to creating 21 jpanels with different ways... 1. drag & drop from eclipse windowsbuilder 21 times so each time its code like with settings also JPanel panel_example = new JPanel(); panel_example.setBackground(new Color(245, 245, 245)); panel_example.setFont(new Font("Trebuchet MS", Font.PLAIN, 12)); panel_example.setBorder(new LineBorder(new Color(0, 0, 0), 1, true)); panel_example.setBounds(78, 68, 86, 82); panel_example.setLayout(new BorderLayout(0, 0));
VIEWS ON THIS POST

129

Posted on:

Saturday 22nd September 2012
View Replies!

Trying to make a JScrollbar transparent

My JScrollPane is transparent by setting the Viewport.setOpaque(false). Works fine, but I'd like to have the JScrollBar (Vertical in this case) transparent too. scrollBar.setOpaque(false) doesn't do anything, nor does setting scrollBar foreground/background colors do anything. In looking at JScrollBar source code, I don't see where the drawing takes place. Or is that actually in the JScrollPane
VIEWS ON THIS POST

79

Posted on:

Saturday 22nd September 2012
View Replies!

close the parent widow when user selects YES_OPTION from JOptionPane

I have implemented a JOptionPane confirm dialog with YES NO option with the code below int result = JOptionPane.showConfirmDialog((Component) null, "Do you really want to quit", "alert", JOptionPane.YES_NO_OPTION); I can get the user response with the code below if (result == JOptionPane.YES_OPTION) { System.out.println(" you selected YES option");} I want to close the parent window when user selects YES_OPTION. How can I do this
VIEWS ON THIS POST

57

Posted on:

Saturday 22nd September 2012
View Replies!

overlapping problem of jpanels

As i got reply from Wendy Gibbons in JDBC section's topic which i created worry about other considerations when you have the simplest version working. Here i try simplest version as per my thought. I make simple swing program (Just swing no jdbc or hibernate & db), Name simpleExample.java Contains 1 JFrame, Array of jpanels.(only 3 jpanels i create by array). Major code is here., but i modified it as i try in 2-3 days after last post in that question. If you want to see how it developed, 1. 3 questions regarding JPanel. Creation of problem:- When program runs 3 panels we can see, 0,1,2. If we drag & drop panel 0 on panel 2, it will locate beside it because code goes to check_overlap_panel(); & run for loop & check if condition & set as below. simpledm.comp_panel.setLocation(simpledm.comp_panel.getX()+25, simpledm.comp_panel.getY()+25); but when we drag & drop panel 1 on panel 2,it will do same for checking ovelaping against panel 2, & setlocation as per above quote,but it forget already that location occupy by panel 0. Problem panel 1 not try to cross check overlap against panel 0. If i increase myindex = any number, then it should be try to setlocation of panel as avoid overlap against another panel. I try my best & then post question...I also try sscce for code What i do:- Here i try to create 13 boolean flags to check many if-else conditions & for easiness i create 5 functions Conditions like 1. In check_resolutionboundries() function i check panel should not move beyond systems resolution, so if program run on any monitor which has any resolution, then it will run without trouble. This function i called in mousedragged event. 2. When program runs all integers are 0 so 1st condition is check integer against 0 in function check_int_zero(). 3. When function check_int_zero() calls in chek_flags(), to check probability of flags true & false. 4. check_overlap_panel() function contain code for checking panels overlap or not. private void check_overlap_panel() { for (Counter= 0; Counter < panels.length; Counter++) { if (simpledm.comp_panel.getBounds().intersects(simpleExample.panels[Counter].getBounds())) { if (Integer.parseInt(simpledm.comp_panel.getName()) != Integer.parseInt(panels[Counter].getName())) { Flag_over= false; }else { Flag_over = true; }}}}
VIEWS ON THIS POST

166

Posted on:

Monday 24th September 2012
View Replies!

Array of jpanels within JScrollPane

I try to create Array of jpanels within JScrollPane... I partially done same but instead of JScrollPane i created jpanel....you can see code here. Here i write simple code for JScrollPane import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; public class scp { static int Array_counter = 11; static int counter,j,k = 0; static JPanel[] panels = new JPanel[Array_counter]; static JLabel[] labels = new JLabel[Array_counter]; JFrame myframe = new JFrame(); sp bgp = new sp(); int sys_want_w, sys_want_h; Point locations; Point locations1; public void mygui() { GraphicsEnvironment env = GraphicsEnvironment .getLocalGraphicsEnvironment(); System.out.println(env.getMaximumWindowBounds()); sys_want_w = env.getMaximumWindowBounds().width; sys_want_h = env.getMaximumWindowBounds().height; JScrollPane myjScrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); myjScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black, 1)); myframe.setSize(800, 600); myframe.setLocationRelativeTo(null); myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myframe.setVisible(true); myframe.setResizable(true); bgp.setLayout(null); bgp.setSize(new Dimension(364, 96)); bgp.setOpaque(true); bgp.setBorder(BorderFactory.createLineBorder(Color.black, 1)); Rectangle r1 = new Rectangle(myjScrollPane.getX(), myjScrollPane.getY(),myjScrollPane.getWidth(), myjScrollPane.getHeight()); bgp.setBounds(r1); myjScrollPane.add(bgp); myjScrollPane.computeVisibleRect(r1); myjScrollPane.setBounds(myframe.getX(),myframe.getY(),myframe.getWidth(),myframe.getHeight()); myjScrollPane.setViewportView(bgp); myjScrollPane.computeVisibleRect(bgp.getBounds()); myframe.getContentPane().add(myjScrollPane); for (counter = 0; counter < panels.length; counter++) { panels[counter] = new JPanel(); panels[counter].setLayout(new FlowLayout()); panels[counter].setBackground(new Color(255, 255, 204)); panels[counter].setSize(25, 25); panels[counter].setBorder(BorderFactory.createLineBorder(Color.black,1)); panels[counter].setName(String.valueOf(counter)); labels[counter] = new JLabel(); labels[counter].setText(String.valueOf(counter)); panels[counter].add(labels[counter], null); panels[counter].setOpaque(true); Point locations = new Point((0 + (26 * k)), ((j))); k++; panels[counter].setLocation(locations); bgp.add(panels[counter]); } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new scp().mygui(); } }); } class sp extends JPanel { private static final long serialVersionUID = 1L; Image image; public sp() { try { image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("bg.jpg"), "bg.jpg")); } catch (Exception e) { /* handled in paintComponent() */ } } @Override protected void paintComponent(Graphics gr) { super.paintComponent(gr); if (image != null) gr.drawImage(image, 0, 0, sys_want_w - 8, sys_want_h - 35, this); } } }
VIEWS ON THIS POST

140

Posted on:

Tuesday 25th September 2012
View Replies!

how to calculate cpu/memory utilizing by jcomponents/jpanels/Jframe?

I create 1 Jframe in that 1 big jpanel fitted to that JFrame. In that jpanel i create array of jpanels(small) say n numbers...n=5,6,7,,9...up to...99. size (25,25) Now i want print statement which shows cpu/memory utilized by each panel/component...
VIEWS ON THIS POST

157

Posted on:

Tuesday 25th September 2012
View Replies!

gridlayout not working with custom jpanel and jscrollpane; my jpanels get cut off

I'm trying to add my own implementation of jpanel to another jpanel, in a scrollpane, so that as it adds more it will make a list of them down the screen. Unfortunately I can't seem to put space between my jpanels; when I set the second two gridlayout parameters, parts of them get cut off (so that they appear shorter vertically). Any idea why this is happening or how to get around it (called from a method in a jframe class) miniPanel = new JPanel(); miniPanel.setLayout(new java.awt.GridLayout(100, 4,0,60)); for(int i=0;i
VIEWS ON THIS POST

202

Posted on:

Tuesday 25th September 2012
View Replies!

empty Jframe

im quite new to java (and this forum)and this is a class for an IRC bot i am experimenting with using the pircbotx 1.6 api. I have a frame from another class that opens and gets disposed before this is called. When this frame opens it is just an empty frame that you cant see have i done something wrong in the code or is this caused by something else Here is the class (I put it on pastebin as it is 258 lines long): Display.class Also i originally had it without the JTabbedPane (still the problem mentioned above) have i added it correctly as i have never used it before
VIEWS ON THIS POST

55

Posted on:

Wednesday 26th September 2012
View Replies!

How to get parent frame of a JMenuItem (or its ActionListener)

I am trying to implement a message dialog to be shown when a JMenuItem is selected. I want the dialog window to appear centered in the Application's window. So I need acess to the ParentFrame so I can do this: myMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Component parentFrame = \t\t; JOptionPane.showMessageDialog(parentFrame, "Message goes here"); } });
VIEWS ON THIS POST

70

Posted on:

Sunday 30th September 2012
View Replies!

Drawing a Transparent PNG

I'm trying to draw a translucent PNG onto a JPanel: alphaImage = new ImageIcon("alphaImage.png").getImage(); //Get the translucent image currentGraphics.drawImage(alphaImage, affineAngle, null); //Draw using JPanel graphics object
VIEWS ON THIS POST

30

Posted on:

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

58

Posted on:

Wednesday 17th October 2012
View Replies!

adding container's parent to itself error

Problem code : private void tryM (StyledDocument textPaneU, int integerF, String stringA, SimpleAttributeSet attributesJ) { //This is the method try { textPaneU.insertString(integerF, stringA, attributesJ); } catch(Exception eafff) { eafff.printStackTrace(); } } //Later...This is it being used... StyledDocument fqDOC = new DefaultStyledDocument(); SimpleAttributeSet fqPaneAttrs = new SimpleAttributeSet(); JTextPane fqPane = new JTextPane(fqDOC); fqPaneAttrs.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.green); JScrollPane fqScroll = new JScrollPane(fqPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); tryM(fqDOC,0,"Test F&Q", fqPaneAttrs);
VIEWS ON THIS POST

184

Posted on:

Wednesday 17th October 2012
View Replies!

linking two jpanels

i am working a desktop application,in which i am having a jpanel which is a login page,what i want is to move to other jpanel on successful login .
VIEWS ON THIS POST

109

Posted on:

Wednesday 17th October 2012
View Replies!

filtering N number of leaf nodes per parent node

hi. i have a filteredtreemodel that extends DefaultTreeModel what i want to do is at the end of each parent node, i place a Jbutton as a leaf node that says show/hide. when this button is clicked, it will only show like the 1st 5 leaf nodes if button labeled, hide. if it is labeled show, it will display all leaf nodes my problem is that whenever i iterate from the parentnode using either getChildAt() or children() from the DefaultMutableTreeNode and i loop the nodes one by one, it doesn not seem to be in order if it was displayed in order, this would be easy. however it is not and i cant understand why it's outputted in random and not in sequence as when you added them to the treemodel. anyone got ideas
VIEWS ON THIS POST

35

Posted on:

Wednesday 17th October 2012
View Replies!

Child Frame's compoenent (JFrame) is not displayed till parent frame exceution

I am using JFrame and i have OK button. If we click on the OK button then message "Service Updating..." should display in the child frame or Dilaog and the parent process should not be blocked. Currently the problem we are phasing is Child JFrame component (JLabel) is not displayed till the parent process gets exceuted. Please dot the needful.
VIEWS ON THIS POST

39

Posted on:

Wednesday 17th October 2012
View Replies!

How to detected when a new child is added to a Composite parent?

Hi all, Could anyone please help me out on this I am trying to figure out a way of detecting whenever a child is added to a SWT Composite parent. Any suggestions please THanks
VIEWS ON THIS POST

42

Posted on:

Wednesday 17th October 2012
View Replies!

how to make Canvas transparent ?

all, sorry for the double posting but its different subject . i have Canvas and i like to make its background transparent , but with no luck the canvas is create on canvas parent . can it be done with canvas or i need to use other control
VIEWS ON THIS POST

44

Posted on:

Wednesday 17th October 2012
View Replies!

How to make popup invisible

If I run the following application and then right-click on the application, a popup menu will show up. If I move mouse outside the frame (I try to make JComponent visible so that I can move mouse outside JComponent, but I cannot make it happen), popup menu is still visible. I try to add the following to mouseExited method: popupMenu.setVisible(false); or add the following to let popup listen to mouse listener: popupMenu.addMouseListener(new MouseListener(){ public void mouseExited(final MouseEvent e) { System.out.println("Mouse Exited..."); popupMenu.setVisible(false); //line added } public void mouseEntered(final MouseEvent e) { System.out.println("Mouse Entered..."); } public void mousePressed(final MouseEvent e) { System.out.println("Mouse pressed..."); } public void mouseReleased(final MouseEvent e) { } public void mouseClicked(final MouseEvent e) { System.out.println("Mouse Clicked..."); } });
VIEWS ON THIS POST

79

Posted on:

Thursday 18th October 2012
View Replies!

How do I get layered items to show outside the parent frame?

Ok, I don't know if what I'm asking is possible, and I haven't worked with layered items and such before now. However, here's the code I've got thus far: import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.lang.Integer; import java.awt.Color; public class Layers extends JFrame implements ActionListener { JLayeredPane mainScreen = new JLayeredPane(); JPanel sub1 = new JPanel(); JPanel sub2 = new JPanel(); JButton close1 = new JButton("Close Button #1"); JButton close2 = new JButton("Close Button The Second"); JButton close3 = new JButton("The Third Close Button"); public Layers() { super("Main Stuff");// set title of frame setBounds(0,0,400,300); setBackground(Color.cyan); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); sub1.add(close1); sub1.add(close2); sub2.add(close3); close1.addActionListener(this); close2.addActionListener(this); close3.addActionListener(this); sub1.setBounds(30,30,200,600); sub1.setBorder(BorderFactory.createLineBorder(Color.black)); //sub1.setOpaque(false); sub1.setBackground(Color.blue); sub2.setBounds(80,145,300,300); sub2.setBackground(Color.green); sub2.setBorder(BorderFactory.createLineBorder(Color.black)); mainScreen.add(sub1,new Integer(950)); mainScreen.add(sub2,new Integer(500)); setContentPane(mainScreen); setVisible(true); } public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if ((source == close1) || (source == close2) || (source == close3)) System.exit(0); } public static void main (String[] arguments) { Layers rb = new Layers(); rb.show(); } }
VIEWS ON THIS POST

48

Posted on:

Thursday 18th October 2012
View Replies!