Search Results

Search found 37239 results on 1490 pages for 'javax swing text'.

Page 11/1490 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Wrong background colors in Swing ListCellRenderer

    - by Johannes Rössel
    I'm currently trying to write a custom ListCellRenderer for a JList. Unfortunately, nearly all examples simply use DefaultListCellRenderer as a JLabel and be done with it; I needed a JPanel, however (since I need to display a little more info than just an icon and one line of text). Now I have a problem with the background colors, specifically with the Nimbus PLAF. Seemingly the background color I get from list.getBackground() is white, but paints as a shade of gray (or blueish gray). Outputting the color I get yields the following: Background color: DerivedColor(color=255,255,255 parent=nimbusLightBackground offsets=0.0,0.0,0.0,0 pColor=255,255,255 However, as can be seen, this isn't what gets painted. It obviously works fine for the selected item. Currently I even have every component I put into the JPanel the cell renderer returns set to opaque and with the correct foreground and background colors—to no avail. Any ideas what I'm doing wrong here? ETA: Example code which hopefully runs. public class ParameterListCellRenderer implements ListCellRenderer { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { // some values we need Border border = null; Color foreground, background; if (isSelected) { background = list.getSelectionBackground(); foreground = list.getSelectionForeground(); } else { background = list.getBackground(); foreground = list.getForeground(); } if (cellHasFocus) { if (isSelected) { border = UIManager.getBorder("List.focusSelectedCellHighlightBorder"); } if (border == null) { border = UIManager.getBorder("List.focusCellHighlightBorder"); } } else { border = UIManager.getBorder("List.cellNoFocusBorder"); } System.out.println("Background color: " + background.toString()); JPanel outerPanel = new JPanel(new BorderLayout()); setProperties(outerPanel, foreground, background); outerPanel.setBorder(border); JLabel nameLabel = new JLabel("Factory name here"); setProperties(nameLabel, foreground, background); outerPanel.add(nameLabel, BorderLayout.PAGE_START); Box innerPanel = new Box(BoxLayout.PAGE_AXIS); setProperties(innerPanel, foreground, background); innerPanel.setAlignmentX(Box.LEFT_ALIGNMENT); innerPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); JLabel label = new JLabel("param: value"); label.setFont(label.getFont().deriveFont( AffineTransform.getScaleInstance(0.95, 0.95))); setProperties(label, foreground, background); innerPanel.add(label); outerPanel.add(innerPanel, BorderLayout.CENTER); return outerPanel; } private void setProperties(JComponent component, Color foreground, Color background) { component.setOpaque(true); component.setForeground(foreground); component.setBackground(background); } } The weird thing is, if I do if (isSelected) { background = new Color(list.getSelectionBackground().getRGB()); foreground = new Color(list.getSelectionForeground().getRGB()); } else { background = new Color(list.getBackground().getRGB()); foreground = new Color(list.getForeground().getRGB()); } it magically works. So maybe the DerivedColor with nimbusLightBackground I'm getting there may have trouble?

    Read the article

  • -Java- Swing GUI - Moving around components specifically with layouts

    - by Xemiru Scarlet Sanzenin
    I'm making a little test GUI for something I'm making. However, problems occur with the positioning of the panels. public winInit() { super("Chatterbox - Login"); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(ClassNotFoundException e) { } catch (InstantiationException e) { } catch (IllegalAccessException e) { } catch (UnsupportedLookAndFeelException e) { } setSize(300,135); pn1 = new JPanel(); pn2 = new JPanel(); pn3 = new JPanel(); l1 = new JLabel("Username"); l2 = new JLabel("Password"); l3 = new JLabel("Random text here"); l4 = new JLabel("Server Address"); l5 = new JLabel("No address set."); i1 = new JTextField(10); p1 = new JPasswordField(10); b1 = new JButton("Connect"); b2 = new JButton("Register"); b3 = new JButton("Set IP"); l4.setBounds(10, 12, getDim(l4).width, getDim(l4).height); l1.setBounds(10, 35, getDim(l1).width, getDim(l1).height); l2.setBounds(10, 60, getDim(l2).width, getDim(l2).height); l3.setBounds(10, 85, getDim(l3).width, getDim(l3).height); l5.setBounds(l4.getBounds().width + 14, 12, l5.getPreferredSize().width, l5.getPreferredSize().height); l5.setForeground(Color.gray); i1.setBounds(getDim(l1).width + 15, 35, getDim(i1).width, getDim(i1).height); p1.setBounds(getDim(l1).width + 15, 60, getDim(p1).width, getDim(p1).height); b1.setBounds(getDim(l1).width + getDim(i1).width + 23, 34, getDim(b2).width, getDim(b1).height - 5); b2.setBounds(getDim(l1).width + getDim(i1).width + 23, 60, getDim(b2).width, getDim(b2).height - 5); b3.setBounds(getDim(l1).width + getDim(i1).width + 23, 10, etDim(b2).width, getDim(b3).height - 5); b1.addActionListener(clickButton); b2.addActionListener(clickButton); b3.addActionListener(clickButton); pn1.setLayout(new FlowLayout(FlowLayout.RIGHT)); pn2.setLayout(new FlowLayout(FlowLayout.RIGHT)); pn1.add(l1); pn1.add(i1); pn1.add(b1); pn2.add(l2); pn2.add(p1); pn2.add(b2); add(pn1); add(pn2); } I am attempting to use FlowLayout to position the panels in the way desired. I'd use BorderLayout while adding, but the vertical spacing is too far away when I just use directions closest to one another. The output of this code is to create a window, 300,150, place whatever's in the two panels in the exact same spaces. Yes, I realize there's useless code there with setBounds(), but that was just me screwing around with Absolute Positioning, which wasn't working out for me either.

    Read the article

  • Finding text's bounding rect in Core Text

    - by Mo
    I'm trying to find the boundaries of a line of text in Core Text. For simplicity, assume it has a single character. At the moment I'm using the following method: line = CTLineCreateWithAttributedString(attrString); rect = CTLineGetImageBounds(line, context); It works most of the times, but for some characters, like math italic d (Unicode: 0x1D451) or math italic q (Unicode: 0x1D45E), the width is a bit short. I tried using CTLineGetTypographicBounds() or CTFramesetterSuggestFrameSizeWithConstraints, but they didn't help either (I think they use glyph's advance to find the width, not its graphical width.) As the font itself isn't italic, I also can't use slant angle to correct this. I tried accessing the glyphs directly and using CTFontCreatePathForGlyph(), but failed as CGGlyph and UniChar are both 16-bits and I need 32-bit characters. Does anyone know if I'm doing anything wrong? If so, what's the right way?

    Read the article

  • Preferred way to render text in OpenGL

    - by dukeofgaming
    Hi, I'm about tu pick up computer graphics once again for an university project. For a previous project I used a library called ftgl that didn't leave me quite satisfied as it felt kind of heavy (I tried all rendering techniques, text rendering didn't scale very well). My question is, is there a good and efficient library for this?, if not, what would be the way to implement fast but nice looking text?. Some intended uses are: Floating object/character labels Dialogues Menus HUD Regards and thanks in advance. EDIT: Preferrably that it can load fonts

    Read the article

  • Possible applications of algorithm devised for differentiating between structured vs random text

    - by rooznom
    I have written a program that can rapidly (within 5 sec on a 2GB RAM desktop, 2.33 Ghz CPU) differentiate between structured text (e.g english text) and random alphanumeric strings. It can also provide a probability score for the prediction. Are there any practical applications/uses of such a program. Note that the program is based on entropy models and does not have any dictionary comparisons in its workflow. Thanks in advance for your responses

    Read the article

  • Java-Swing: Change getSource() in ActionListener

    - by Brandon
    I have a class that contains a JButton. This can't be changed. The problem is this: The actionListener calls getSource() and gets the JButton, not the container class. Can I change what getSource retrieves, before the actionListener is added? OR can JButtons have a variable reference to its container? I can't make a class extend a JButton. It caused bugs for drawing purposes... story of my week.

    Read the article

  • Swing button repaint issue

    - by KáGé
    Hello, I'm new to java and I have to get a school project done by Sunday and got a problem. Here's the code: private abstract class GamePanel { JPanel panel = null; } private class PutPanel extends GamePanel { JButton putShip1 = new JButton(""); JButton putShip2 = new JButton(""); JButton putShip3 = new JButton(""); JButton putShip4 = new JButton(""); ShipDirection ship1Direction = ShipDirection.NORTH; ShipDirection ship2Direction = ShipDirection.NORTH; ShipDirection ship3Direction = ShipDirection.NORTH; ShipDirection ship4Direction = ShipDirection.NORTH; JButton startButton = new JButton("Start game"); public PutPanel(){ this.panel = new JPanel(); panel.setSize(200, Torpedo.session.map.size*Field.buttonSize+300); panel.setBackground(Color.blue); putShip1.setSize(90, 90); putShip1.setLocation(55, 5); putShip1.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship1/full_north.png", null)); putShip2.setSize(90, 90); putShip2.setLocation(55, 105); putShip2.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship2/full_north.png", null)); putShip3.setSize(90, 90); putShip3.setLocation(55, 205); putShip3.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship3/full_north.png", null)); putShip4.setSize(90, 90); putShip4.setLocation(55, 305); putShip4.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship4/full_north.png", null)); startButton.setSize(150, 30); startButton.setLocation(20, Torpedo.session.map.size*Field.buttonSize+205); panel.add(putShip1); panel.add(putShip2); panel.add(putShip3); panel.add(putShip4); panel.add(startButton); startButton.addActionListener(startButton()); startButton.addActionListener(putShip1()); startButton.addActionListener(putShip2()); startButton.addActionListener(putShip3()); startButton.addActionListener(putShip4()); panel.setLayout(null); panel.setVisible(true); } private ActionListener startButton(){ return new ActionListener(){ public void actionPerformed(ActionEvent e) { putPanel.panel.setVisible(false); actionPanel.panel.setVisible(true); } }; } private ActionListener putShip1(){ return new ActionListener(){ public void actionPerformed(ActionEvent e) { selectedShip = 1; putShip1.setBackground(Color.red); putShip2.setBackground(null); putShip3.setBackground(null); putShip4.setBackground(null); switch(ship1Direction){ case NORTH: ship1Direction = ShipDirection.EAST; putShip1.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship1/full_east.png", null)); break; case EAST: ship1Direction = ShipDirection.SOUTH; putShip1.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship1/full_south.png", null)); break; case SOUTH: ship1Direction = ShipDirection.WEST; putShip1.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship1/full_west.png", null)); break; case WEST: ship1Direction = ShipDirection.NORTH; putShip1.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship1/full_north.png", null)); break; } putShip1.repaint(); putShip2.repaint(); putShip3.repaint(); putShip4.repaint(); panel.repaint(); JOptionPane.showMessageDialog(new JFrame(), "Repaint finished", "Repaint status info", JOptionPane.INFORMATION_MESSAGE); //this here hangs the program when the method is finally called } }; When one of the putShip* buttons is clicked, it should rotate its own icon right 90° (means changing it to the next image), but it does nothing until the startButton is clicked, which changes the panel to an other one. (Only the first button's actionListener is here, the others' are practically the same). The panel is in a JFrame with two other panels that yet do nothing. How could I make it work properly? Thank you.

    Read the article

  • Java Swing MVC question

    - by juFo
    I'm following this MVC model: http://java.sun.com/developer/technicalArticles/javase/mvc/ In my model I have an "ArrayList shapes" field and I need the shapes in my view. Is the only way of getting my shapes by getting them in the modelPropertyChange method? public void modelPropertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(MyController.PROPERTY_TEXT)) { ArrayList<Shape> shapes = (ArrayList<Shape>) evt.getNewValue(); } } or should I also create a generic getter method in my controller? like this generic setter method: protected void setModelProperty(String propertyName, Object newValue) { for (AbstractModel model: registeredModels) { try { Method method = model.getClass(). getMethod("set"+propertyName, new Class[] { newValue.getClass() } ); method.invoke(model, newValue); } catch (Exception ex) { // Handle exception. } } } If I need such a generic getter method, I have no clue how to transform this generic setter above to a generic getter method. If I don't need such a generic getter method to retreive my data from the model, if I only need the modelPropertyChange method from my View. How would I get my data from the model the first time the application starts? :o Pfft I need to get my arraylist of shapes from my model in my view :( (and later I need to get some other data also) So confusing :(

    Read the article

  • Java Swing Generate JTable from POJO at runtime

    - by Guillaume
    I'm looking for a library able to build at runtime, using some configuration (xml, annotations, ...) and reflection, a complete JTable (model + searchable and sortable jtable) from a collection of POJOS. I did not found anything like that on the web and I'm wondering if something already exist before I start to coding this.

    Read the article

  • Swing combo boxes

    - by Dalton Conley
    Alright, so I'm simply defining a combo box like so... JComboBox yearSelect = new JComboBox(); Now, I have not even added this to a panel or anything, I've just defined it. When I run the app, nothing displays.. when I comment out this line.. the app displays the other panels like I want it to.. is there something I'm doing wrong? Maybe I'm forgetting something that has to do with combo boxes? I think it may be something stupid that I'm missing.

    Read the article

  • How to create a rounded title border in Java Swing

    - by Stephane Grenier
    I do understand that to create a title border, you do something like: BorderFactory.createTitledBorder(" Your Title "); However this creates a rectangle border whereas I need a rectangle with curved corners. Now from what I understand you can create your own custom border by: class CustomBorder implements Border { ... } The problem is that I'm not sure how to write the code that overrides the method: public void paintBorder(Component component, Graphics g, int x, int y, int width, int height) Or better yet, is there a way to do it without implementing your own Border class? And if not, how would you write that custom Title Border? I'm ok with drawing a rectangle with rounded corners, but how do you do it so that there's space for the label too?

    Read the article

  • Java Swing Table questions

    - by Dalton Conley
    Hey guys, working on an event calendar. I'm having some trouble getting my column heads to display.. here is the code private JTable calendarTable; private DefaultTableModel calendarTableModel; final private String [] days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; ////////////////////////////////////////////////////////////////////// /* Setup the actual calendar table */ calendarTableModel = new DefaultTableModel() { public boolean isCellEditable(int row, int col){ return false; } }; // setup columns for(int i = 0; i < 7; i++) calendarTableModel.addColumn(days[i]); calendarTable = new JTable(calendarTableModel); calendarTable.getTableHeader().setResizingAllowed(false); calendarTable.getTableHeader().setReorderingAllowed(false); calendarTable.setColumnSelectionAllowed(true); calendarTable.setRowSelectionAllowed(true); calendarTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); calendarTable.setRowHeight(105); calendarTableModel.setColumnCount(7); calendarTableModel.setRowCount(6); Also, Im sort of new with tables.. how can I make the rowHeight split between the max size of the table?

    Read the article

  • Java Swing - Drawing markers on JSlider.

    - by Tony Day
    Hi, I have a progress bar which inherits from JSlider to provide highlighting functionality. Highlights can be added to the slider at a point (and a Color) and these are then painted onto the control. As follows: The problem is that I cannot get the highlights in the right place, they need to be in the same location as the markers. I also do not know how to retrieve the left and right margins to where the markers start and end. Is there anyway to get the coordinates of each marker? Or perhaps a better way of performing this task? Many Thanks!

    Read the article

  • Swing Panel Question

    - by dalton conley
    Ok, so I've been pulling my hair out over this all day. I cannot get my panels to resize. I add a panel to anything.. a frame, a content pane, and It wont .. "force" setBounds for some strange reason. Container pane = window.getContentPane(); JPanel calendarPanel = new JPanel(); pane.add(calendarPanel); calendarPanel.setBounds(0,0, 320, 335); note that window is of JFrame. Any suggestions to sizing a panel would be appreciated!

    Read the article

  • Java Swing Threading with Updatable JProgressBar

    - by Anthony Sparks
    First off I've been working with Java's Concurency package quite a bit lately but I have found an issue that I am stuck on. I want to have and Application and the Application can have a SplashScreen with a status bar and the loading of other data. So I decided to use SwingUtilities.invokeAndWait( call the splash component here ). The SplashScreen then appears with a JProgressBar and runs a group of threads. But I can't seem to get a good handle on things. I've looked over SwingWorker and tried using it for this purpose but the thread just returns. Here is a bit of sudo-code. and the points I'm trying to achieve. Have an Application that has a SplashScreen that pauses while loading info Be able to run multiple threads under the SplashScreen Have the progress bar of the SplashScreen Update-able yet not exit until all threads are done. Launching splash screen try { SwingUtilities.invokeAndWait( SplashScreen ); } catch (InterruptedException e) { } catch (InvocationTargetException e) { } Splash screen construction SplashScreen extends JFrame implements Runnable{ public void run() { //run threads //while updating status bar } } I have tried many things including SwingWorkers, Threads using CountDownLatch's, and others. The CountDownLatch's actually worked in the manner I wanted to do the processing but I was unable to update the GUI. When using the SwingWorkers either the invokeAndWait was basically nullified (which is their purpose) or it wouldn't update the GUI still even when using a PropertyChangedListener. If someone else has a couple ideas it would be great to hear them. Thanks in advance.

    Read the article

  • Java/Swing: the fast/slow UI binding problem

    - by Jason S
    I need a way to bind UI indicators to rapidly-changing values. I have a class NumberCruncher which does a bunch of heavy processing in a critical non-UI thread, thousands of iterations of a loop per second, and some number of those result in changes to a set of parameters I care about. (think of them as a key-value store) I want to display those at a slower rate in the UI thread; 10-20Hz would be fine. How can I add MVC-style notification so that my NumberCruncher code doesn't need to know about the UI code/binding?

    Read the article

  • Java Swing TanleModel fireTableRowsInserted on EDT

    - by Ayman
    I have a TableModel that is populated from a background running thread. I am calling fireTableRowsInserted when data is inserted, which is NOT on the EDT. My question is, do I need to use invokeLater for the fireTableRowsInserted? In other words, is the below correct: public void putData(TableRow row) { // we are not on the EDT here... rows.add(row); fireTableRowsInserted(rows.size()-1, rows.size()-1); }

    Read the article

  • java/swing: Shape questions: serializing and combining

    - by Jason S
    I have two questions about java.awt.Shape. Suppose I have two Shapes, shape1 and shape2. How can I serialize them in some way so I can save the information to a file and later recreate it on another computer? (Shape is not Serializable but it does have the getPathIterator() method which seems like you could get the information out but it would be kind of a drag + I'm not sure how to reconstruct a Shape object afterwards.) How can I combine them into a new Shape so that they form a joint boundary? (e.g. if shape1 is a large square and shape2 is a small circle inside the square, I want the combined shape to be a large square with a small circular hole)

    Read the article

  • How to extract the word and line wrapping information from JTextArea for text with given font

    - by Gábor Lipták
    I have to convert styled text to wrapped simple text (for SVG word wrapping). I cannot beleive that the word wrapping information (how many lines are there, where are the line breaks) cannot be extracted from the JTextArea. So I created a small frame program: package bla; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.List; import javax.swing.JTextArea; public class Example1 extends WindowAdapter { private static String content = "01234567890123456789\n" + "0123456 0123456 01234567 01234567"; JTextArea text; public Example1() { Frame f = new Frame("TextArea Example"); f.setLayout(new BorderLayout()); Font font = new Font("Serif", Font.ITALIC, 20); text = new JTextArea(); text.setFont(font); text.setForeground(Color.blue); text.setLineWrap(true); text.setWrapStyleWord(true); f.add(text, BorderLayout.CENTER); text.setText(content); // Listen for the user to click the frame's close box f.addWindowListener(this); f.setSize(100, 511); f.show(); } public static List<String> getLines( JTextArea text ) { //WHAT SHOULD I WRITE HERE return new ArrayList<String>(); } public void windowClosing(WindowEvent evt) { List<String> lines = getLines(text); System.out.println( "Number of lines:" + lines.size()); for (String line : lines) { System.out.println( line ); } System.exit(0); } public static void main(String[] args) { Example1 instance = new Example1(); } } If you run it you will see this: And what I expect as output: Number of lines:6 0123456789 0123456789 0123456 0123456 01234567 01234567 What should I write in place of the comment?

    Read the article

  • Java Swing - Problem in disabling JCheckbox

    - by Yatendra Goel
    I am disabling a JCheckbox and then enabling it with the help of setEnabled(...) method. But the problem is if I disable a unselected checkbox, then it becomes selected after I enable it. I want all of them to have the same state after being enabled that they had before being disabled.

    Read the article

  • Updating position of JSlider Swing

    - by GLRockwell
    My apologies for posting tons of questions as of late. I'm trying to get a JSlider to update its position based on a constantly updating variable. The setValue(n) method doesn't seem to work. Is there any alternative? We're using this as a time marker for a music player.

    Read the article

  • Swing- focus problem

    - by AlonaK
    Hi, In my application I have a frame, with toolbar (the toolbar contains some actions). I want the toolbar to be visible only when the window is focused. So, I registered a windowFocusListener on the window. The problem is- when the window is not focused and I click on the place where a tool bar action should be- the action is performed. This happens because the WindowFocusGained is called before the mouse button is released and when the mouse button released it calls the actionPerformed. Does anybody has any idea for a work around for this problem? Does anybody know how to determine wether the mouse button is clicked now?

    Read the article

  • Java Swing jtable cell editor doubles E numbers

    - by Michael
    Hi I an issue with editors in a JTable. I have a column which displays data as 26,687,489,800.00 ie: Double. When the user clicks the cell to edit the data it is displayed as -2.66874908E10. I want the data to be edited as it appears when it is displayed ie: 26,687,489,800.00 - without the E10 etc... Any help would be appreciated. Mike

    Read the article

  • Using maven to distribute a swing application that can have each dependency individually tracked

    - by tms
    I'm moving my project to Maven and eventually OSGi. I currently distribute the project is a large Zip file with all the dependencies. Although my projects code is only 20% of the total package I have to redistribute all the dependency. With smaller independent modules this may be even less. Looking here on stack overflow it seems that to keep my current plan the maven-assembly-plugin should do the trick. I was considering having a base installer that would look at a XML manifest, then collect all the libraries that needed to be updated. This would mean that libraries that change occasionally would be downloaded less often. This also makes since for something like OSGi plugins (which could have independent release schedules). In essence I want my software to look and manage individual libraries, and download on demand (based on the manifest). I was wondering if there is a "maven way" of generating this Manifest and publishing all the libraries to a website? I believe the deploy life-cycle would do the second step. As an alternative, is there a OpenSource Java library that does this type of deployment? I don't want to embed Maven or something larger with the distributed code. The application is not for coders, the simpler the better, and the smaller the installer the better.

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >