header color and the cursor double headed arrow in JTable is not visible




I am using NetBeans 6.7.1

In this desktop app after the user imports a file, the data is displayed in the JTable.

Before the file is imported the JTable is setVisible(false)

Once the user selects a file to open the code is below

tableScrollPane.setVisible(true); jTable1.setVisible(true); DataFileTableModel model = new DataFileTableModel(dataList); jTable1.setModel(model); jTable1.getTableHeader().setBackground(Color.blue); jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //HERE is the code to assign the width of the column equal to the length of the header text
Posted On: Wednesday 17th of October 2012 09:27:45 PM Total Views:  93
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




Change Background color on button Click

Hi I want to change Background color of Jpanel and its font on button click. Can anyone tell me what i am doing wrong Here is the code: import java.applet.*; import java.awt.*; import java.awt.image.BufferedImage; import java.awt.event.*; import javax.swing.*; public class test3 extends Applet { JPanel c; JScrollPane s; Button connect; Panel controls; Color back,fore; public void init() { back = Color.black; fore = Color.white; setBackground(Color.darkGray); setLayout(new BorderLayout()); s = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); //s.setSize(100, 100); add("Center",s); c = new myCanvas11(this); s.setOpaque(false); s.setViewportView(c); //s.add(c); c.setSize(1000, 16000); add("North", controls = new Panel()); controls.setLayout(new FlowLayout()); controls.add(connect = new Button("Change Color")); } public void start() { // s.setScrollPosition(100, 100); } public boolean action(Event e, Object arg) { back = Color.magenta; fore = Color.blue; //setBackground(back); //invalidate(); //repaint(); c.setBackground(back); c.repaint(); //s.getViewport().setBackground(back); // s.getViewport().repaint(); //c.repaint(); c.setFocusable(true); return true; } } class myCanvas11 extends JPanel implements KeyListener { Image buffImage; Graphics offscreen; boolean initDone = false; int chw, chh; // size of a char (in pixels) int chd; // offset of char from baseline int width, height; // size of applet (in pixels) int w, h; // size of applet (in chars) Font fn; Graphics gr; int nh, nw; test3 owner; static int counter = 0; myCanvas11(test3 t) { super(); owner = t; nh = 16000; nw = 1000; this.setOpaque(true); this.setFocusable(true); addKeyListener(this); } public void reshape(int nx, int ny, int nw1, int nh1) { if (nw1 != width || nh1 != height) { width = nw; height = nh; gr = getGraphics(); fn = new Font("Courier", Font.PLAIN, 11); if (fn != null) gr.setFont(fn); FontMetrics fnm = gr.getFontMetrics(); chw = fnm.getMaxAdvance(); chh = fnm.getHeight(); chd = fnm.getDescent(); // kludge for Windows NT and others which have too big widths if (chw + 1 >= chh) { chw = (chw + 1) / 2; } // work out size of drawing area h = nh / chh; w = nw / chw; buffImage = this.createImage(nw, nh); offscreen = buffImage.getGraphics(); //offscreen.setColor(Color.black); //offscreen.fillRect(0, 0, nw, nh); offscreen.setColor(Color.blue); offscreen.setFont(fn); if (initDone) offscreen.drawString(" World!", 0, 50); else offscreen.drawString("khushbu", 2, 50); initDone = true; offscreen.drawImage(buffImage, 0, 0, this); } super.reshape(nx, ny, nw, nh); } public void paint(Graphics g) { // if (!initDone) // initpaint(g); // else g.drawImage(buffImage, 0, 0, this); //g.drawImage(buffImage, 0, 0, owner.back, this); } public void update(Graphics g) { g.drawImage(buffImage, 0, 0, this); super.update(g); //g.drawImage(buffImage, 0, 0, owner.back, this); } public void initpaint(Graphics g) { try { nh = getHeight(); nw = getWidth(); gr = getGraphics(); fn = new Font("Courier", Font.PLAIN, 11); if (fn != null) gr.setFont(fn); FontMetrics fnm = gr.getFontMetrics(); chw = fnm.getMaxAdvance(); chh = fnm.getHeight(); chd = fnm.getDescent(); // kludge for Windows NT and others which have too big widths if (chw + 1 >= chh) { chw = (chw + 1) / 2; } // work out size of drawing area h = nh / chh; w = nw / chw; buffImage = this.createImage(nw, nh); offscreen = buffImage.getGraphics(); //offscreen.setColor(Color.black); //offscreen.fillRect(0, 0, nw, nh); offscreen.setColor(Color.white); offscreen.setFont(fn); if (initDone) offscreen.drawString(" World!", 0, 50); else offscreen.drawString("khushbu", 2, 50); initDone = true; g.drawImage(buffImage, 0, 0, this); } catch (Exception e) { e.printStackTrace(); } } /** Handle the key typed event from the text field. */ public void keyTyped(KeyEvent e) { } /** Handle the key pressed event from the text field. */ public void keyPressed(KeyEvent e) { String s; offscreen.setColor(owner.fore); offscreen.setFont(fn); for (int i = counter; i < counter + 25; ++i) { s = Integer.toString(i); offscreen.drawString(s, 3, i * chh); offscreen.drawLine(10, i * chh, 160, i * chh); } //owner.s.setScrollPosition(0, counter * 16); counter = counter + 25; repaint(); } /** Handle the key released event from the text field. */ public void keyReleased(KeyEvent e) { } public boolean keyDown(Event e, int k) { String s; offscreen.setColor(owner.fore); offscreen.setFont(fn); for (int i = counter; i < counter + 25; ++i) { s = Integer.toString(i); offscreen.drawString(s, 3, i * chh); offscreen.drawLine(10, i * chh, 160, i * chh); } //owner.s.setScrollPosition(0, counter * 16); counter = counter + 25; repaint(); return true; } }
VIEWS ON THIS POST

71

Posted on:

Saturday 22nd September 2012
View Replies!

Trouble with JEditorPane changing colors with styles

I'm using Styles to change the color of my reserved words, but its changing incorrectly, its changing right when I type in the first line but in the next lines only part of the word is changed, what is wrong with my code\t the problem! Uploaded with ImageShack.us this is the code -> public void doFindText(String find) { SimpleAttributeSet bluAttr = new SimpleAttributeSet(); StyleConstants.setForeground(bluAttr, Color.BLUE); SimpleAttributeSet GreenAttr = new SimpleAttributeSet(); StyleConstants.setForeground(GreenAttr, Color.GREEN); int nextPosn = 0; if (!find.equals(findText) ) // *** new find word findPosn = 0; // *** start from top nextPosn = nextIndex( Ed_Prog.getText(), find, findPosn, false); if ( nextPosn >= 0 ) { //Ed_Prog.setSelectionStart( nextPosn-1 ); // position cursor at word start //Ed_Prog.setSelectionEnd( nextPosn + find.length() ); if(find.equalsIgnoreCase("programa")){ Ed_Prog.getStyledDocument().setCharacterAttributes(nextPosn,nextPosn + find.length()+1, bluAttr, false); }else if(find.equalsIgnoreCase("string")){ Ed_Prog.getStyledDocument().setCharacterAttributes(nextPosn-1,nextPosn + find.length()+1, GreenAttr, false); } else if(find.equalsIgnoreCase("inteiro")){ Ed_Prog.getStyledDocument().setCharacterAttributes(nextPosn-1,nextPosn + find.length()+1, GreenAttr, false); } else if(find.equalsIgnoreCase("real")){ Ed_Prog.getStyledDocument().setCharacterAttributes(nextPosn-1,nextPosn + find.length()+1, GreenAttr, false); } findPosn = nextPosn + find.length()+1; // reset for next //search findText = find; // save word & case nextPosn = 0; } else { findPosn = nextPosn; // set to -1 if not found //JOptionPane.showMessageDialog(this, find + " not Found!" ); } }
VIEWS ON THIS POST

75

Posted on:

Saturday 22nd September 2012
View Replies!

Trying to get a square change color on button click

EDIT: Obviously a beginners question! Probably in the wrong forum, please feel free to move mods! Apologies! I thought I'd help myself understanding the GUI and ActionListener proces a bit better by sussing out how to do something simple like putting a button and a rectangle on a screen and then having it change color from blue to red on buttonclick. Appears I've ended up in a swamp and everytime I move I get sucked farther in. I soon found out I have no clue how to easily change the color of something when clicking a button so I thought I'd fake it first by simply running a different color panel on mouseclick. And that failed miserably too! Trying to use the boolean swoosh in two different classes is not the way to go. So a little help, hint or push in the right direction would be greatly appreciated! import javax.swing.*; import java.awt.*; import java.awt.event.*; public class KnopOefen implements ActionListener { JFrame frame; public static void main(String[] args) { boolean swoosh = true; KnopOefen knop = new KnopOefen(); knop.go(); } public void go() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Click to make the square red!"); button.addActionListener(this); Rectangle recty = new Rectangle(); frame.getContentPane().add(BorderLayout.SOUTH, button); frame.getContentPane().add(BorderLayout.CENTER, recty); frame.setSize(300,300); frame.setVisible(true); } public void actionPerformed(ActionEvent event) { boolean swoosh = false; KnopOefen knip = new KnopOefen(); knip.go(); } }
VIEWS ON THIS POST

108

Posted on:

Wednesday 26th September 2012
View Replies!

background and foreground color is not changing in full screen window

why my background and foreground color is not changing\t import java.awt.*; import javax.swing.*; public class mainScreen extends JFrame{ public static void main(String args[]) { DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN); mainScreen ms = new mainScreen(); ms.run(dm); } public void run(DisplayMode dm) { setBackground(Color.PINK); setForeground(Color.GRAY); setFont(new Font("Arial", Font.PLAIN, 24)); Screen s = new Screen(); try{ s.setFullScreen(dm, this); try{ Thread.sleep(5000); }catch(Exception e){} }finally{ s.restoreScreen(); } } public void paint(Graphics g) { g.drawString("This is FullScreen", 200, 200); } }
VIEWS ON THIS POST

