Search Results

Search found 1571 results on 63 pages for 'swing'.

Page 34/63 | < Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >

  • How to display panel which is of Singleton class in two different frames at a time?

    - by Sriku
    I am trying to display a singleton obj on two different Jframe, but it is displayed only in the Jframe in which the object is added at last ( in example Frame2). Other Jframe is empty. This Singleton class is inherited from Panel and contains a label in it. Can anybody please tell me how can i display this singleton object in two different frame ? public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { NewJFrame inst = new NewJFrame(); inst.setTitle("Frame1"); inst.setSize(300, 300); inst.setLocationRelativeTo(null); inst.setVisible(true); singltonpanel _sin = singltonpanel.instance(); inst.add(_sin); inst.repaint(); JFrame frame = new JFrame("Frame2"); frame.setSize(300, 300); frame.setVisible(true); singltonpanel _sin1 = singltonpanel.instance(); frame.add(_sin1); frame.repaint(); } });

    Read the article

  • Java BoxLayout alignment issue

    - by ManInMoon
    Can anyone help me. Why is the Label "Current" NOT left aligned in Panel/Frame? public static void main(String[] args) { JFrame TFrame = new JFrame("Test DisplayLayout"); TFrame.setResizable(true); TFrame.setSize(new Dimension(900, 840)); TFrame.setLocationRelativeTo(null); TFrame.setTitle("DisplayLayout"); TFrame.setVisible(true); JPanel P = DisplayLayout2(); P.setVisible(true); P.setOpaque(true); P.setLayout(new BoxLayout(P, BoxLayout.Y_AXIS)); TFrame.add(P); TFrame.revalidate(); TFrame.repaint(); } public static JPanel DisplayLayout2() { JPanel Panel=new JPanel(); Panel.setVisible(true); Panel.setOpaque(true); Panel.setLayout(new BoxLayout(Panel, BoxLayout.Y_AXIS)); Panel.setAlignmentX(Component.LEFT_ALIGNMENT); JLabel lab = new JLabel("Current"); lab.setHorizontalAlignment(SwingConstants.LEFT); lab.setForeground(Color.WHITE); lab.setBackground(Color.PINK); lab.setOpaque(true); Panel.add(lab,Component.LEFT_ALIGNMENT); JPanel posPanel = new JPanel(); JScrollPane scrollPane = new JScrollPane(posPanel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setPreferredSize(new Dimension(290, 200)); scrollPane.setOpaque(true); posPanel.setBackground(Color.YELLOW); posPanel.setPreferredSize(new Dimension(290, 200)); posPanel.setLayout(new BoxLayout(posPanel, BoxLayout.Y_AXIS)); posPanel.setAlignmentX(Component.LEFT_ALIGNMENT); Panel.add(scrollPane); return Panel; }

    Read the article

  • Please help me to allow my `JTable` to search the text even the table is in editable mode on key-press

    - by Ashish Pancholi
    If user starts pressing keys using keyboards then JTable is supposed to be searched the matching text for him and if user double clicks on cell then Table should allow him to edit the text. And the issue is - Table is only searching text when the table is in non-editable mode and if Table is editable and user starts typing the text-using keyboard, cell is allowing him to edit the cell rather then search. Mr mKorbel has just solved my issue to allow edit only if double click on Table cell. Please help me to allow my JTable to search the text even the table is in editable mode on key-press.

    Read the article

  • JComobox is not showing in the JDialog

    - by Pujan Srivastava
    I have 2 classes. when I put bold 3 lines in the method addCourses() the dialog does not show combobox in the Panel but when I remove from addCourses and put those bold lines in the constructor, JComboBox are shown in the Panel. But data will not show because data items updates to ComboBox will happen after Constructor is created. How can I solve this problem. this.mainPanel.add(courseCombo, BorderLayout.NORTH); this.mainPanel.add(sessionCombo, BorderLayout.CENTER); this.mainPanel.add(courseButton, BorderLayout.SOUTH); public class Updator { CourseListFrame clf = new CourseListFrame(); for(...){ clf.addContentsToBox(displayName, className); } clf.addCourses(); } and second class is public class CourseListFrame extends JDialog implements ActionListener { public JPanel mainPanel = new JPanel(new BorderLayout(2, 2)); public JButton courseButton = new JButton(("Submit")); public JComboBox courseCombo; public JComboBox sessionCombo; public Multimap<String, String> map; // = HashMultimap.create(); public static CourseListFrame courseListDialog; public CourseListFrame() { super(this.getMainFrame()); this.getContentPane().add(mainPanel); map = HashMultimap.create(); courseCombo = new JComboBox(); courseCombo.addItem("Select Courses"); courseCombo.addActionListener(this); sessionCombo = new JComboBox(); } public void addContentsToBox(String course, String session) { map.put(course, session); courseCombo.addItem(course); } public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); String str = (String) cb.getSelectedItem(); setSessionCombo(str); } public void setSessionCombo(String course) { if (map.containsKey(course)) { sessionCombo.removeAllItems(); Iterator it = map.get(course).iterator(); while (it.hasNext()) { sessionCombo.addItem(it.next()); } } } public void addCourses() { this.mainPanel.add(courseCombo, BorderLayout.NORTH); this.mainPanel.add(sessionCombo, BorderLayout.CENTER); this.mainPanel.add(courseButton, BorderLayout.SOUTH); } public static void showCourseListDialog() { if (courseListDialog == null) { courseListDialog = new CourseListFrame(); } courseListDialog.pack(); courseListDialog.setVisible(true); courseListDialog.setSize(260, 180); } }

    Read the article

  • How can I change the arrow style in a JComboBox

    - by Stephane Grenier
    Let's say I want to use a custom image for the arrow in JComboBox, how can I do this? I understand it's possible using the synth xml files, or maybe even UIManager.put(...), but I don't know how. All I want to do at this time is change the arrow image to something else, either programatically or even just overriding the image it uses. How exactly can I do this?

    Read the article

  • How can I get the text color of a button using the Substance LaF?

    - by DR
    In my Java application I have to custom-paint a control and for that I need to use the same font colors as JButton. (Enabled an disabled) I don't want to to hard-code them, because the user can change the Substance skin at runtime. I'm aware of the ColorSchemes but I'm not sure how to proceed once I have the color scheme of the current skin. Also the Substance documentation says something about creating your own color scheme, but I just can't figure out the way to retrieve a certain color.

    Read the article

  • how to display a image in java application after downloading the image

    - by Nubkadiya
    i want to display a image after downloading that image from a web-server i have wrote the code for downloading the image. but i cant set it up to a label or any thing other than jframe (because i want to add more buttons and labels to the GUI). here is the code to download the image from the webserver. now i want to set it to a label. please help me URL url = new URL("http://www.personal.psu.edu/acr117/blogs/audrey/images/image-2.jpg"); image = ImageIO.read(url);

    Read the article

  • Is there a version of postActionEvent for KeyEvent (specifically for a JTextArea)?

    - by Brian Pelc
    I'm writing a program that contains multiple JTextFields and 2 JTextAreas within an input panel. I have a submit button on the bottom. I have it set up so when a user types something into each field (including the JTextAreas) and hits the Enter key, it updates a text file, and when they press the submit button it updates the file then outputs a new version of it in the local directory. If the user presses Enter in any of the fields, it validates their input, however, I want to re-validate all fields when they press the submit button. Each field (again, JTextAreas included) has it's own validation check within its ActionListener or KeyListener (for the JTextAreas). It's easy enough to use postActionEvent() for the JTextFields, but is there a similar method for the JTextAreas to force fire a KeyEvent? I don't want to duplicate code and consume memory by re-writing the validation for those 2 Components inside the ActionEvent for the JButton. Unfortunately, I can't provide a sample because I'm writing the program on a classified machine (PC).

    Read the article

  • jframe adding own design jinternal frame error

    - by Van Minh
    I designed a title bar color on my JInternal frame. Then I took attempt to add it to my JFrame, but I cannot. Here is the code of my title bar: public class MyIFtitleBar extends BasicInternalFrameTitlePane { public MyIFtitleBar(JInternalFrame jif) { super(jif); } protected void paintTitleBackground(Graphics g){ g.setColor(Color.pink); g.fillRect(0, 0, getWidth(), getHeight()); } } Here is my JInternal frame. I tried running it in its psvm method, that worked! public class FitnessProg_Frame extends javax.swing.JInternalFrame { public FitnessProg_Frame() { initComponents(); this.setUI(new BasicInternalFrameUI(this){ @Override protected JComponent createNorthPane(JInternalFrame jif) { return new MyIFtitleBar(jif); } }); } @SuppressWarnings("unchecked") private void initComponents() { setBackground(new java.awt.Color(255, 255, 255)); setBorder(new javax.swing.border.MatteBorder(null)); setTitle("Fitness Progarm"); setPreferredSize(new java.awt.Dimension(507, 304)); pack(); } } But when I add it to my JFrame I get an error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException Here is my JFrame code: public class NewJFrame extends javax.swing.JFrame { public NewJFrame() { initComponents(); FitnessProg_Frame ff = new FitnessProg_Frame(); ff.setVisible(true); mydes.add(ff); // this line made errors } @SuppressWarnings("unchecked") private void initComponents() { mydes = new javax.swing.JDesktopPane(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); javax.swing.GroupLayout mydesLayout = new javax.swing.GroupLayout(mydes); mydes.setLayout(mydesLayout); mydesLayout.setHorizontalGroup( mydesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); mydesLayout.setVerticalGroup( mydesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); getContentPane().add(mydes, java.awt.BorderLayout.CENTER); pack(); } public static void main(String args[]) { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NewJFrame().setVisible(true); } }); } private javax.swing.JDesktopPane mydes; }

    Read the article

  • JButtons re-enable themselves after being disabled

    - by Anarchist
    I have an array of JButtons which form a keypad interface. After six numbers are entered I want to disable the keypad so that no further numbers can be entered by the user. I have written the code and the buttons do disable until the mouse hovers above any of them, then the buttons seem to re-enable themselves and run actionEvents added to them. The full code is available here. Possible things that I think are wrong. There is some sort of MouseListener which is ignoring when I set button.setEnabled(false); I haven't separated attributes from the buildGUI(); correctly, I only did this anyway so that the inner class could access them. Possibly something to do with the gridLayout as disabling the buttons seems to work for my services JPanel buttons.

    Read the article

  • how to get selected chracter position in JTextArea?

    - by Reddy
    Hi! Here is a challenging question! Let me first tell you my scenario how am i implementing a solution to a problem. I am reading a log file and displaying it on the JTextArea. Log file is cp037 character coded. I was reading each file as a byte stream or byte array from the log file & displaying it. Anyways, i managed to display the text properly in JTextArea by cp037 character coding. Now, User may select a set of characters in the JTextArea. All i want is the position of first character of the user's selected text, from a nearest special character '+'(its character code in cp037 is 4E), which is prior to the selected text. This character may occur at several places in the JTextArea. In simple sentence, i want the first character location(of user selected text) from nearset '+' which should be occuring prior to the user's selected text. PS: cp037 is a type of character encoding scheme which is created by IBM & used for IBM Mainframes. Please fell free to ask me if the question is not clear...:-

    Read the article

  • MouseListener fired without checking JCheckBox

    - by Morinar
    This one is pretty crazy: I've got an AppSight recording (for those not familiar, it's a recording of what they did including keyboard/mouse input + network traffic, etc) of a customer reproducing a bug. Basically, we've got a series of items listed on the screen with JCheckBox-es down the left side. We've got a MouseListener set for the JPanel that looks something like this: private MouseAdapter createMouseListener() { return new MouseAdapter(){ public void mousePressed( MouseEvent e ) { if( e.getComponent() instanceof JCheckBox ) { // Do stuff } } }; } Based on the recording, it appears very strongly that they click just above one of the checkboxes. After that, it's my belief that this listener fired and the "Do stuff" block happened. However, it did NOT check the box. The user then saw that the box was unchecked, so they clicked on it. This caused the "Do stuff" block to fire again, thus undoing what it had done the first time. This time, the box was checked. Therefore, the user thinks that the box is checked, and it looks like it is, but our client thinks that the box is unchecked as it was clicked twice. Is this possible at all? For the life of me, I can't reproduce it or see how it could be possible, but based on the recording and the data the client sent to the server, I can't see any other logical explanation. Any help, thoughts, and or ideas would be much appreciated.

    Read the article

  • JMenu issue with Gnome's native look and feel.

    - by gmunk
    I stumbled on a very odd problem while trying to set up a JMenuBar with the native look and feel of Gnome. Here is a screenshot: http://img23.imageshack.us/i/issuel.png/ It has to say File there but it gets cut out. http://pastebin.com/CjFhmxcf http://pastebin.com/gwB3vnC3 Any, help is appreciated!

    Read the article

  • Synth LaF JLabel DISABLED color

    - by mmoris
    Hi all, Using the Synth LaF, I am unable to set a JLabel's FOREGROUND color for the DISABLED state. has anybody succeeded in doing this? Here is my label's style definition in my LaF.xml file. <style id="whiteLabelStyle"> <opaque value="false"/> <font name="Bitstream Vera Sans" size="16" /> <state> <color type="FOREGROUND" value="WHITE"/> </state> <state value="DISABLED"> <color type="FOREGROUND" value="BLACK"/> </state> </style> <bind style="whiteLabelStyle" type="name" key="WhiteOrbitLabel"/> Please not that all the other styles defined in my LaF.xml file are rendered properly in my application including my label's WHITE normal state color (it just never goes to black when I do lbl.setEnabled(false) Also, going through the Synth code, I have found the following comment in SynthStyle.getColor if ((context.getComponentState() & SynthConstants.DISABLED) != 0) { //This component is disabled, so return the disabled color. //In some cases this means ignoring the color specified by the //developer on the component. In other cases it means using a //specified disabledTextColor, such as on JTextComponents. //For example, JLabel doesn't specify a disabled color that the //developer can set, yet it should have a disabled color to the //text when the label is disabled. This code allows for that. if (c instanceof JTextComponent) { JTextComponent txt = (JTextComponent)c; Color disabledColor = txt.getDisabledTextColor(); if (disabledColor == null || disabledColor instanceof UIResource) { return getColorForState(context, type); } } else if (c instanceof JLabel && (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND)){ return getColorForState(context, type); } But I could not figure out how to set a disabled color for a JLabel Thanks for your help!

    Read the article

  • "Zoom" text to be as big as possible within constraints/box

    - by stolsvik
    First problem: You have 400 pixels width to go on, and need to fit some text within that constraint as large as possible (thus, the text shall use that amount of space). Throw in a new constraint: If the text is just "A", then it shall not zoom this above 100 pixels (or some specific font size). Then, a final situation: Linebreaks. Fit some text in the largest possible way within e.g. 400 x 150 pixels. An obvious way is to simply start with point 1, and then increase until you can't fit it anymore. This would work for all three problems, but would be very crude. The fitting of a single line within bounds could be done by writing it with some fixed point size, check the resulting pixel bounds of the text, and then simply scale it with a transform (the text scales properly too then, check out TransformUI). Any ideas of other ways to attack this would be greatly appreciated!

    Read the article

  • Writing a line in a JTextArea from another class

    - by Christopher Nastovski
    I'm trying to use a Method in my class 'Visual' to write a line of code into a JTextArea and it prints when I call it from 'Visual' but when I call it from 'Login' It only prints Text into the Console, not to the TextArea. private static Visual Visual; Visual.WriteLine("I'm sorry, your username or password is incorrect. Please try again."); or private static Visual Visual = new Visual(); Visual.WriteLine("I'm sorry, your username or password is incorrect. Please try again."); Dont work form 'Login' But, WriteLine("Test"); works from 'Visual', the class that the method is in. Here's the method in 'Visual' public void WriteLine(String Text) { System.out.println(Text); SystemFeed.append(Text.toString() + "\n"); SystemFeed.setCaretPosition(SystemFeed.getDocument().getLength()); }

    Read the article

  • BufferedImage.getGraphics() resulting in memory leak, is there a fix?

    - by user359202
    Hi friends, I'm having problem with some framework API calling BufferedImage.getGraphics() method and thus causing memory leak. What this method does is that it always calls BufferedImage.createGraphics(). On a windows machine, createGraphics() is handled by Win32GraphicsEnvironment which keeps a listeners list inside its field displayChanger. When I call getGraphics on my BufferedImage someChart, someChart's SurfaceManager(which retains a reference to someChart) is added to the listeners map in Win32GraphicsEnvironment, preventing someChart to be garbage collected. Nothing afterwards removes someChart's SurfaceManager from the listeners map. In general, the summarized path stopping a BufferedImage from being garbage collected, once getGraphics is called, is as follows: GC Root - localGraphicsEnvironment(Win32GraphicsEnvironment) - displayChanger(SunDisplayChanger) - listeners(Map) - key(D3DChachingSurfaceManager) - bImg(BufferedImage) I could have changed the framework's code so that after every called to BufferedImage.getGraphics(), I keep a reference to the BufferedImage's SurfaceManager. Then, I get hold of localGraphicsEnvironment, cast it to Win32GraphicsEnvironment, then call removeDisplayChangedListener() using the reference to the BufferedImage's SurfaceManager. But I don't think this is a proper way to solve the problem. Could someone please help me with this issue? Thanks a lot!

    Read the article

  • How can I fade in a JPanel & children?

    - by Christian 'fuzi' Orgler
    I know that I can fade in a panel, by adding the alpha value to the background color & a timer. But how can I fade in a panel with child components (like a JLabel)? EDIT _fadeTimer = new Timer(40, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (_alpha == 255) { _fadeTimer.stop(); } else { pnl_hint.setBackground(new Color( bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), (_alpha += 1))); pnl_hint.updateUI(); } } }); _fadeTimer.start();

    Read the article

  • jprogressbar visible and working on button click

    - by Jisson
    public NewJDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); jProgressBar1.setVisible(false); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { jButton1.setEnabled(false); jProgressBar1.setVisible(true); repaint(); for(int i=0;i<=100;i+=5){ jProgressBar1.setValue(i); // jProgressBar1.setIndeterminate(false); try{ jProgressBar1.paintImmediately(0, 0, 100, 100);//0, 1, 100, 10 Thread.sleep(100); jProgressBar1.setStringPainted(true); }catch(Exception e){} } I use above code for using a Jprogressbar in a JDialog,If I use this I can see a progressbar aftercompleting its process(100 %) and also I want to hide progressbar upto buttonclick.Can any one help me?

    Read the article

  • JList strike through

    - by kap
    I have a list of data in a JList component in my GUI. I would like to know if there is a method that i can call on the list element(s) to strike through a particular element in the list. I would like to draw a line through the element to appear as if that element is canceled. I want a similar thing like the strike through functionality in Microsoft Word document whereby a line i drawn through the text. thanks for your help

    Read the article

< Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >