JScrollPane background color




I have a JScrollPane that contains a JLabel. The function of this section of the program is to open an image onto that JLabel. But what I need is two things;
1. I need to have the area inside the scroll pane to be white before the image loads.
2. Once the image has loaded, I need the area around the image to be white.

Here is the code that I've tried to do it, but it doesn't work, the background stays gray.


JPanel compressedImagePanel = new JPanel(new BorderLayout());
compressedImagePanel.setBackground(Color.WHITE);
JLabel compressedImageLabel = new JLabel();
compressedImageLabel.setBackground(Color.WHITE);

JScrollPane comPane = new JScrollPane(compressedImageLabel,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
comPane.setBackground(Color.WHITE);

compressedImagePanel.add(comPane);

As you can see, I've set EVERYTHING to white. Am I doing it in the wrong order or is there another trick to it

Posted On: Tuesday 23rd of October 2012 11:33:58 PM Total Views:  291
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




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

267

Posted on:

Tuesday 25th September 2012
View Replies!

how to change the background color of Buttons in a JPanel?

hey I know how to change the background color for buttons. but if you 50 button in a panel and you want all of them to have same color. it's really hard to write code for 50 button or 200 button a panel to chage thier color. is there a way to change all with very simple code. Jbutton1.setbackground(Color.red) ........... Jbutton50.setBackground(color.red)
VIEWS ON THIS POST

111

Posted on:

Wednesday 17th October 2012
View Replies!

update the JVM from 1.5 to 1.6, JDialog background cant paint

package test; import java.lang.reflect.InvocationTargetException; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class TestXXX { public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { new FrameX(); } }); } catch (InterruptedException e) { } catch (InvocationTargetException e) { } } }
VIEWS ON THIS POST

142

Posted on:

Wednesday 17th October 2012
View Replies!

How to resize an image, where extra space is filled with a background color

For example, I want to resize an image with size 3 x 5 pixels, to 10 by 15, keeping the ratio. To keep the ratio, the result is 9 x 15. There is a 1 pixel area that I want to fill with, say, white color. Do you have an idea how it is done
VIEWS ON THIS POST

135

Posted on:

Wednesday 17th October 2012
View Replies!

Adding background image to JDesktopPane

How am I going to do that import java.awt.*; import java.net.URL; import java.util.Arrays; import javax.swing.*; import java.awt.event.*; import javax.swing.ImageIcon; import javax.swing.JMenuBar; public class mainPg extends JFrame { private JLabel statusBar = new JLabel(); private JMenuItem menuHelpAbout = new JMenuItem(); private JMenu menuHelp = new JMenu(); private JMenuItem menuFileExit = new JMenuItem(); private JMenu menuFile = new JMenu(); private JMenu menuSuper = new JMenu(); private JMenu menuAdmin = new JMenu(); private JMenuItem menuSuperdrop = new JMenuItem(); private JMenuItem menuSuperdrop2 = new JMenuItem(); private JMenuItem menuSuperdrop3 = new JMenuItem(); private JMenuBar menuBar = new JMenuBar(); private JPanel panelCenter = new JPanel(); private BorderLayout layoutMain = new BorderLayout(); private JDesktopPane desktop; private JMenuItem login = new JMenuItem(); private ActionMap actionMap1 = new ActionMap(); public adminResult aR = null; public finalist f = null; //public finalist f = new finalist(); //public votingPg vpg = null; //String[][] namelist = new String[8][2]; static int[] numvote = new int[8]; static int[] unsorted = new int[8]; private JMenuItem jMenuItem1 = new JMenuItem(); int j =0; int k =0; int l =0; int num; String name; boolean count; Class metaObject = this.getClass(); URL url = metaObject.getResource("images/superstar.jpg"); ImageIcon imageIcon = new ImageIcon(url); Image image = imageIcon.getImage(); public mainPg() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } globals.mp = this; } public static String announceResult(int avote) { String name = globals.test[avote]; return name; } public void visi(boolean b) { menuSuperdrop2.setEnabled(b); } public void visi2(boolean b2) { menuSuperdrop3.setEnabled(b2); } public void visi3(boolean b3) { login.setEnabled(b3); } private void jbInit() throws Exception { count = false; this.setJMenuBar(menuBar); this.getContentPane().setLayout(layoutMain); panelCenter.setLayout(null); this.setSize(new Dimension(645, 600)); this.setTitle("Project Sup3rStar"); menuFile.setText("File"); menuSuper.setText("Sup3rStar"); menuAdmin.setText("Administrator"); menuSuperdrop.setText("Finalist"); menuSuperdrop2.setText("Vote"); menuSuperdrop3.setText("Result"); menuFileExit.setText("Exit"); jMenuItem1.setText("Restart"); desktop = new JDesktopPane(); //a specialized layered pane login.setText("Login"); setContentPane(desktop); menuFileExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { fileExit_ActionPerformed(ae); } } ); jMenuItem1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jMenuItem1_ActionPerformed(ae); } } ); ..................................continues....
VIEWS ON THIS POST

92

Posted on:

Wednesday 17th October 2012
View Replies!

Whats the best way to change background of treeNode in JTree

Greetings Ranchers, I'm trying to change the background of a treeNode to get a hovering effect on mouseOver(); evrything seems to work so far...except I'm updating my whole tree UI; this is causing flickering of my cursor. Is there another way of changing the background of tree node without whole tree updateUI() //In TreeRenderer if (selected)// selection flag { setForeground(Color.white); setBackground(NavyBlueColor); } else if (flag) //mouseEntered flag { setForeground(Color.white); setBackground(Color.LIGHT_GRAY); } //Mouse Hovering effect if(mouseEntered) { // update the treeRenderer to make changes to foreground & background; tree.updateUI(); }
VIEWS ON THIS POST

86

Posted on:

Thursday 18th October 2012
View Replies!

JTextField background color and UIManager

I have a JPanel and on it is a JTextField. Now I want to set the color of the JTextField to be the same as that of the JPanel. So I try this... Color c = UIManager.getColor("Panel.background"); attachField.setBackground(new Color(c.getRed(), c.getGreen(), c.getBlue()));
VIEWS ON THIS POST

78

Posted on:

Thursday 18th October 2012
View Replies!

jtable and jscrollpane question

hey, I have a JTable in a JScrollPane. My application is designed to have this table take up most of the screen. Sometimes the table has hundreds of rows of data in it and everything works well. However, sometimes it only has three rows in it and it looks very bad inside of the scrollPane. I would like my table to be full screen all the time regardless of the actual number of rows of data it has. Is there an easy way to do this or do I have to add "blank" rows to my table whenever I detect this condition
VIEWS ON THIS POST

183

Posted on:

Thursday 18th October 2012
View Replies!

Change background/foreground color of a disablled object

How I can change background/foreground color of a disablled object (i.e. JCheckBox, JTextField and so on..) Thank you, very much! Domenico
VIEWS ON THIS POST

93

Posted on:

Sunday 21st October 2012
View Replies!

background bleed-through when using getInsets.

Hi all, I'm new to Java programming, and I'm Eclipse Indigo on a WinXP machine. I'm reading a beginner's book and learning to use the Swing classes. I notice that when I use getInsets on a JFrame subclass that the border region somehow contains the background of my desktop behind it. That border region is not actively transparent because I can drag my frame around on my desktop and the image in the border region does not change - it remains looking like the background of whatever the desktop looked like when the frame first appeared. If I drag another window (say Word) on top of my frame and then move it off the frame, then the border region of the frame is suddenly opaque as expected. Is there anything I can do to stop the border region of my frame from copying in images of the desktop behind it
VIEWS ON THIS POST

91

Posted on:

Sunday 21st October 2012
View Replies!

JTable inside JScrollPane - background coloring problem

I have a situation with a table that's narrower and shorter than the enclosing scroll pane's viewport, and column auto-resizing is turned off, so there's empty space below and to the right of the table. I'd like to fill the empty space with a single background color. I can fill in the bottom using scrollPane.setBackground(), and I can set most of the right side using scrollPane.getViewport().setBackground(). But I'm still left with an uncolored strip to the right of the table's column headers. I've tried using setBackground on the scroll pane's enclosing panel, and also tried using scrollPane.setColumnHeaderView() to force a new colored JPanel, but neither method has worked. Is there any way to fill in that strip right of the table's column headers Below is the code I'm using, a slight variation of TableDemo.java from Oracle's Swing Example set.
VIEWS ON THIS POST

168

Posted on:

Monday 22nd October 2012
View Replies!

JButton with icon as background and button name as pop up

I want to create a few buttons vertically on right side of a window, these buttons take images/icons as background, but do not show button name, only when mouse is moved to the button, button name will be shown beside the mouse, like those icons on the tool bar. And when a checkbox is clicked, these button can be disabled. Could I use Jbutton to do this How
VIEWS ON THIS POST

107

Posted on:

Monday 22nd October 2012
View Replies!

What the heck!? JPanel background problem - weird!

Ok, so I got the background image working on my first window, then I went to add it to a second window and the weirdest thing happened. Two different applications (one called by the other), two different images (different names), but both windows display the same image. Here's the code: First application: class BackgroundPanel extends JPanel { Image image; public BackgroundPanel(int size[]) { try { image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("jeep03.jpg"), "jeep03.jpg")); size[0] = image.getWidth(null); size[1] = image.getHeight(null); } catch (Exception e) { /*handled in paintComponent()*/ } return; } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (image != null) g.drawImage(image, 0,0,this.getWidth(),this.getHeight(),this); } }
VIEWS ON THIS POST

120

Posted on:

Monday 22nd October 2012
View Replies!

JMenuBar showing gradient background on Mac -- how to disable?

JMenuBar on Mac OS adds a gradient, which I don't want. See the simple example below. (Note, the gradient is very subtle. Using Mac OS's DigitalColorMeter utility, you can detect it.) Does anyone know how I can get rid of it. No matter what I set the background color to, it adds this subtle gradient on top of it. UIManager.get("MenuBar.gradient") returns null. Any ideas import javax.swing.*; public class Test extends JFrame { public Test() { JMenuBar menuBar = new JMenuBar(); menuBar.add(new JMenu("Menu 1")); menuBar.add(new JMenu("Menu 2")); setJMenuBar(menuBar); JPanel panel = new JPanel(); panel.add(new JLabel("Test Label")); getContentPane().add(panel); setSize(100, 100); setVisible(true); } public static void main(String[] args) { new Test(); } }
VIEWS ON THIS POST

74

Posted on:

Monday 22nd October 2012
View Replies!

how to set background of SWT MenuBar

, Can anyone tell me how can i set background color of a menu Bar (in SWT) I cant find setBackground method in Menu class...
VIEWS ON THIS POST

81

Posted on:

Monday 22nd October 2012
View Replies!

jTable background? problem

i built this jTable, played with setbackground and setOpace on jtable, jScrollPane and Jpanel, but without results in getting what i want: when displaying a table, i want that the remaining space between rows and the space i initialy gave jtable to display shows white (imagine i gave jtable 400 x 400 and only have one single row - the remaining space displays in gray and i want it to be white) how can i achieve it TiA
VIEWS ON THIS POST

85

Posted on:

Monday 22nd October 2012
View Replies!

How to display an image in the background of a JTable with customized rendrer?

I am working on one desktop application. I have JTable displayed on top of the Scroll Pane. Now the requirement is to display company logo in the background. I am using customized rendrer to display the non editable columns in grey etc.. So how can I display the image in the background
VIEWS ON THIS POST

101

Posted on:

Monday 22nd October 2012
View Replies!

JButton is not displaying the background color

Hi , I have a JButton that pops up the color chooser on click and changes its background color when a new color is selected. This works fine unless I change the LookAndFeel of the dialog containing the button as follows. UIManager.setLookAndFeel(new WindowsLookAndFeel()); When the LookAndFeel is set, it appears like the button is on a panel, and the panel is changing its background color. I understand that on WindowsLookAndFeel a gradient is drawn on top of the button to display that 3D look which is why the background color is not being shown. Just wondering if there is a work around for this.
VIEWS ON THIS POST

87

Posted on:

Monday 22nd October 2012
View Replies!

background problem

Hi , I want to put an image to the background of my tab(panel) in the TabbedPane, but I do not know how to do it. So how can I do this
VIEWS ON THIS POST

74

Posted on:

Tuesday 23rd October 2012
View Replies!

Change the background of combobox in disabled mode

Hi all, How do i change the background color of the combobox to white in disabled mode. I have used UIManager.put ( "ComboBox.disabledBackground", Color.WHITE ); This is actually making the background color of the combo box to white. But the problem is when i apply this, the background color of the combo box is changed to white throughout the application. I want the color to change to white only in one screen . How do i do this Kindly help me in this regard regards smriti
VIEWS ON THIS POST

75

Posted on:

Tuesday 23rd October 2012
View Replies!