71

Posted on:

Wednesday 26th September 2012
View Replies!

JCheckboxMenuItem won't change selection color

guy, Am I doing something wrong or what I want to change the color for the selection background of the JCheckboxMenuItem and it doesn't change at all. This is what I have, what am i doing wrong UIManager.put( "CheckBoxMenuItem.acceleratorForeground", Crawler.color_black); UIManager.put( "CheckBoxMenuItem.acceleratorSelectionForeground", Crawler.color_black); UIManager.put( "CheckBoxMenuItem.background", Crawler.color_white); UIManager.put( "CheckBoxMenuItem.border",BorderFactory.createLineBorder(Crawler.color_white, 1)); UIManager.put( "CheckBoxMenuItem.disabledBackground", Crawler.color_white); UIManager.put( "CheckBoxMenuItem.disabledForeground", Crawler.color_white); UIManager.put( "CheckBoxMenuItem.foreground", Crawler.color_black); UIManager.put( "CheckBoxMenuItem.selectionBackground", Crawler.color_blue); UIManager.put( "CheckBoxMenuItem.selectionForeground", Crawler.color_black);
VIEWS ON THIS POST

64

Posted on:

Wednesday 26th September 2012
View Replies!

Substitute one color with another on an image

Hi! I need to substitute one color with white on an image. I've read about IndexColorMmodel, ColorModel and RGBImageFilter, but I don't understand how they work. The color I want to substitute is: R: 113 G: 75 B: 96 And of course, white is 255,255,255. I've read several examples, but can't grasp all the concepts. I'm new working with images. How can I do it
VIEWS ON THIS POST

