java code for round rectangle java swing button


I need a code that should extends the JButton and tje button have the round rect edges JButton Thank U
Posted On: Tuesday 23rd of October 2012 11:28:46 PM Total Views:  185
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




BackgroundPanel.java cannot be placed in BorderLayout.NORTH

i am trying to put a picture on the top of my swing GUI that stretches horizontally to fit the width of the window as it resizes http://www.camick.com/java/source/BackgroundPanel.java this is the code for a commonly used function that scales images to their components size. it works by overloading the paintcontainer class, which is called every time the window resizes, which then calls the paint class. they simply grab the size of the container and draw the image to those dimensions the image that needs to be resized must be placed in BorderLayout.NORTH, because the rest of my GUI is in BorderLayout.CENTER, but BackgroundPanel cant be placed in NORTH, the image disappears, even with a minimum size set. it cant be placed inside a panel inside a panel inside NORTH either. ive been reading over the code for BackgroundPanel and its driving me crazy i cant figure out why here is some short example code, not my program but it simplifies the problem: import java.awt.*; import javax.swing.*; import java.awt.event.WindowEvent; public class JPanel1 extends JFrame { public static void main(String[] args) { new JPanel1(); } public JPanel1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); add(mainJPanel()); pack(); setVisible(true); } //debug space center to streatch private JPanel mainJPanel() { JPanel JPanel = new JPanel(); BorderLayout layout = new BorderLayout(); this.setMinimumSize( new Dimension( 224, 224 ) ); JPanel.setLayout(layout); JPanel.add(mainJPanel2(),BorderLayout.NORTH); return(JPanel); } //debug space center to streatch private JPanel mainJPanel2() { JPanel JPanel = new JPanel(); BorderLayout layout = new BorderLayout(); JPanel.setLayout(layout); JPanel.add(JPanel2(),BorderLayout.CENTER); return(JPanel); } private JPanel JPanel2() { BorderLayout layout = new BorderLayout(); this.setLayout(layout); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image duke = toolkit.getImage("sun.jpg"); BackgroundPanel panel = new BackgroundPanel(duke, BackgroundPanel.SCALED); //panel.setMinimumSize( new Dimension( 224, 224 ) ); this.setMinimumSize( new Dimension( 224, 224 ) ); GradientPaint paint = new GradientPaint(0, 0, Color.BLUE, 600, 0, Color.RED); panel.setPaint(paint); return panel; } //exit when closed public void processWindowEvent(WindowEvent event) { if(event.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0); } }
VIEWS ON THIS POST

74

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

76

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

94

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

64

Posted on:

Monday 22nd October 2012
View Replies!

.setBackground JPanel problem

everbody! This my Frame class for tetris and i can't seem to set the background color for any of the JPanels, the color is shown only on the borders of the JPanels. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package tetris; /** * * @author Benjamin */ import java.awt.Color; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; /** * * @author Benjamin */ public class TetrisOkvir extends JFrame { private JMenu meni = new JMenu(); private JMenuItem izhod = new JMenuItem(); private JMenuBar menivrstica = new JMenuBar(); static JLabel labela = new JLabel(); static JLabel labela2 = new JLabel(); static JButton knof = new JButton(); private static IgralnaPlata plata = new IgralnaPlata(); private static PredogledPlata predogled = new PredogledPlata(); /** * */ public TetrisOkvir() { JPanel content = new JPanel(); //labeli za izpis tock in stopnje /// labela.setText("Tocke: " + Integer.toString(plata.padel)); labela2.setText("Stopnja: " + Integer.toString(plata.stopnja)); knof.setText("Zacni"); meni.setText("Meni"); izhod.setText("Izhod"); //****************************// plata.setFocusable(true); content.setLayout(null); content.setBackground(new Color(240,240,240)); izhod.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { System.exit(1); } }); meni.add(izhod); menivrstica.add(meni); setJMenuBar(menivrstica); content.add(predogled); content.add(labela); content.add(labela2); content.add(knof); content.add(plata); predogled.setBounds(350, 50, 150, 150); labela.setBounds(350, 300, 300, 20); labela2.setBounds(350, 330, 300, 20); predogled.setBackground(Color.BLACK); plata.setBackground(Color.BLACK); //predogled.setOpaque(true); //predogled.setForeground(Color.BLACK); predogled.setPreferredSize(new Dimension(150,150)); plata.setPreferredSize(new Dimension(299,600)); //gumb Zacni knof.setBounds(350, 360, 100, 20); knof.setEnabled(true); knof.setFocusable(false); knof.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { plata.padel(); System.out.println("pritisk gumba"); } }); //**************************************************// plata.setBounds(0, 0, 299, 600); setContentPane(content); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); pack(); } /** * * @param args */ public static void main(String[] args) { JFrame okno = new TetrisOkvir(); okno.setTitle("Tetris"); okno.setSize(555, 650); okno.setLocationRelativeTo(null); okno.setResizable(false); okno.setVisible(true); while (plata.th.isAlive()) { predogled.repaint(); } } }
VIEWS ON THIS POST

65

Posted on:

Monday 22nd October 2012
View Replies!

Unsatisfied LinkError: with windows WCanvasPeer setNativeBackgroundErase

, I got a bug which has the following stack trace. java.lang.UnsatisfiedLinkError: sun.awt.windows.WCanvasPeer.setNativeBackgroundErase(Z)V at sun.awt.windows.WCanvasPeer.setNativeBackgroundErase(Native Method) at sun.awt.windows.WCanvasPeer.initialize(WCanvasPeer.java:92) at sun.awt.windows.WCanvasPeer.initialize(WPanelPeer.java:58) at sun.awt.windows.WWindowPeer.initialize(WWindowPeer.java:105) at sun.awt.windows.WDialogPeer.initialize(WDialogPeer.java:48) at sun.awt.windows.WComponentPeer.(WComponentPeer.java:602) at sun.awt.windows.WCanvasPeer.(WCanvasPeer.java:602) ... ... Does anyone know what this error means. I have tried to search in other forums and couldnt find much information.
VIEWS ON THIS POST

72

Posted on:

Monday 22nd October 2012
View Replies!

getting rid of edges on round component

So i posted earlier about making a custom jframe and found that was a bad idea. So What I've decided was to then add a jpanel to the frame and make that round which is not a problem. However the edges of the JFrame still pop out of the corners. Is their anyway way to get rid of that
VIEWS ON THIS POST

56

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

67

Posted on:

Monday 22nd October 2012
View Replies!

Display message in foreground

I have developed an application in Swing. Now when I start a process in the application and then start other applications say ms-word, now when my java process finishes it displays message as 'process finished' with ok button. But as currently ms-word is my foreground process, java message appears at background and user has to press alt+tab to see the message. My question is - Is it possible to bring the message to foreground overriding other applications Thank you.
VIEWS ON THIS POST

33

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

73

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

83

Posted on:

Monday 22nd October 2012
View Replies!

Not able to change Background color of a component

In my JApplet, I am able to change the background color of the panel but not the currentSurface which is an instance of PaintSurface. Could someone please help me out Many thanks import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.geom.*; public class Tanks extends JApplet { public static final int WIDTH = 400; public static final int HEIGHT = 400; private JButton button1; private PaintSurface currentSurface = new PaintSurface(); public Tanks() { this.add(currentSurface,BorderLayout.CENTER); ButtonListener b1 = new ButtonListener(); JPanel panel = new JPanel(); panel.setBackground(Color.white); currentSurface.setBackground(Color.white); button1 = new JButton("Start"); button1.addActionListener(b1); panel.add(button1); this.add(panel,BorderLayout.NORTH); } public void init() { this.setSize(WIDTH, HEIGHT); this.setVisible(true); } private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getActionCommand() == "Start") { currentSurface.figure="Start"; repaint(); } } } } class AnimationThread extends Thread { JApplet c; public AnimationThread(JApplet c) { this.c = c; } public void run() { } } class PaintSurface extends JComponent { String figure; public PaintSurface() { } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if(figure=="Start") { Shape s = new Ellipse2D.Float(20,50,250,150); g2.setPaint(Color.BLACK); g2.draw(s); } } }
VIEWS ON THIS POST

57

Posted on:

Monday 22nd October 2012
View Replies!

back ground image repeating

hey i have a problem. i set the background image to "something.png" its a repeating pattern which is just for the background. Here is the problem. When i resize my frame, the image only spreads so far, and then theres white space. so is there a quick and easy way to get the image to repeat sincerly, Chris Dancy
VIEWS ON THIS POST

49

Posted on:

Monday 22nd October 2012
View Replies!

back ground image repeating

hey i have a problem. i set the background image to "something.png" its a repeating pattern which is just for the background. Here is the problem. When i resize my frame, the image only spreads so far, and then theres white space. so is there a quick and easy way to get the image to repeat sincerly, Chris Dancy
VIEWS ON THIS POST

63

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

72

Posted on:

Monday 22nd October 2012
View Replies!

Background image

I'd like to set the background of a JFrame using a png or jpg file that contains a graphics image, rather than just setting the background colour. I've tried creating a panel, painting the image on the panel and setting it as the frames contentpane but this disturbs the layout when positioned other components on the pane. Any suggestions would be welcome - I'm sure there must be something obvious that I'm missing (been away from Java for 2 years, heaven forbid).
VIEWS ON THIS POST

52

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

65

Posted on:

Tuesday 23rd October 2012
View Replies!

any good open source swing library around here ?

Hi Swing gourous !! After 7 years of web development I've been sent in exile for my sins in the Swing world. Because I'm a lazy boy I'm used to use open source libraries. Do one you, swing gourous tamed by hundreds of years of Swing coding, happen to know one equivalent to Struts
VIEWS ON THIS POST

59

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

67

Posted on:

Tuesday 23rd October 2012
View Replies!

TableCellRenderer with JLabel setBackground help

In a specific instance I need a column of a table to look blank. So I have coded the renderer as follows... class BlankCellRenderer extends JLabel implements TableCellRenderer{ public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected, boolean hasFocus, int row, int column) { setBackground(Color.GRAY); setForeground(Color.red); setText("hello"); return this; } }
VIEWS ON THIS POST

69

Posted on:

Tuesday 23rd October 2012
View Replies!