46

Posted on:

Thursday 27th September 2012
View Replies!

can't see the background color of a frame , why?

today in college i was trying to set the background color of a jframe but it only shows the color when i resize the frame and not when i just select the radio button but if i set the background color of a panel instead frame it works fine can you explain me why we cant see the background color of a frame /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javachallenge; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; /** * * @author Admin */ public class JavaChallenge extends JFrame implements ActionListener{ /** * @param args the command line arguments */ JRadioButton green,red; JPanel panel; void foo() { panel = new JPanel(); ButtonGroup btngroup = new ButtonGroup(); red = new JRadioButton("Red"); btngroup.add(red); green = new JRadioButton("Green"); btngroup.add(green); panel.add(red); panel.add(green); add(panel,BorderLayout.SOUTH); pack(); red.addActionListener(this); green.addActionListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { // TODO code application logic here new JavaChallenge().foo(); } @Override public void actionPerformed(ActionEvent e) { if(red.isSelected()) { setBackground(Color.RED); setExtendedState(JFrame.MAXIMIZED_BOTH); // panel.updateUI(); }else { setBackground(Color.GREEN); setExtendedState(JFrame.MAXIMIZED_BOTH); //panel.updateUI(); } } }
VIEWS ON THIS POST

62

Posted on:

Saturday 29th September 2012
View Replies!

how to use rgb color values to set JPanel background color

how to use RGB values to set JPanel Background color, which is not in the color list... i tried like this but not working for me.. int red = 100; int green = 100; int blue = 150; Color myBlue = new Color(red,green,blue); panel.setBackground(Color.myBlue);
VIEWS ON THIS POST

76

Posted on:

Monday 1st October 2012
View Replies!

changing headers on JTable caused other problems

Hi Guys, I'm working with a JTable which sets up certain columns with cell renderers and editors. My application allows the user to change the interface to a different language, so JMenuItems, buttons, etc. change their text and I've set it up so that the header on the JTable changes as well. Two lines of code make that happen: private void changeTableHeaders() { ((JLTableModel)table.getModel()).setHeaders(this.getHeaders()); ((JLTableModel)table.getModel()).fireTableStructureChanged(); }
VIEWS ON THIS POST

123

Posted on:

Monday 1st October 2012
View Replies!

in a JTable, changing column header text alignment for specific columns only

, At what classes should one look at (research) when trying to change the alignment of the header text for a specific column in a JTable I figured out how to change the entire JTableHeader text aligment through the getDefaultRenderer(), but I cannot figure out how to make certain column headers to be aligned left, while others are right.
VIEWS ON THIS POST

140

Posted on:

Monday 1st October 2012
View Replies!

change text area background color at run time.

I have text area which is initially disabled on a button click i am enabling it and I am trying to change background color at run time but its not working. Can any body help me I am doing the below: notesJTextArea.setEditable(editable); Color color = Color.white; notesJTextArea.setBackground(color);
VIEWS ON THIS POST

102

Posted on:

Monday 1st October 2012
View Replies!

Jtable mouse header cursor

, when the mouse cursor is over the boundary between the headers of two adjacent columns in a jtable, it changes to a double headed arrow, indicating that the column width can be changed by dragging the mouse. How can I put a listener that tells me when the mouse icon has changed from a simpe mouse pointer to a double headed arrow
VIEWS ON THIS POST

74

Posted on:

Tuesday 2nd October 2012
View Replies!

Problem in passing color as a parameter

, below code is for bounce multiple balls, my code is working correctly, but when i m trying to add Color also as a parameter, it not changing the color of the balls, code is: Point.java import java.applet.*; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; public class Point extends Applet implements Runnable{ private Image i; private Graphics doubleG; Cfish f,f1,f2; public void init() { setSize(800,600); } public void start() { f = new Cfish(); f1 = new Cfish(250,250); f2 = new Cfish(350,350); Thread thread = new Thread(this);//if this confuses run method can also be done here... thread.start(); } public void run() { while(true) { f.update(this); f1.update(this); f2.update(this); repaint(); try { Thread.sleep(17); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void update(Graphics g) { if(i == null) { i = createImage(this.getSize().width, this.getSize().height); doubleG = i.getGraphics(); } doubleG.setColor(getBackground()); doubleG.fillRect(0, 0,this.getSize().width, this.getSize().height); doubleG.setColor(getForeground()); paint(doubleG); g.drawImage(i, 0, 0, this); } public void paint(Graphics g) { f.display(g); f1.display(g); f2.display(g); } }
VIEWS ON THIS POST

39

Posted on:

Wednesday 3rd October 2012
View Replies!

background color is not changing?

hello i m having some problem in the below code, my background color is not going to change to green, can anyone tell me why and also how can i set an image as my background here package game; import java.awt.*; import javax.swing.JFrame; public class gameMain extends JFrame { public static void main(String[] arg) { DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN); gameMain b = new gameMain(); b.run(dm); } public void run(DisplayMode dm) { setBackground(Color.GREEN); setForeground(Color.BLUE); setFont(new Font("Arial", Font.PLAIN, 24)); screen s = new screen(); try{ s.setFullScreen(dm, this); try{ Thread.sleep(5000); }catch(Exception ex){} }finally{ s.restoreScreen(); } } public void paint(Graphics g){ if(g instanceof Graphics2D){ Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } g.drawString(" it's me punit.", 200, 200); } }
VIEWS ON THIS POST

56

Posted on:

Wednesday 3rd October 2012
View Replies!

converting a string color to an object color

Would any one please shed a light. how to convert a String like: String colorStr = "Red"; to an Object Color.red
VIEWS ON THIS POST

76

Posted on:

Wednesday 3rd October 2012
View Replies!

how to color a particular word in a jtextpane?

i have searched in the google but all examples are quite complex so this is my code can you give a example code to color a particular text like "void" so that i can learned it in a simple way please package highlighter; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultHighlighter; /** * * @author Admin */ public class Highlighter implements KeyListener{ /** * @param args the command line arguments */ JTextPane text; void gui() { JFrame frame = new JFrame(); text = new JTextPane(); frame.add(text, BorderLayout.CENTER); String s = text.getText(); s.indexOf(s); int lenght = s.length(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { // TODO code application logic here new Highlighter().gui(); } public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { throw new UnsupportedOperationException("Not supported yet."); } public void keyReleased(KeyEvent e) { throw new UnsupportedOperationException("Not supported yet."); } }
VIEWS ON THIS POST

79

Posted on:

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

85

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

103

Posted on:

Wednesday 17th October 2012
View Replies!

How to retrieve constant for bg-color of a JPanel?

Defining a central constant referring to the default background color of a JPanel I do the following as a first approach: public static final Color DEFAULT_BG_COLOR = new JPanel().getBackground();
VIEWS ON THIS POST

42

Posted on:

Wednesday 17th October 2012
View Replies!

awt colors

I'm looking for a color navy blue in Awt. I have seen the colors in AWT. java.awt.Color; But I want navy blue. How would I get it in AWT Can anyone please help me
VIEWS ON THIS POST

50

Posted on:

Wednesday 17th October 2012
View Replies!